Search code examples
node.jsazure-eventhub

how to resolve unable to open amqp operation timeout issue in production?


Below is the eventhub producer code. The below issue is constantly occuring for my nodejs application since few days. Unable to open amqp connection connectionid =21 due to operation timeout

Producer.js

const { EventHubProducerClient } = require("@azure/event-hubs");

const connectionString = "EVENT HUBS NAMESPACE CONNECTION STRING";
const eventHubName = "EVENT HUB NAME";

async function main() {

  // Create a producer client to send messages to the event hub.
  const producer = new EventHubProducerClient(connectionString, eventHubName);

  // Prepare a batch of three events.
  const batch = await producer.createBatch();
  batch.tryAdd({ body: "First event" });
  batch.tryAdd({ body: "Second event" });
  batch.tryAdd({ body: "Third event" });    

  // Send the batch to the event hub.
  await producer.sendBatch(batch);

  // Close the producer client.
  await producer.close();

  console.log("A batch of three events have been sent to the event hub");
}

main().catch((err) => {
  console.log("Error occurred: ", err);
});

Package.json

"dependencies":{
"@azure/arm-eventhub":"3.3.0",
"@azure-eventhubs":"5.5.2",
"@azure/eventhubs-checkpointstore-blob":"1.0.1",
"@azure/identity":"1.4.0",
"@azure/storage-blob":"12.6.0",
"azure-arm-eventhub":"3.2.0"
}

NodeJs version is 10

Is there anyway to code a retry logic in case of these amqp failures? Can anyone help me out in resolving the issue?

Thank you in advance.


Solution

  • You can provide an option to the EventHubProducerClient.

    The retry option would include maxRetries and retryDelayInMs

    new EventHubProducerClient(connectionString: string, eventHubName: string, options?:{ "maxRetries": 4, "retryDelayInMs": 30000 })
    

    Refer Documentation.