List of usage examples for org.springframework.amqp.core MessagePostProcessor postProcessMessage
Message postProcessMessage(Message message) throws AmqpException;
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);//from w w w. j ava 2 s .c o m 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.kurento.rabbitmq.RabbitTemplate.java
public void convertAndSend(String exchange, String routingKey, final Object message, final MessagePostProcessor messagePostProcessor, CorrelationData correlationData) throws AmqpException { Message messageToSend = convertMessageIfNecessary(message); messageToSend = messagePostProcessor.postProcessMessage(messageToSend); send(exchange, routingKey, messageToSend, correlationData); }
From source file:org.kurento.rabbitmq.RabbitTemplate.java
@Override public Object convertSendAndReceive(final String exchange, final String routingKey, final Object message, final MessagePostProcessor messagePostProcessor) throws AmqpException { Message requestMessage = convertMessageIfNecessary(message); if (messagePostProcessor != null) { requestMessage = messagePostProcessor.postProcessMessage(requestMessage); }// ww w. j a va 2s .c o m Message replyMessage = this.doSendAndReceive(exchange, routingKey, requestMessage); if (replyMessage == null) { return null; } return this.getRequiredMessageConverter().fromMessage(replyMessage); }
From source file:org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.java
/** * Execute the specified listener, committing or rolling back the transaction afterwards (if necessary). * * @param channel the Rabbit Channel to operate on * @param messageIn the received Rabbit Message * @throws Exception Any Exception.// w w w . ja va2 s .com * * @see #invokeListener * @see #handleListenerException */ protected void executeListener(Channel channel, Message messageIn) throws Exception { if (!isRunning()) { if (logger.isWarnEnabled()) { logger.warn( "Rejecting received message because the listener container has been stopped: " + messageIn); } throw new MessageRejectedWhileStoppingException(); } try { Message message = messageIn; if (this.afterReceivePostProcessors != null) { for (MessagePostProcessor processor : this.afterReceivePostProcessors) { message = processor.postProcessMessage(message); } } Object batchFormat = message.getMessageProperties().getHeaders() .get(MessageProperties.SPRING_BATCH_FORMAT); if (MessageProperties.BATCH_FORMAT_LENGTH_HEADER4.equals(batchFormat) && this.deBatchingEnabled) { ByteBuffer byteBuffer = ByteBuffer.wrap(message.getBody()); MessageProperties messageProperties = message.getMessageProperties(); messageProperties.getHeaders().remove(MessageProperties.SPRING_BATCH_FORMAT); while (byteBuffer.hasRemaining()) { int length = byteBuffer.getInt(); if (length < 0 || length > byteBuffer.remaining()) { throw new ListenerExecutionFailedException("Bad batched message received", new MessageConversionException( "Insufficient batch data at offset " + byteBuffer.position()), message); } byte[] body = new byte[length]; byteBuffer.get(body); messageProperties.setContentLength(length); // Caveat - shared MessageProperties. Message fragment = new Message(body, messageProperties); invokeListener(channel, fragment); } } else { invokeListener(channel, message); } } catch (Exception ex) { if (messageIn.getMessageProperties().isFinalRetryForMessageWithNoId()) { if (this.statefulRetryFatalWithNullMessageId) { throw new FatalListenerExecutionException( "Illegal null id in message. Failed to manage retry for message: " + messageIn); } else { throw new ListenerExecutionFailedException("Cannot retry message more than once without an ID", new AmqpRejectAndDontRequeueException("Not retryable; rejecting and not requeuing", ex), messageIn); } } handleListenerException(ex); throw ex; } }