使用EventHub的WebJob的任何示例吗? [英] Any Example of WebJob using EventHub?

查看:96
本文介绍了使用EventHub的WebJob的任何示例吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我尝试从WebJobsSDK gitHub中的示例中提出一些建议

var eventHubConfig = new EventHubConfiguration();
string eventHubName = "MyHubName";
eventHubConfig.AddSender(eventHubName,"Endpoint=sb://test.servicebus.windows.net/;SharedAccessKeyName=SendRule;SharedAccessKey=xxxxxxxx");
eventHubConfig.AddReceiver(eventHubName, "Endpoint=sb://test.servicebus.windows.net/;SharedAccessKeyName=ReceiveRule;SharedAccessKey=yyyyyyy");

config.UseEventHub(eventHubConfig);
JobHost host = new JobHost(config);

但是,对于我有限的技能"来说,这恐怕还远远不够!

  • 我找不到具有UseEventHub属性的JobHostConfiguration实例(使用Microsoft.AzureWebJobs软件包的v1.2.0-alpha-10291版本),因此无法将EventHubConfiguration传递给JobHost./p>

  • 我以前使用过EventHub,而不是在WebJob上下文中使用过.如果使用WebJob触发器,我是否仍不需要EventHostProcessor ...还是WebJob触发器本质上充当EventHostProcessor?

无论如何,如果有人拥有像我这样的简单人的更完整的例子,那将是非常美好的!谢谢

解决方案

从文档

I've tried to come up with something from the example in the WebJobsSDK gitHub

var eventHubConfig = new EventHubConfiguration();
string eventHubName = "MyHubName";
eventHubConfig.AddSender(eventHubName,"Endpoint=sb://test.servicebus.windows.net/;SharedAccessKeyName=SendRule;SharedAccessKey=xxxxxxxx");
eventHubConfig.AddReceiver(eventHubName, "Endpoint=sb://test.servicebus.windows.net/;SharedAccessKeyName=ReceiveRule;SharedAccessKey=yyyyyyy");

config.UseEventHub(eventHubConfig);
JobHost host = new JobHost(config);

But I'm afraid that's not far enough for someone of my limited "skillset"!

  • I can find no instance of JobHostConfiguration that has a UseEventHub property (using the v1.2.0-alpha-10291 version of the Microsoft.AzureWebJobs package), so I can't pass the EventHubConfiguration to the JobHost.

  • I've used EventHub before, not within the WebJob context. I don't see if the EventHostProcessor is still required if using the WebJob triggering...or does the WebJob trigger essentially act as the EventHostProcessor?

Anyway, if anyone has a more complete example for a simpleton like me that would be really sweet! Thanks

解决方案

From the documentation here, you should have all the information you need.

What you are missing is a reference of the Microsoft.Azure.WebJobs.ServiceBus.1.2.0-alpha-10291 nuget package.

The UseEventHub is an extension method that is declared in this package.

Otherwise your configuration seems ok. Here is an example on how to receive or send messages from/to an EventHub:

public class BasicTest
{
    public class Payload
    {
        public int Counter { get; set; }
    }
    public static void SendEvents([EventHub("MyHubName")] out Payload x)
    {
        x = new Payload { Counter = 100 };
    }

    public static void Trigger(
        [EventHubTrigger("MyHubName")] Payload x,
        [EventHub("MyHubName")] out Payload y)
    {
        x.Counter++;
        y = x;
    }
}

这篇关于使用EventHub的WebJob的任何示例吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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