Results 1 to 3 of 3

Thread: Error in sending message properties by convertAndSend()

  1. #1
    Join Date
    Feb 2011
    Posts
    12

    Default 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. #2
    Join Date
    Jun 2005
    Posts
    4,230

    Default

    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. #3
    Join Date
    Feb 2011
    Posts
    12

    Default

    Thanks Dave. That worked...

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •