question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

ServiceBusTrigger scheduled message is undefined when read from the queue

See original GitHub issue

When 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:

  1. 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;
    }
}
  1. 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:open
  • Created 4 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
yann-hcommented, Jul 22, 2019

Workaround:

sender.send({
    messageId: "...",
    partitionKey: "...",
    scheduledEnqueueTimeUtc: ...,
    body: { ... }
})

1reaction
AlexZhidkovcommented, Jun 4, 2019

@mathewc I’m using @azure/service-bus to send message. I set contentType on SendableMessageInfo to "application/json" and it didn’t change anything 😦

Read more comments on GitHub >

github_iconTop 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 &quot;in&quot
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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found