0
votes

I have a java ActiveMQ producer which produces Integer messages into an ObjectMessage instance.

On the python side, I use stomp python for listening on the queue. However, I receive empty message body although all the headers are received right.

Moreover, if I change the message type to TextMessage on the java side, I get correct message on python-consumer side.

I have also tried with PyactiveMQ but with the same effect

Any suggestions will be appreciated!!!

EDIT: Here is a boilerplate java producer code and python subscriber code which i wrote to test stomp on python

public class App 
{
Connection conn;
Session session;
MessageProducer producer;

public void registerPublisher(String queueName, String url) throws JMSException {
    ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory("system", "manager" ,url);
    conn = cf.createConnection();
    conn.start();
    session = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
    Destination destination = session.createQueue(queueName);
    producer = session.createProducer(destination);
    producer.setDeliveryMode(DeliveryMode.PERSISTENT);

}

public void send(int c) {

    for (int i=0; i<c; ++i) {

        try {
            TextMessage tm = session.createTextMessage(new Integer(i).toString());
//              ObjectMessage tm = session.createObjectMessage();
            producer.send(tm);
        } catch (JMSException e) {
            e.printStackTrace();
        }

    }
}

public static void main(String []arg) {
    App app = new App();
    try {
        app.registerPublisher(arg[0], arg[1]);
        System.out.println(app.session);
    } catch (JMSException e) {
        e.printStackTrace();
    }
    app.send(1000);
}


}

And Python Stomp listener

import time
import sys
import logging
import stomp
from stomp import ConnectionListener

queuename = sys.argv[1]

logging.basicConfig( level=logging.DEBUG)

class MyListener(ConnectionListener):
    def on_error(self, headers, message):
        print 'received an error %s' % message

    def onMessage(self, headers, message):
        print headers
        print str(message)
        print type(message)
        print 'received a message ...%s...' % message


conn = stomp.Connection([('localhost', 61613)])                                                                                               
conn.set_listener('', MyListener())
conn.start()
conn.connect()


conn.subscribe(destination='/queue/'+queuename, ack='auto')


while 1:
    time.sleep(2)
2
give us some code fragments, where you create a message and where you read a message.Dmitry Zagorulkin

2 Answers

4
votes

In order to send an receive ObjectMessage types over Stomp you need to use the message transformation feature of ActiveMQ to have the object payload delivered in a form a STOMP client can understand. ActiveMQ provides XML and JSON transformation support out of the box however you can add your own transformer to get whatever format you want on the content.

2
votes

PROBLEM: Sending ObjectMessage from a java producer to ActiveMQ Broker. Stomp Python consumer client was getting empty message body

SOLUTION: Use transformation header while subscribing to the activemq broker in the python client,

for example:

connection.subscribe(destination='/queue/'+queuename, ack='auto', transformation="jms-json")

So that the broker knows in what form the message is to be sent to the stomp client