List of usage examples for org.springframework.amqp.core MessageProperties getDeliveryTag
public long getDeliveryTag()
From source file:com.ushahidi.swiftriver.core.dropqueue.DropHandlerTest.java
@Test public void onMessage() throws JsonParseException, JsonMappingException, IOException { Message mockMessage = mock(Message.class); MessageProperties mockMessageProperties = mock(MessageProperties.class); Channel mockChannel = mock(Channel.class); String body = "{\"identity_orig_id\": \"http://feeds.bbci.co.uk/news/rss.xml\", \"droplet_raw\": \"The danger of growing resistance to antibiotics should be treated as seriously as the threat of terrorism, England's chief medical officer says.\", \"droplet_orig_id\": \"c558d88a44fc70da36d04746574e05e4\", \"droplet_locale\": \"en-gb\", \"identity_username\": \"http://www.bbc.co.uk/news/#sa-ns_mchannel=rss&ns_source=PublicRSS20-sa\", \"droplet_date_pub\": \"Mon, 11 Mar 2013 07:32:59 +0000\", \"droplet_type\": \"original\", \"identity_avatar\": \"http://news.bbcimg.co.uk/nol/shared/img/bbc_news_120x60.gif\", \"droplet_title\": \"Antibiotic resistance 'threat to UK'\", \"links\": [{\"url\": \"http://www.bbc.co.uk/news/health-21737844#sa-ns_mchannel=rss&ns_source=PublicRSS20-sa\", \"original_url\": true}], \"droplet_content\": \"The danger of growing resistance to antibiotics should be treated as seriously as the threat of terrorism, England's chief medical officer says.\", \"identity_name\": \"BBC News - Home\", \"channel\": \"rss\", \"river_id\": [2]}"; when(mockMessage.getBody()).thenReturn(body.getBytes()); when(mockMessage.getMessageProperties()).thenReturn(mockMessageProperties); when(mockMessageProperties.getDeliveryTag()).thenReturn(22L); when(mockCallbackQueue.getName()).thenReturn("callback"); dropHandler.onMessage(mockMessage, mockChannel); assertTrue(dropsMap.size() > 0);//ww w . j a v a 2s . c om assertTrue(deliveryFramesMap.size() > 0); String correlationId = (String) dropsMap.keySet().toArray()[0]; ArgumentCaptor<RawDrop> dropArgument = ArgumentCaptor.forClass(RawDrop.class); ArgumentCaptor<MessagePostProcessor> processorArgument = ArgumentCaptor .forClass(MessagePostProcessor.class); verify(mockAmqpTemplate).convertAndSend(dropArgument.capture(), processorArgument.capture()); RawDrop drop = dropArgument.getValue(); assertTrue(dropsMap.containsValue(drop)); assertEquals("Antibiotic resistance 'threat to UK'", drop.getTitle()); MessagePostProcessor postProcessor = processorArgument.getValue(); postProcessor.postProcessMessage(mockMessage); verify(mockMessageProperties).setReplyTo("callback"); verify(mockMessageProperties).setCorrelationId(correlationId.getBytes()); }
From source file:org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.java
/** * If this is a non-POISON non-null delivery simply return it. If this is * POISON we are in shutdown mode, throw shutdown. If delivery is null, we * may be in shutdown mode. Check and see. * /* w w w . j a v a 2 s . c o m*/ * @throws InterruptedException */ private Message handle(Delivery delivery) throws InterruptedException { if ((delivery == null && shutdown != null)) { throw shutdown; } if (delivery == null) { return null; } byte[] body = delivery.getBody(); Envelope envelope = delivery.getEnvelope(); MessageProperties messageProperties = this.messagePropertiesConverter .toMessageProperties(delivery.getProperties(), envelope, "UTF-8"); messageProperties.setMessageCount(0); Message message = new Message(body, messageProperties); if (logger.isDebugEnabled()) { logger.debug("Received message: " + message); } deliveryTags.add(messageProperties.getDeliveryTag()); int retryTimes = getRequeueTimes(message); retryDeliveryTags.put(messageProperties.getDeliveryTag(), ++retryTimes); return message; }
From source file:org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.java
/** * wrap message back to a delivery and put to ref's queue for retry several * times//w w w. j a va 2 s . c om * * @param message * @throws InterruptedException */ public void requeueLocalMessage(Message message) throws InterruptedException { MessageProperties messageProperties = message.getMessageProperties(); AMQP.BasicProperties properties = messageProperties == null ? null : this.messagePropertiesConverter.fromMessageProperties(messageProperties, "UTF-8"); Envelope envelope = messageProperties == null ? null : this.messagePropertiesConverter.fromMessagePropertiesToEnvelope(messageProperties, "UTF-8"); Delivery delivery = new Delivery(envelope, properties, message.getBody()); // remove the delivery tags and it will requeue while nextMessage() Long deliveryTag = messageProperties.getDeliveryTag(); deliveryTags.remove(deliveryTag); queue.put(delivery); }
From source file:org.springframework.amqp.rabbit.listener.BlockingQueueConsumer.java
/** * return requeue times of the message//from w ww . j av a 2 s. c om * * @param message * @return */ public int getRequeueTimes(Message message) { MessageProperties messageProperties = message.getMessageProperties(); Long deliveryTag = messageProperties.getDeliveryTag(); return retryDeliveryTags.containsKey(deliveryTag) ? retryDeliveryTags.get(deliveryTag) : 0; }