gpt4 book ai didi

node.js - node-amqp 无法向 RabbitMQ 发送消息

转载 作者:IT老高 更新时间:2023-10-28 23:26:44 26 4
gpt4 key购买 nike

我正在尝试 rabbitmq-tutorials , ruby​​ 版本工作正常,但 node.js 版本无法发送消息。不知道怎么回事。

var amqp       = require('amqp');
var amqp_hacks = require('./amqp-hacks');

var connection = amqp.createConnection({host: 'localhost'});

connection.on('ready', function(){
connection.publish('hello_node', 'Hello World!');
console.log(" [x] Sent 'Hello World!'");

amqp_hacks.safeEndConnection(connection);
});

运行 node send.js 后,运行进程 node recv.js 无法接收任何内容。并且 rabbitmqctl list_queues 不显示 hello_node 队列。

最佳答案

您需要指明队列然后发布。该版本应该可以工作:

    var amqp       = require('amqp');
var amqp_hacks = require('./amqp-hacks');

var connection = amqp.createConnection({host: 'localhost'});

connection.on('ready', function(){
connection.queue('hello_node', {'durable': false}, function(q){
connection.publish('hello_node', 'Hello World!');
console.log(" [x] Sent 'Hello World!' to 'hello_node'");

amqp_hacks.safeEndConnection(connection);
});
});

关于node.js - node-amqp 无法向 RabbitMQ 发送消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/16144665/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com