我试图在nodejs项目中使用activemq。我使用依赖项"stomp"("^0.1.1")
。
我想为“ activemq队列”创建一个使用者。但是实际上在activemq指挥官页面(Apache ActiveMQ Console
)中,我看到了两个使用者。
对于将信息发送到队列,有时一个消费者使用它而不使用正确的代码逻辑进行处理。
我想知道为什么有两个消费者以及如何解决它。 谢谢。
var stomp = require('stomp');
var domain = require('./domain');
var log4js = require('log4js');
log4js.configure('./config/log4js.json');
var logger = require('log4js').getLogger("stompUtils");
// Set to true if you want a receipt of all messages sent.
var receipt = true;
// Set debug to true for more verbose output.
// login and passcode are optional (required by rabbitMQ)
var stomp_args = {
port: domain.stomp_port,
host: domain.stomp_host,
debug: domain.stomp_debug,
login: domain.stomp_login,
passcode: domain.stomp_pwd,
};
var client = new stomp.Stomp(stomp_args);
client.connect();
const depositEventQueue = '/queue/DEPOSIT_EVENT_QUEUE';
const withdrawEventQueue = '/queue/WITHDRAW_EVENT_QUEUE';
client.on('connected', function() {
client.subscribe({destination: withdrawEventQueue}, function (body, header) {
logger.info("withdraw success");
logger.info(body);
parseWithdrawInfo(body);
});
client.subscribe({destination: depositEventQueue}, function (body, header) {
logger.info("deposit success");
logger.info(body);
parseDepositInfo(body[0]);
});
});
client.on('receipt', function(receipt) {
logger.info("activemq get receipt: " + receipt);
});
client.on('error', function(error_frame) {
logger.error("activemq get error ", error_frame.body);
});
process.on('SIGINT', function() {
logger.info('sigint for activemq');
client.disconnect();
process.exit(0);
});