Announcement Announcement Module
No announcement yet.
Error in sending message properties by convertAndSend() Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Error in sending message properties by convertAndSend()


    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.

    public class ProducerTest {
    	public static void main(String[] args) {			
    		AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(
    		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{
    	public Message postProcessMessage(Message message) throws AmqpException {
    	                message.getMessageProperties().setUserId("Test User ID");
    		message.getMessageProperties().setTimestamp(new Date());
    		return message;
    Thanks in Advance

  • #2
    My guess would be that "Test User ID" is not the user that is authenticated (default is "guest"), so it barfs with a not-permitted error If you look at the protocol exchange you will see a 406 return code from the broker.


    • #3
      Thanks Dave. That worked...