List of usage examples for com.rabbitmq.client BasicProperties getHeaders
public abstract Map<String, Object> getHeaders();
From source file:org.zenoss.amqp.impl.BasicPropertiesWrapper.java
License:Open Source License
BasicPropertiesWrapper(BasicProperties basicProperties) { this.properties = basicProperties; /*// w w w. j a v a 2 s.c om * We want to convert header values of type LongString (RabbitMQ * specific) to String. */ if (basicProperties.getHeaders() != null && !basicProperties.getHeaders().isEmpty()) { headers = new HashMap<String, Object>(); for (Map.Entry<String, Object> entry : basicProperties.getHeaders().entrySet()) { String key = entry.getKey(); Object val = entry.getValue(); if (val instanceof LongString) { try { headers.put(key, new String(((LongString) val).getBytes(), "UTF-8")); } catch (UnsupportedEncodingException e) { throw new RuntimeException("UTF-8 encoding required", e); } } else { headers.put(key, val); } } } else { headers = Collections.emptyMap(); } }
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 {// w ww.j av a 2s .co m 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); } }