List of usage examples for com.rabbitmq.client BasicProperties getContentType
public abstract String getContentType();
From source file:org.springframework.amqp.rabbit.support.RabbitUtils.java
License:Apache License
public static MessageProperties createMessageProperties(final BasicProperties source, final Envelope envelope, final String charset) { MessageProperties target = new MessageProperties(); Map<String, Object> headers = source.getHeaders(); if (!CollectionUtils.isEmpty(headers)) { for (Map.Entry<String, Object> entry : headers.entrySet()) { target.setHeader(entry.getKey(), entry.getValue()); }/* www . j a v a 2 s .co m*/ } target.setTimestamp(source.getTimestamp()); target.setMessageId(source.getMessageId()); target.setUserId(source.getUserId()); target.setAppId(source.getAppId()); target.setClusterId(source.getClusterId()); target.setType(source.getType()); Integer deliverMode = source.getDeliveryMode(); if (deliverMode != null) { target.setDeliveryMode(MessageDeliveryMode.fromInt(deliverMode)); } target.setExpiration(source.getExpiration()); target.setPriority(source.getPriority()); target.setContentType(source.getContentType()); target.setContentEncoding(source.getContentEncoding()); String correlationId = source.getCorrelationId(); if (correlationId != null) { try { target.setCorrelationId(source.getCorrelationId().getBytes(charset)); } catch (UnsupportedEncodingException ex) { throw new AmqpUnsupportedEncodingException(ex); } } String replyTo = source.getReplyTo(); if (replyTo != null) { target.setReplyTo(new Address(replyTo)); } if (envelope != null) { target.setReceivedExchange(envelope.getExchange()); target.setReceivedRoutingKey(envelope.getRoutingKey()); target.setRedelivered(envelope.isRedeliver()); target.setDeliveryTag(envelope.getDeliveryTag()); } // TODO: what about messageCount? return target; }
From source file:pl.nask.hsn2.bus.rabbitmq.endpoint.RbtDefaultConsumer.java
License:Open Source License
@Override public final void handleDelivery(String consumerTag, Envelope envelope, BasicProperties properties, byte[] body) throws IOException { super.handleDelivery(consumerTag, envelope, properties, body); Message message = new Message(properties.getType(), body, properties.getCorrelationId(), new RbtDestination(RABBITMQ_DEFAULT_EXCHANGE_NAME, properties.getReplyTo())); message.setDestination(new RbtDestination(RABBITMQ_DEFAULT_EXCHANGE_NAME, envelope.getRoutingKey())); message.setContentType(properties.getContentType()); // take retries count try {//from w w w. ja va 2 s. com if (properties.getHeaders() != null) { Object xretriesObject = properties.getHeaders().get("x-retries"); if (xretriesObject != null) { int xretries = 0; if (xretriesObject instanceof Integer) { xretries = (Integer) xretriesObject; } else if (xretriesObject instanceof String) { xretries = Integer.parseInt((String) xretriesObject); } else { LOGGER.error("Unknown object type of x-retries property."); } message.setRetries(xretries); } } } catch (NumberFormatException ex) { // not important } try { responseHandler.handleMessage(message); if (!autoack) { getChannel().basicAck(envelope.getDeliveryTag(), false); } } catch (ConsumeHandlerException ex) { if (!autoack) { getChannel().basicReject(envelope.getDeliveryTag(), true); } // nothing can do :( } catch (Throwable t) { if (!autoack) { getChannel().basicReject(envelope.getDeliveryTag(), true); } LOGGER.error("Error handling message.", t); } }
From source file:pl.nask.hsn2.unicorn.connector.ConnectorImpl.java
License:Open Source License
public Response receive() throws ConnectionException { try {// www.j av a 2s. c om Delivery delivery = consumer.nextDelivery(); BasicProperties properties = delivery.getProperties(); return new Response(properties.getType(), properties.getContentType(), delivery.getBody()); } catch (ShutdownSignalException e) { throw new ConnectionException("Receiving error!", e); } catch (InterruptedException e) { throw new ConnectionException("Receiving error!", e); } }