Polling an Azure Service Bus Queue from an Azure WebJob using Node.js

前端 未结 3 2017
闹比i
闹比i 2021-01-14 19:55

Trying to poll an Azure Service Bus Queue using a WebJob written in Node.js. I created 2 WebJobs. The first is on demand and sends 10 unique messages to the queue. The secon

相关标签:
3条回答
  • 2021-01-14 20:15

    Switching off the partitioned flag of the Service Bus queue worked for me, too.

    With the partitioned queue some messages had delays of more than 30 minutes. A simple DotNet webclient could download all messages without any delays. However, as soon as nodejs was supposed to download messages, only the first message would be downloaded without problems, afterwards delays showed up. Playing with nodejs to change the http agent options keepalive and socket timeout did not improve the situation.

    After stopping nodejs, I had to wait several minutes before the DotNet client actually started working without problem. This was reproducable several times. I also found the simple DotNet webclient program showed similar problems, after being started and stopped several times in a row.

    Anyway, your post showed me the solution: Turn off the partitioned flag :)

    0 讨论(0)
  • 2021-01-14 20:22

    Try using the amqp to read the messages off the azure service bus partitioned queue and this will work for a partitioned topic/queue and you don't even have to poll a lot.

    const AMQPClient = require('amqp10').Client;
    const Policy = require('amqp10').Policy;
    
    const protocol = 'amqps';
    const keyName = 'RootManageSharedAccessKey';
    const sasKey = 'your_key_goes_here';
    const serviceBusHost = 'namespace.servicebus.windows.net';
    const uri = `${protocol}://${encodeURIComponent(keyName)}:${encodeURIComponent(sasKey)}@${serviceBusHost}`;
    const queueName = 'partitionedQueueName';
    const client = new AMQPClient(Policy.ServiceBusQueue);
    client.connect(uri)
    .then(() => Promise.all([client.createReceiver(queueName)]))
    .spread((receiver) => {
        console.log('--------------------------------------------------------------------------');
        receiver.on('errorReceived', (err) => {
            // check for errors
            console.log(err);
        });
        receiver.on('message', (message) => {
            console.log('Received message');
            console.log(message);
            console.log('----------------------------------------------------------------------------');
        });
    })
    .error((e) => {
        console.warn('connection error: ', e);
    });
    

    https://www.npmjs.com/package/amqp10

    0 讨论(0)
  • 2021-01-14 20:27

    And the issue was the queue I was using was partitioned (the default option when creating a queue in the Azure portal). Once I created a new queue that was not partitioned, everything worked as expected without the lag (other than the weird 230 second timeout on a long poll attempt). So basically the node.js library doesn't work for partitioned queues. At all. Wasted many days figuring that one out. Will leave this here for others.

    0 讨论(0)
提交回复
热议问题