1

I want to push service bus message using inbuilt functionality provided by the azure web job sdk. https://github.com/Azure/azure-webjobs-sdk/wiki/Service-Bus this link is mentioned how to do but not clear yet

Cœur
  • 37,241
  • 25
  • 195
  • 267
smith
  • 73
  • 1
  • 8

1 Answers1

0

Service Bus has provided all prerequisites and code snippets for you to receive / create Service Bus messages.

To write a function that creates a new queue message use the ServiceBus attribute and pass in the queue name to the attribute constructor.

Create a single queue message:

public static void CreateServiceBusQueueMessage(
    [ServiceBusTrigger("inputqueue")] string queueMessage,
    [ServiceBus("<your-queue-name>")] out string outputMessage)
{
    outputMessage = queueMessage;
}

The output parameter for creating a single queue message can be any of the following types:

  • string
  • byte[]
  • BrokeredMessage
  • A serializable POCO type that you define. Automatically serialized as JSON.

For creating a Service Bus topics message:

public static void CreateServiceBusTopicMessage(
    [ServiceBusTrigger("inputqueue")] string queueMessage,
    [ServiceBus("<your-topic-name>")] out string outputMessage)
{
    outputMessage = queueMessage;
}

Moreover, you could also use TimerTrigger, FileTrigger, QueueTrigger, BlobTrigger, EventHubTrigger to trigger the execution of your function to create service bus queue/topic messages. Details you could follow here and Microsoft Azure WebJobs SDK ServiceBus Sample.

Bruce Chen
  • 18,207
  • 2
  • 21
  • 35
  • thanks for the answer, actually those information i could see from the sdk. but could not come up with correct code example. is CreateServiceBusTopicMessage inbuilt function? – smith Jun 15 '18 at 08:16
  • In general, `CreateServiceBusTopicMessage` is just a custom method defined under `Functions.cs` which would be picked up by WebJobs SDK, you could rename it as you expected and add multiple methods under `Functions.cs`. AFAIK, Azure WebJobs SDK would pick up the proper public methods under public classes. Moreover, you could download the sample https://github.com/Azure/azure-webjobs-sdk-samples/tree/master/BasicSamples/ServiceBus to run it locally, and modify it to have a better understanding of WebJobs. – Bruce Chen Jun 15 '18 at 08:34