下面是偶数生产者代码。下面的问题是不断发生在我的nodejs应用程序,因为几天。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版本为10
在这些amqp失败的情况下,是否有任何方式来编码重试逻辑?有人能帮我解决这个问题吗?
提前谢谢你。
您可以为EventHubProducerClient
提供一个选项。
重试选项将包括maxRetries
和retryDelayInMs
new EventHubProducerClient(connectionString: string, eventHubName: string, options?:{ "maxRetries": 4, "retryDelayInMs": 30000 })
参考文档。