容器重新启动后,Azure服务总线消息订阅停止工作

时间:2019-07-18 05:10:49

标签: azure docker asp.net-core kubernetes azureservicebus

我正在使用部署在使用asp.net core 2.2构建的Kubernetes上的微服务。每个微服务都订阅了不同的天蓝色服务总线“订阅”。在应用程序启动过程中,该服务为其要侦听的事件添加订阅规则(过滤器)。

一切正常,并处理订阅的消息,除非我杀死Pod,Kubernetes带回副本,然后服务停止处理消息,然后继续堆积在队列中。无论我等待多少,即使我重新启动Pod,它们也不会得到处理。

我的Startup.cs

   public static IServiceCollection RegisterEventBus(this IServiceCollection services, IConfiguration configuration)
    {
        var subscriptionClientName = configuration["SubscriptionClientName"];

        services.AddSingleton<IEventBus, EventBusServiceBus>(sp =>
        {
            var serviceBusPersisterConnection = sp.GetRequiredService<IServiceBusPersisterConnection>();
            var iLifetimeScope = sp.GetRequiredService<ILifetimeScope>();
            var logger = sp.GetRequiredService<ILogger<EventBusServiceBus>>();
            var eventBusSubcriptionsManager = sp.GetRequiredService<IEventBusSubscriptionsManager>();

            return new EventBusServiceBus(serviceBusPersisterConnection, logger,
                eventBusSubcriptionsManager, subscriptionClientName, iLifetimeScope);
        });

        services.AddSingleton<IEventBusSubscriptionsManager, InMemoryEventBusSubscriptionsManager>();
        services.AddTransient<PaymentProcessedIntegrationEventHandler>();
        services.AddTransient<OrderStatusChangedIntegrationEventHandler>();

        return services;
    }

    //Subscribe to Events
    private void ConfigureEventBus(IApplicationBuilder app)
    {
        var eventBus = app.ApplicationServices.GetRequiredService<IEventBus>();
        eventBus.Subscribe<PaymentProcessedIntegrationEvent, PaymentProcessedIntegrationEventHandler>();
        eventBus.Subscribe<OrderStatusChangedIntegrationEvent, OrderStatusChangedIntegrationEventHandler>();

    }

我从github的eshopcontainers复制了官方的Azure Service总线类,并在这里的项目中使用了它。

https://github.com/ImranMA/MicroCouriers/blob/master/src/BuildingBlocks/EventBus/EventBusServiceBus/EventBusServiceBus.cs

我们非常感谢您的帮助!

0 个答案:

没有答案