ServiceBusTrigger scheduled message is undefined when read from the queue
See original GitHub issueWhen sending a scheduled message to service bus queue, when the message is passed on to the queue itself and an Azure Function is triggered (Service Bus Queue Trigger) the message is undefined
.
Repro steps
I am using https://github.com/Azure/azure-sdk-for-js for sending messages to the queue:
- Step A
public static async sendMessage(content: MessageDTO): Promise<string> {
const ns = AzureServiceBus.createConnection();
const client = ns.createQueueClient("" + process.env.AZURE_SERVICEBUS_SMS_QUEUE);
const sender = client.createSender();
let resp = "";
try {
const scheduledEnqueueTimeUtc = moment().utc().add(1, "m").toDate();
const long = await sender.scheduleMessage(scheduledEnqueueTimeUtc, {body: JSON.stringify(content), label: "Change"});
resp = long.toString();
await client.close();
} catch (error) {
winston.warn("Was not possible to send sms for changeId: " + content.changeId);
} finally {
await ns.close();
}
return resp;
}
private static createConnection(): ServiceBusClient {
winston.info("Creating connection on AZURE SERVICE BUS");
try {
return ServiceBusClient.createFromConnectionString("" + process.env.AZURE_SERVICEBUS_CONNECTION_STRING);
} catch (err) {
winston.error("Failed to create connection on AZURE SERVICE BUS", err.stack);
throw err;
}
}
- Step B
Receiving it on an azure function:
module.exports = async function (context, mySbMsg) {
context.log("JavaScript ServiceBus queue trigger function processed message", JSON.stringify(mySbMsg));
};
Expected behavior
mySbMsg
should not be undefined
Actual behavior
When the function is triggered mySbMsg
is undefined
:
bindings: Object {mySbMsg: undefined}
Known workarounds
Putting my message on the label
as in:
const message: SendableMessageInfo = {
body: JSON.stringify(content),
label: JSON.stringify(content),
};
Allows me to read the message from:
module.exports = async function (context, mySbMsg) {
const msg = mySbMsg ? JSON.parse(mySbMsg) : context.bindingData.label;
context.log("JavaScript ServiceBus queue trigger function processed message", msg);
}
Related information
Also opened this issue on #https://github.com/Azure/azure-sdk-for-js/issues/2144 and was suggested that I opened it up here as well as it might be a problem on the service bus trigger itself not being able to do the binding in a proper way.
- Package version
- Links to source
Issue Analytics
- State:
- Created 4 years ago
- Comments:8 (2 by maintainers)
Top Results From Across the Web
Azure Service Bus scheduled message "in" binding ...
The issue is caused by a bug in the @azure/service-bus sdk. Workaround. Import DefaultDataTransformer from "@azure/amqp-common" library.
Read more >Azure Service Bus scheduled message "in"
Coding example for the question Azure Service Bus scheduled message "in" binding undefined.
Read more >Azure Service Bus Explorer returning error when peeking ...
When using the Azure Service Bus Explorer to peek messages either in queue or deadletter, an error appears with the following message:
Read more >Azure Service Bus and its Complete Overview
Scheduled delivery. You can submit messages to a queue or topic for delayed processing; for example, to schedule a job to become available...
Read more >Sitemap - European SharePoint, Office 365 & Azure ...
Using Power Automate to schedule a refresh of a Power BI dataset at the time you want! Using Power Automate with Azure Queues...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Workaround:
@mathewc I’m using @azure/service-bus to send message. I set
contentType
onSendableMessageInfo
to"application/json"
and it didn’t change anything 😦