Guest User

Untitled

a guest
Jan 30th, 2018
143
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.78 KB | None | 0 0
  1. #!/usr/bin/env python
  2. import time
  3.  
  4. import pika
  5.  
  6. connection = pika.BlockingConnection(pika.ConnectionParameters(
  7. host='localhost'))
  8. channel = connection.channel()
  9.  
  10. channel.queue_declare(queue='hound')
  11.  
  12. def callback(ch, method, properties, body):
  13. print(" [x] Received %r" % (body,))
  14. time.sleep(5)
  15. print(" [x] Done")
  16. ch.basic_ack(delivery_tag = method.delivery_tag)
  17.  
  18. channel.basic_consume(callback,
  19. queue='hound',
  20. )
  21.  
  22. print(' [*] Waiting for messages. To exit press CTRL+C')
  23. channel.start_consuming()
  24.  
  25. #include <SimpleAmqpClient/SimpleAmqpClient.h>
  26.  
  27. using namespace AmqpClient;
  28.  
  29. int main(int argc, char *argv[])
  30. {
  31. Channel::ptr_t channel;
  32.  
  33. channel = Channel::Create("SERVER_HOST", SERVER_PORT,
  34. "LOGIN", "PASS", "/");
  35.  
  36. BasicMessage::ptr_t msg = BasicMessage::Create("HELLO!!!");
  37. channel->DeclareQueue("hound");
  38. channel->BasicPublish("", "hound", msg, true);
  39. }
  40.  
  41. terminate called after throwing an instance of 'AmqpClient::PreconditionFailedException'
  42. what(): channel error: 406: AMQP_QUEUE_DECLARE_METHOD caused: PRECONDITION_FAILED - parameters for queue 'hound' in vhost '/' not equivalent
  43. Aborted
  44.  
  45. #!/usr/bin/env python
  46. import sys
  47. import pika
  48.  
  49. credentials = pika.PlainCredentials(
  50. username=username, password=password
  51. )
  52.  
  53. connection = pika.BlockingConnection(
  54. pika.ConnectionParameters(
  55. host=host,
  56. virtual_host=virtual_host,
  57. credentials=credentials,
  58. port=RABBIT_PORT
  59. )
  60. )
  61.  
  62. channel = connection.channel()
  63. channel.queue_declare(queue='hound')
  64.  
  65. channel.basic_publish(exchange='',
  66. routing_key='hound',
  67. body='hello!')
  68. print(" [x] Sent %r" % (message,))
Add Comment
Please, Sign In to add comment