Results 1 to 6 of 6

Thread: Using Message and MessageProperties classes

Hybrid View

  1. #1
    Join Date
    Mar 2012
    Posts
    4

    Default Using Message and MessageProperties classes

    Hi,

    I am trying out a few prototypes with Spring-AMQP using RabbitMQ. I am able to send and receive simple text messages using the RabbitTemplate.convertAndSend() method.

    However, I need to send binary content in the message body and need to utilize the MessageProperties class for additional information. Can I use only the RabbitTemplate.send(Message) method and not the convertAndSend?

    I tried using the RabbitTemplate.send(Message) at the message producer and overloaded the handleMessage(Message) method at the consumer end - for the registered message handler with the MessageListenerAdapter class. This particular overloaded method is not being called. [when a simple text is passed with convertAndSend method, the message handler's handleMessage(String text) is promptly called.]

    Can someone please help me in getting this sorted out?

  2. #2
    Join Date
    Mar 2012
    Posts
    4

    Default

    I am able to send binary and text content (read from a file) to the consumer now. But it only works if I send it as a String using rabbitTemplate.convertAndSend(strMsg).
    The public void onMessage(Message message) on the consumer is promptly processing the message.

    If I try something like
    Code:
    Message msg = new Message(strMsg.getBytes(), messageProps); rabbitTemplate.convertAndSend(QueueName,msg,postProcessor);
    the message is not received by the same consumer.

    BTW, I am using JsonMessageConverter for the producer and consumer.

    Please help out in cracking this. Thanks in advance.

  3. #3
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,151

    Default

    If it's already a Message, you should call send() not convertAndSend() (it doesn't need conversion).

    We should probably either detect you are using this incorrectly, or simply don't do a conversion if the object is already a message (that's what we do with JMS).

    Please open an 'Impovement' JIRA here

    https://jira.springsource.org/browse/AMQP

    In the meantime, switch to using a send() method.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  4. #4
    Join Date
    Mar 2012
    Posts
    4

    Default

    Thanks for the response, Gary. I will raise the issue in JIRA.

    I tried using the send() method. The listener still does not process the Message payload (only String is handled).

    Excerpts from the listener code:

    Code:
    container.setMessageListener(new MessageListenerAdapter(new AMessageHandler()));
    AMessageHandler code:
    Code:
    public 	void handleMessage(Message msg) {
    	logger.info("AMessageHandler Received: " + msg.toString());
    }
    does not get invoked at all when a Message object is passed via send(QueueName, msg);

    However, the following AMessageHandler code gets invoked when a String is passed (through convertAndSend()):
    Code:
    public 	void handleMessage(String text) {
    	logger.info("AMessageHandler Received: " + text);
    }
    Looking for guidance. Thanks.

  5. #5
    Join Date
    Mar 2010
    Location
    Gtr Philadelphia, PA
    Posts
    2,151

    Default

    Well, you need to make sure the message is sent properly. Are you sure you are using the same routing key?

    In your convertAndSent() example (post#3), you were using the template's default routing key, but in your send() example (also post#3) you are passing in the routing key in a variable 'QueueName'.

    If you haven't already, you should install the rabbit management plugin so you can see message counts in the broker.
    Gary P. Russell
    Spring Integration Team
    SpringSource, a division of VMware

  6. #6
    Join Date
    Mar 2012
    Posts
    4

    Default

    Thanks to Gary, I was able to fix the issue discussed above. The problem was with the userId property of MessageProperties - if you set it a different value from the one you set for the ConnectionFactory, the broker (RabbitMQ) drops the message.

Posting Permissions

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