hi Hans
Your code looks perfectly correct, and the fact that normal sends work but scheduled messages fail with a connlost error points directly to a potential issue in the Go SDK's handling of the scheduling AMQP link.
This kind of error often happens when the underlying AMQP connection for the scheduling operation is dropped or times out before the broker can acknowledge the scheduled message.
Here are a few things to try to troubleshoot and work around this:
- Check your scheduled time horizon: Azure Service Bus has a maximum limit for how far in the future you can schedule a message (I believe it's up to 7 days). If your
scheduledTimeUTCis beyond this limit, it could cause an unexpected failure that manifests as a connection loss. Double-check that your scheduled time is within the supported range.
Try a much shorter timeout: You're using a 2-minute timeout, which is quite long. Sometimes, a shorter, more aggressive timeout can help isolate whether this is a genuine connection issue or a protocol-level problem. Try reducing it to 30 seconds to see if the failure mode changes.
Enable client-side logging: The Azure SDK for Go has built-in logging that can reveal the exact AMQP-level error. Enable debug logging to see what's happening under the hood. You can do this by setting the environment variable AZURE_SDK_GO_LOGGING to all before running your application.
Consider a workaround pattern: As an immediate workaround to unblock yourself, you could implement a "scheduling" mechanism yourself. Instead of using the built-in scheduled messages, send a normal message with a property indicating the desired enqueue time. Then, have a separate processor function that receives these messages, checks the timestamp, and re-sends them to the actual target queue if the current time has passed the scheduled time. It's more work, but it's reliable.
Given the specificity of this issue, it's also worth checking the GitHub issues for the azure-sdk-for-go repository to see if others have reported similar problems with the ScheduleMessages function in your version (v1.10.0).
regards,
Alex
and "yes" if you would follow me at Q&A - personaly thx.
P.S. If my answer help to you, please Accept my answer