Hi,
I am using Spring-AMQP-1.0.0.M2.
I have a producer which has to populate a String message in Direct Exchange queue.
I have used same value for RoutingKey (ie.,test.queue) and QueueName(ie.,test.queue) . RoutingKey was set to RabbitTemplate bean in the Spring Configuration file.
Using convertAndSend(Object msg) method, I am able to publish the message in the server.
Now I need to send some message properties (like UserId, Timestamp, etc.,) along with the actual message. I have used instance of MessagePostProcessor, but this doesn't publish the message.
The code snippet of Producer is given below.
Can someone help me to set the message properties while sending the message.
Thanks in AdvanceCode:public class ProducerTest { public static void main(String[] args) { AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext( AmsAmqpConfiguration.class); RabbitTemplate rabbitTemplate = (RabbitTemplate) context.getBean("rabbitTemplate"); CustomMessagePostProcessor postProcessor = new CustomMessagePostProcessor(); String testMessage = "This is a sample message to be prublished"; Object messageObject = testMessage; //rabbitTemplate.convertAndSend(messageObject); ==> This publish the message rabbitTemplate.convertAndSend(messageObject,postProcessor); ==> This doesnt publish the message } } class CustomMessagePostProcessor implements MessagePostProcessor{ @Override public Message postProcessMessage(Message message) throws AmqpException { message.getMessageProperties().setUserId("Test User ID"); message.getMessageProperties().setTimestamp(new Date()); return message; } }
ponsu...


Reply With Quote