Kingsley
Kingsley

Reputation: 14926

Python Stomp connection to ActiveMQ has wrong Topic Name

I'm trying to form a Python + Stomp subscription to an ActiveMQ server. I'm testing against an ActiveMQ server on localhost. It all seems to work OK, except the subscription name for Topic XYZ is being named ActiveMQ.Advisory.Consumer.Queue.XYZ, and the queue I want to connect to (created by a java client) is named only XYZ.

Is there a way to get subscribed to this "short" name queue?

import stomp

QUEUE_NAME='XYZ'

class MyListener(stomp.ConnectionListener):
    def on_error(self, headers, message):
        print('received an error "%s"' % message)
    def on_message(self, headers, message):
        print('received a message "%s"' % message)

headers = {}
conn = stomp.Connection( )
conn.set_listener('127.0.0.1:61616', MyListener())
conn.start()
conn.connect('admin', 'admin', wait=True)

conn.subscribe(destination=QUEUE_NAME, id=2, ack='auto')

time.sleep(6660)
conn.disconnect()

The local ActiveMQ Console shows the "Topic": Screenshot of ActiveMQ Topics panel

Whereas the real server has a short-named queue: Correct Name

Upvotes: 0

Views: 2418

Answers (2)

Kingsley
Kingsley

Reputation: 14926

Finally got back to this problem... After reading some other examples, I guessed at an answer, tested, and it worked (phew!). Previously I could see my own messages, but the target subscriber (written in java) never received my messages.

If you want to send to an existing ActiveMQ queue with the current stomp library, the queue name needs to be prefixed with /topic/. For example (as per my question) if you want to send to the queue named XYZ, the stomp sending code needs to use a destination of /topic/XYZ. If this is documented somewhere, I could not find it!

Obligatory code snippet:

import time
import stomp

MQ_SERVER     = "192.168.1.111"
MQ_PORT       = 61613
MQ_USERNAME   = "user"
MQ_PASSWORD   = "pass"
MQ_QUEUENAME  = 'XYZ'

conn = stomp.Connection( [( MQ_SERVER, MQ_PORT )] )
conn.start()
conn.connect( MQ_USERNAME, MQ_PASSWORD, wait=True )

for i in range( 3 ):
    conn.send( body="Hello World", destination='/topic/'+MQ_QUEUENAME )  # <- HERE
    time.sleep( 1 )

conn.disconnect()

I'm not sure if this is only for ActiveMQ, or for other message-system flavours.

Upvotes: 2

Justin Bertram
Justin Bertram

Reputation: 35122

This looks like normal broker behavior in order to support "advisory messages". It shouldn't have any direct impact on your application. See the ActiveMQ documentation on this subject for more details.

Upvotes: 2

Related Questions