azure - Azure WebJob 内的 EventHub 注册处理器无法正常工作

标签 azure azure-webjobs azure-eventhub

我正在尝试减轻主服务器的负载。为此,我创建了一个微服务来处理消耗大量资源的打印任务,并尝试使用 Azure 事件中心将两者集成。问题是,我似乎无法让网络作业正常工作。这是网络作业的代码:

public class Functions
{
    [NoAutomaticTrigger]
    public static async Task StartConsumerService()
    {
        Trace.WriteLine("Print - Inside StartConsumerService - Before GetEventProcessor");
        var eventProcessor = API.Integrations.Azure.EventHub.Client.GetEventProcessor(Constants.Azure.EventHub.Hubs.Print);
        Trace.WriteLine("Print - Inside StartConsumerService - Before RegisterEventProcessorAsync");
        await eventProcessor.RegisterEventProcessorAsync<PrintEventProcessor>();
        Trace.WriteLine("Print - Inside StartConsumerService - After RegisterEventProcessorAsync");

        Console.ReadLine();
    }
}

这是Program.cs:

public class Program
{
    public static void Main()
    {
        Trace.WriteLine("Print - Inside Main");
        var config = new JobHostConfiguration();

        if (config.IsDevelopment)
        {
            config.UseDevelopmentSettings();
        }


        Trace.WriteLine("Print - Inside Main - Before JobHost Initialization");
        var host = new JobHost(config);

        Trace.WriteLine("Print - Inside Main - Before Async Call");
        host.CallAsync(typeof(Functions).GetMethod("StartConsumerService"));
        Trace.WriteLine("Print - Inside Main - After Async Call");
        host.RunAndBlock();
        Trace.WriteLine("Print - Inside Main - After Run And Block");
    }
}

WebJob 正在运行并且该函数已被调用。我在 Azure 门户上检查过:

enter image description here

这是我从网络应用程序触发客户端的方式:

var client = EventHubClient.CreateFromConnectionString(cs);

await client.SendAsync(new EventData(Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(message))));
await client.CloseAsync();

尽管如此,它永远不会被 webjob 上运行的事件处理器消耗。此外,我的任何跟踪都没有显示在日志中,无论是来自 SCM 的 webjob 日志,还是来自 Azure WebApp 门户的应用程序日志。

有什么想法吗?现在已经一个多星期了,我无法让它工作......

最佳答案

我过去在网络作业中调用 Console.Readline() 时有过非常糟糕的经历(这是从带有泵和网络作业的常规控制台的基本移动中遗留下来的)

理论上,由于 RunAndBlock(),这个 Console.Readline() 并不是保持作业正常运行所必需的

关于azure - Azure WebJob 内的 EventHub 注册处理器无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51930536/

相关文章:

azure - 主机路径不允许作为卷源,您需要引用 'volumes' 部分中定义的 Azure 文件共享

Azure辅助角色通信

azure - Azure Web 作业中的 Signalr 自托管集线器需要提升吗?

azure-eventhub - eventhub 的消费者数量有限制吗?

具有多个读取器的 Azure 事件中心使用者组

python-2.7 - 如何使用 azure cosmos db 最大化数据库上传速率

c# - 创建文档不起作用 - C# DocumentDB/CosmosDB

Azure WebJobs NuGet 包错误

c# - 跨 Azure 进程锁定多个函数

Azure 事件中心 - "ErrorCode":"Forbidden","ErrorMessage":"SubCode=40300. 已达到或超过 EventHub 类型的资源最大数量