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

  • Error in sending message properties by convertAndSend()

    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.

    Code:
    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;
    	}
    	
    }
    Thanks in Advance
    ponsu...

  • #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.

    Comment


    • #3
      Thanks Dave. That worked...

      Comment

      Working...
      X