Advertisement
Guest User

Untitled

a guest
Dec 12th, 2016
82
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.79 KB | None | 0 0
  1. <transportConnectors>
  2. <transportConnector name="stomp" uri="stomp://0.0.0.0:61616?maximumConnections=1000&wireFormat.maxFrameSize=104857600"/>
  3. </transportConnectors>
  4.  
  5. #!/usr/bin/python2
  6. # -*- coding: utf-8 -*-
  7. from stompy import stomp
  8.  
  9.  
  10. try:
  11. s = stomp.Stomp(amq_ip, amq_port)
  12. s.connect(username=amq_user, password=amq_pass) # подключаемся к AMQ
  13. body = '{"sample_msg": "%s"}' % "for second client"
  14. message = {
  15. "destination": "/queue/test_queue",
  16. "body": body,
  17. "persistent": "true"
  18. }
  19. s.send(message) # отправляем сообщение
  20. except stomp.ConnectionError:
  21. print u"Couldn’t connect to the STOMP server."
  22. except stomp.ConnectionTimeoutError:
  23. print u"Timed-out while establishing connection to the STOMP server."
  24. except stomp.NotConnectedError:
  25. print u"No longer connected to the STOMP server."
  26. except Exception as e:
  27. print e
  28.  
  29. #!/usr/bin/python2
  30. # -*- coding: utf-8 -*-
  31. from stompy import stomp
  32. import json
  33.  
  34.  
  35. s = stomp.Stomp(amq_ip, amq_port)
  36.  
  37. try:
  38. s.connect(username=amq_user, password=amq_pass)
  39. s.subscribe({'destination': '/queue/%s' % amq_queue, 'ack': 'client'})
  40. except Exception as e:
  41. print "ActiveMQ errorn %s" % e
  42.  
  43. while True:
  44. try:
  45. frame = s.receive_frame()
  46. body = json.loads(frame.body)
  47.  
  48. # это сообщение для меня?
  49. if body["sample_msg"] == "for first client":
  50. print "Its for me. I receive it"
  51. # Это сообщение для меня. Я его приму и обработаю
  52. s.ack(frame)
  53. else:
  54. # Это сообщение предназначено для кого-то другого и мне не подходит
  55. print "Its not for me"
  56. except Exception as e:
  57. print e
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement