Announcement Announcement Module
No announcement yet.
Using Message and MessageProperties classes Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Using Message and MessageProperties classes


    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
    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
    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
      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

      In the meantime, switch to using a send() method.


      • #4
        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:

        container.setMessageListener(new MessageListenerAdapter(new AMessageHandler()));
        AMessageHandler code:
        public 	void handleMessage(Message msg) {"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()):
        public 	void handleMessage(String text) {"AMessageHandler Received: " + text);
        Looking for guidance. Thanks.


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


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