I'm using @azure/service-bus JavaScript library to publish and subscribe to messages on Azure Service Bus topic from Azure Functions. To receive messages, I'm using Azure Service Bus Topic trigger function created from the template without any changes. When I publish message using sender.send(message) I receive it fine.
import { AzureFunction, Context, HttpRequest } from "@azure/functions"
import * as sb from "@azure/service-bus"
const PublishToServiceBus: AzureFunction = async function (context: Context, req: HttpRequest): Promise<void> {
const eventDoc = req.body;
const serviceBusConnectionString = process.env["ServiceBusConnection"];
const topicName = process.env["TopicName"]';
const sbClient = sb.ServiceBusClient.createFromConnectionString(serviceBusConnectionString);
const topicClient = sbClient.createTopicClient(topicName);
const sender = topicClient.createSender();
const message: sb.SendableMessageInfo = { body: eventDoc };
// this works
sender.send(message);
// this creates message without body?
const scheduledEnqueueTimeUtc = new Date(Date.now() + 10000);
sender.scheduleMessages(scheduledEnqueueTimeUtc, [message]);
};
export default PublishToServiceBus;
But when I schedule message with sender.scheduleMessages(), my incoming binding variable is undefined in Azure Service Bus Topic trigger function.
import { AzureFunction, Context } from "@azure/functions"
const serviceBusTopicTrigger: AzureFunction = async function (context: Context, mySbMsg: any): Promise<void> {
context.log('ServiceBus topic trigger function processed message', mySbMsg);
};
export default serviceBusTopicTrigger;
Output: ServiceBus topic trigger function processed message undefined
Is this a problem with the library or I'm doing something wrong?