How to trigger a ServiceBusTrigger?

388 views Asked by At

I have an Azure WebJob which has a similar code inside:

public class Functions
{
    public static void GenerateImagesForViewer(
    [QueueTrigger("resize-images-queue")] BlobInformation blobInfo,
    [Blob("unprocessed-pdf-storage-container/{BlobName}", FileAccess.Read)] Stream input,
    [Blob("unprocessed-pdf-storage-container/{BlobNameWithoutExtention}-pdf.jpg")] CloudBlockBlob outputPdf)
    {            
        //Do something here
        string connectionString = "myConnectionString";
        TopicClient Client = 
        TopicClient.CreateFromConnectionString(connectionString, "resize- 
        images-topic");
        var topicMessage = new BrokeredMessage(blobInfo);
        Client.Send(topicMessage);
    }

    public static void GenerateImagesForViewerW80(
    [ServiceBusTrigger("resize-images-topic", "SizeW80")] BlobInformation blobInfo,
    [Blob("unprocessed-pdf-storage-container/{BlobNameWithoutExtention}-pdf.jpg", FileAccess.Read)] Stream input,
    [Blob("processed-image-storage-container/{BlobNameWithoutExtention}-h0-w80.jpg")] CloudBlockBlob outputBlob_0_80)
    {
      // It never comes here
      //Do something here
    }
}

After uploading data (BlobInformation object) to my Queue there is no problem triggering the first method (GenerateImagesForViewer). But when I try to send data (BlobInformation object) to the topic it never triggers any of the subscribers(GenerateImagesForViewerW80). Is there something wrong in the code, or there is a required configuration in Azure?

1

There are 1 answers

5
Jerry Liu On BEST ANSWER

In Program.cs, config.UseServiceBus(); is necessary for usage of ServiceBus trigger. We won't see warning if there are other trigger or bindings in Functions, like your case.

See code sample below and check official guidance for more details.

        var config = new JobHostConfiguration();

        if (config.IsDevelopment)
        {
            config.UseDevelopmentSettings();
        }
        config.UseServiceBus();
        var host = new JobHost(config);
        host.RunAndBlock();

Besides, I see some suspicious blank in your input and output blob path. If it's the same as your original code, just remove them otherwise the trigger won't execute code related to blob operation correctly.