美文网首页Node.js
node-amqp exchange.publish callb

node-amqp exchange.publish callb

作者: 老码农不上班 | 来源:发表于2016-12-07 21:14 被阅读27次

    I met a problem when using exchange.publish to push message.
    my code fragment as follow

    exc.pushblish('', JSON.stringify(message), {}, function(){
      console.log("message published");
    });
    

    Every time push the message, would output the log, sadly it can't work as my expect.
    After read the doc exchange.publish(routingKey, message, options, callback), I found some description:

    callback
    is a function that will get called if the exchange is in confirm mode, the value sent will be true or false, this is the presense of a error so true, means an error occured and false, means the publish was successfull

    my exchange object new as:

    var exc = connection.exchange("ethereum.exchange", options = { type: 'fanout', durable: true, autoDelete: false  }, function(exchange){
      console.log("exchange" + exchange.name + "is opened");
    });
    

    horriblely! without confirm mode when create exchange, when publish message, it would the callback function would not be called.
    So, to solve the problem, we should add confirm: true for connection.exchange function second args options.

    相关文章

      网友评论

      • auguszou:last paragraph:to save the problem?

      本文标题:node-amqp exchange.publish callb

      本文链接:https://www.haomeiwen.com/subject/rgrjmttx.html