I have ActiveMQ deployed with stomp support
<transportConnectors> <transportConnector name="stomp" uri="stomp://0.0.0.0:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/> </transportConnectors> A client is connected to ActiveMQ, which can send messages:
#!/usr/bin/python2 # -*- coding: utf-8 -*- from stompy import stomp try: s = stomp.Stomp(amq_ip, amq_port) s.connect(username=amq_user, password=amq_pass) # подключаемся к AMQ body = '{"sample_msg": "%s"}' % "for second client" message = { "destination": "/queue/test_queue", "body": body, "persistent": "true" } s.send(message) # отправляем сообщение except stomp.ConnectionError: print u"Couldn't connect to the STOMP server." except stomp.ConnectionTimeoutError: print u"Timed-out while establishing connection to the STOMP server." except stomp.NotConnectedError: print u"No longer connected to the STOMP server." except Exception as e: print e and several clients who can accept the message:
#!/usr/bin/python2 # -*- coding: utf-8 -*- from stompy import stomp import json s = stomp.Stomp(amq_ip, amq_port) try: s.connect(username=amq_user, password=amq_pass) s.subscribe({'destination': '/queue/%s' % amq_queue, 'ack': 'client'}) except Exception as e: print "ActiveMQ error\n %s" % e while True: try: frame = s.receive_frame() body = json.loads(frame.body) # это сообщение для меня? if body["sample_msg"] == "for first client": print "Its for me. I receive it" # Это сообщение для меня. Я его приму и обработаю s.ack(frame) else: # Это сообщение предназначено для кого-то другого и мне не подходит print "Its not for me" except Exception as e: print e In the current configuration, only one client picks up the message from AMQ. But not the fact that this particular client should process this message.
How do I broadcast a message? Or maybe there is an opportunity to identify customers subscribed to the queue?