how to set sessionId while using Service Bus Queue as output bindings for Azure Function with javascript

Ahsan Habib 126 Reputation points
2020-06-25T08:26:03.337+00:00

Hello!

I am using an Azure Function with Javascript/TypeScript SDK where Azure Event Hub is the trigger and and Service Bus is the output. i.e. I am getting data from Event Hubs, then processing it in Azure Function, after that output the processed data to Service Bus Queue. As I need ordered Service Bus, I need to set SessionId. I see the option to bind message body. However, do not see where to bind the sessionId.

The Function provides something like this option for the Service Bus Output.

context.bindings.myServiceBus = myServiceBusMessageBody;

So where to put the sessionId?

Azure Service Bus
Azure Service Bus
An Azure service that provides cloud messaging as a service and hybrid integration.
547 questions
Azure Functions
Azure Functions
An Azure service that provides an event-driven serverless compute platform.
4,281 questions
0 comments No comments
{count} votes

Accepted answer
  1. Krish G 2,326 Reputation points
    2020-06-26T15:34:24.803+00:00

    Hello @AhsanHabib-1895 ,

    Built-in output binding in javascript based function currently does not support setting message properties other than body. There is an open github issue similar to this. Also. please feel free to provide feedback as feature request here.

    As an work around, you can use service bus client to send message to a queue instead of using output binding like below.

    • You need to install @azure/service-bus npm package.

    npm install @azure/service-bus

    • Import the required service client at the top of your index.js.

    const { ServiceBusClient } = require("@azure/service-bus");

    • Follow the below code sample to directly use SB client to send message with session id: const sbClient = ServiceBusClient.createFromConnectionString(connectionString);
      const queueClient = sbClient.createQueueClient(queueName);
      const sender = queueClient.createSender();
      const message= {
      body: 'your message body, can be string, js object or byte array',
      sessionId: 'your session id'
      };
      await sender.send(message);

    Also, if you prefer, you can leverage C# based function which has built-in support to set properties of BrokeredMessage object in output binding.

    Please let me know if you have any question. Also if it helps, please consider accepting as answer which can help other community members with similar queries.

    1 person found this answer helpful.
    0 comments No comments

0 additional answers

Sort by: Oldest