noodlefrenzy / node-amqp10

amqp10 is a promise-based, AMQP 1.0 compliant node.js client
MIT License
134 stars 56 forks source link

Duplicate on message handlers. #358

Open tony-gutierrez opened 6 years ago

tony-gutierrez commented 6 years ago

I have to use logic in a 'connection:opened' handler to send a sas token.

If I do anything with the client in this 'connection:opened' event handler, I get two calls to my "on message" handler, regardless of where my receiver was created. I have verified I am only creating one receiver, once.

karlvlam commented 6 years ago

I have the same issue.

karlvlam commented 6 years ago

@tony-gutierrez I get the same issue. But when I pause for a while/ use nextTick in the event function, it do not raise duplicated message again.

Here's my workaround.

let client = null; 

function createReceivers() {
  // create receiver links
}

async function reconnectClient() {
    client = new AMQP.Client(policy);
    client.on('connection:opened', async function(){ 
        logger.info('[ListenConn]: opened');
        process.nextTick(createReceivers);       
    });

   try{
        await amqpConnListen.connect(config['MQ_CONNECT_STRING']);
    }catch(err){
      logger.error(err);
    }
}
princjef commented 6 years ago

Have you tried listening to the connected event instead of connection:opened? That won't fire until your connection and session(s) have been initialized, at which point you should be able to do whatever you want with links, etc.