Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <transportConnectors>
- <transportConnector name="stomp" uri="stomp://0.0.0.0:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
- </transportConnectors>
- #!/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
- #!/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 errorn %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
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement