如何创建服务总线触发webjob? [英] How to create service bus trigger webjob?

查看:80
本文介绍了如何创建服务总线触发webjob?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我检查了

I check the doc use the below code to configure the webjob to create service bus trigger function.

    static void Main()
{
    var builder = new HostBuilder();
    builder.ConfigureWebJobs(b =>
    {
        b.AddAzureStorageCoreServices();
        b.AddServiceBus(sbOptions =>
        {
            sbOptions.MessageHandlerOptions.AutoComplete = true;
            sbOptions.MessageHandlerOptions.MaxConcurrentCalls = 16;
        });
    });
    var host = builder.Build();
    using (host)
    {

        host.Run();
    }
}

但是,当我尝试实现它时,AddServiceBus方法不可用,即使添加了服务总线触发功能,它也总是报告未找到作业功能错误.

However when I try to implement it, the AddServiceBus method is not available, even add the service bus trigger function it always reports No job functions found error.

那么配置错误在哪里,谢谢您的帮助.

So where is the configuration error, thanks for any help.

推荐答案

根据我的经验,创建webjob时使用的软件包不正确.如果您检查

Per my experience when you create the webjob you are not using the correct package. If you check the service bus binding doc, you will find it need Microsoft.Azure.WebJobs.Extensions.ServiceBus to provide Service Bus bindings.

在我的测试下,您需要以下软件包:

And under my test, the follow packages are what you need:

  1. Microsoft.Azure.WebJobs(> = 3.0.10)
  2. Microsoft.Azure.WebJobs.Extensions
  3. Microsoft.Azure.WebJobs.Extensions.ServiceBus
  4. Microsoft.Azure.WebJobs.ServiceBus

使用Microsoft.Azure.WebJobs.Extensions.ServiceBus,您将能够使用b.AddServiceBus()方法和Microsoft.Azure.WebJobs.ServiceBus来创建ServiceBusTrigger函数.

With Microsoft.Azure.WebJobs.Extensions.ServiceBus, you will be able to use b.AddServiceBus() method and with Microsoft.Azure.WebJobs.ServiceBus to create ServiceBusTrigger function.

以下是我的测试代码,请尝试一下.

The below is my test code, have a try.

public static void Main(string[] args)
    {
        var builder = new HostBuilder();
        builder.ConfigureWebJobs(b =>
        {
            b.AddAzureStorageCoreServices();
            b.AddServiceBus();
        });
        builder.ConfigureLogging((context, b) =>
        {
            b.AddConsole();
        });
        var host = builder.Build();
        using (host)
        {
            host.Run();
        }
    }

Function.cs

Function.cs

public static void processservicebus(
    [ServiceBusTrigger("test", Connection = "ServiceBusConnection")]string myQueueItem,
    ILogger log)
    {
        log.LogInformation(myQueueItem);
    }

希望这可以为您提供帮助,如果仍然有其他问题,请随时告诉我.

Hope this could help you, if you still have other problem please feel free to let me know.

这篇关于如何创建服务总线触发webjob?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆