'Frequent timeout errors from Azure ServiceBus
Using Azure SDK example code as inspiration I have coded a publishing function that sends a message to the specified queue name.
export const publisher = async (message: ServiceBusMessage, queueName: string) => {
let sbClient, sender;
try {
sbClient = new ServiceBusClient(SB_CONNECTION_STRING);
sender = sbClient.createSender(queueName);
await sender.sendMessages([message]);
await sender.close();
} catch (err) {
console.log(`[Service Bus] error sending message ${queueName}`, err);
console.log("retrying message publish...");
publisher(message, queueName);
} finally {
await sbClient.close();
}
};
Most of the time this code works flawlessly but occasionally the connection times out and I retry sending within the catch block which seems to work all the time.
The message I'm sending are quite small:
{
body: {
type: PROCESS_FILE,
data: { type: CURRENT, directory: PENDING_DIRECTORY }
}
}
And example of the log output that includes the thrown error by the Azure SDK:
[08/03/2022 12:40:55.191] [LOG] [X] Processed task
[08/03/2022 12:40:55.346] [LOG] [X] Processed task
[08/03/2022 12:40:55.545] [LOG] [X] Processed task
[08/03/2022 12:41:27.840] [LOG] [Service Bus] error sending message local.importer.process { ServiceBusError: ETIMEDOUT: connect ETIMEDOUT 40.127.7.243:5671
at translateServiceBusError (/usr/share/app/node_modules/@azure/service-bus/src/serviceBusError.ts:174:12)
at MessageSender.open (/usr/share/app/node_modules/@azure/service-bus/src/core/messageSender.ts:304:31)
at process._tickCallback (internal/process/next_tick.js:68:7)
name: 'MessagingError',
retryable: false,
address: '40.127.7.243',
code: 'GeneralError',
errno: 'ETIMEDOUT',
port: 5671,
syscall: 'connect' }
[08/03/2022 12:41:27.840] [LOG] retrying message publish...
[08/03/2022 12:41:28.756] [LOG] [X] Processed task
I am not sure on how to proceed. Azure documentation recommends that you retry the message in the case of a timeout which I am doing however the timeouts are so frequent that it concerns me.
Does any kind soul have some insight into this from previous experience? I am using "@azure/service-bus": "^7.3.0",
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
