使用amqplib库无法在ReactJs中连接RabbitMQ

时间:2018-11-07 13:34:13

标签: reactjs react-redux rabbitmq

amqpLibTest(){
 alert("connection Started")
 let amqp = require('amqplib/callback_api');
 debugger
 amqp.connect('amqp://myuser:notapassword@123.123.123.xyz.com:5672', 
  function(err, conn) {
  console.log("Conn Values=======>", conn)
  conn.createChannel(function(err, ch) {
  let q = 'harbinger-dm-control-response';

ch.assertQueue(q, {durable: true});
console.log(" [*] Waiting for messages in %s. To exit press CTRL+C", q);
ch.consume(q, function(msg) {
let js = JSON.parse(msg.content.toString());
console.log(js);
 }, {noAck: true});
});
});
}

我正在尝试连接到在另一台服务器上运行的Rabbitmq服务。它给我下面的错误: Error of my Library

浏览器控制台中的错误是:-

  

未捕获的TypeError: webpack_require (...)。connect不是函数
      在连接时(connect.js:169)
      在Object.connect(callback_api.js:14)
      在App.amqpLibTest(App.js:54)
      在新的应用程序上(App.js:44)
      在ConstructClassInstance(react-dom.development.js:11447)
      在updateClassComponent(react-dom.development.js:13144)

0 个答案:

没有答案