如何在nodejs中实现rabbitmq

时间:2018-07-07 07:39:41

标签: rabbitmq rabbitmq-exchange

Error : TypeError: Cannot read property 'createChannel' of undefined

> Blockquote
  

Blockquote

    var amqp = require('amqplib/callback_api');        
        amqp.connect('amqp://localhost', function(err, conn) {
          conn.createChannel(function(err, ch) {
            var q = 'hello';        
            ch.assertQueue(q, {durable: false});
            console.log(" [*] Waiting for messages in %s. To exit press CTRL+C", q);
            ch.consume(q, function(msg) {
              console.log(" [x] Received %s", msg.content.toString());
            }, {noAck: true});
          });
        });

var amqp = require('amqplib/callback_api');    
        amqp.connect('amqp://localhost', function(err, conn) {         
          conn.createChannel(function(err, ch) {
            var q = 'hello';
            var msg = 'Hello World!';        
            ch.assertQueue(q, {durable: false});
            // Note: on Node 6 Buffer.from(msg) should be used
            ch.sendToQueue(q, new Buffer(msg));
            console.log(" [x] Sent %s", msg);
          });

        });

TypeError:无法读取未定义的属性'createChannel'             在D:\ samadhan \ Projects \ RabbitMQ \ sender.js:7:8             在D:\ samadhan \ Projects \ RabbitMQ \ node_modules \ amqplib \ callback_api.js:16:10             在套接字。 (D:\ samadhan \ Projects \ RabbitMQ \ node_modules \ amqplib \ lib \ connect.js:187:18)             在Object.onceWrapper(events.js:324:30)             在emitOne上(events.js:125:13)             在Socket.emit(events.js:221:7)             在emitErrorNT上(internal / streams / destroy.js:64:8)             在_combinedTickCallback(内部/进程/next_tick.js:138:11)             在process._tickCallback(internal / process / next_tick.js:180:9)

    D:\samadhan\Projects\RabbitMQ>enter code here

0 个答案:

没有答案