receive_logs_topic.js 959 B

12345678910111213141516171819202122232425262728293031323334
  1. const amqp = require('amqplib/callback_api');
  2. amqp.connect('amqp://test2:test2@114.115.203.60:8071/test', function (error0, connection) {
  3. if (error0) {
  4. throw error0;
  5. }
  6. connection.createChannel(function (error1, channel) {
  7. if (error1) {
  8. throw error1;
  9. }
  10. const exchange = 'ex.test';
  11. channel.assertExchange(exchange, 'topic', {
  12. durable: true
  13. });
  14. channel.assertQueue('', {
  15. exclusive: true
  16. }, function (error2, q) {
  17. if (error2) {
  18. throw error2;
  19. }
  20. console.log(' [*] Waiting for logs. To exit press CTRL+C');
  21. channel.bindQueue(q.queue, exchange, 'test3');
  22. channel.consume(q.queue, function (msg) {
  23. console.log(" [x] %s:'%s'", msg.fields.routingKey, msg.content.toString());
  24. }, {
  25. noAck: true
  26. });
  27. });
  28. });
  29. });