Code never get past call to: eventProcessorHost.Re

2019-09-16 19:28发布

问题:

I am using an Azure Event Hub as backplane for my SignalR Web App (asp.net mvc, 4.5.2).

I have some problems with creating a client that can listen for messages. The loading of the entire application stops at this line when this application start up.

await eventProcessorHost.RegisterEventProcessorAsync<ListenEventProcessor>(options);

my code:

public class TCT
{
    // Singleton instance
    private static readonly Lazy<TCT> Instance = new Lazy<TCT>(() => new TCT(GlobalHost.ConnectionManager.GetHubContext<TCHub>().Clients));

    private TCT()
    {
        InitializeEventHubListnerAsync().GetAwaiter().GetResult();
    }

    private async Task InitializeEventHubListnerAsync()
    {
        ...
        var eventProcessorHostName = Guid.NewGuid().ToString();
        var eventProcessorHost = new EventProcessorHost(eventProcessorHostName, eventHubName, EventHubConsumerGroup.DefaultGroupName, eventHubConnectionString, storageConnectionString);

        var options = new EventProcessorOptions();
        options.ExceptionReceived += (sender, e) =>
        {
            ServiceEventSource.Current.Message("Error occured recieveing message " + e.Exception.Message);
        };

        ServiceEventSource.Current.Message("This is the last entry is see in the log file");
        await eventProcessorHost.RegisterEventProcessorAsync<ListenEventProcessor>(options);
        ServiceEventSource.Current.Message("This line is never printet in the logs and the loading of the entire web application stops here.");
    }
}

If i remove await eventProcessorHost.RegisterEventProcessorAsync(options); the web application loads just fine, but does not recieve any messages of course

I used this guide when writing the code https://docs.microsoft.com/en-gb/azure/event-hubs/event-hubs-dotnet-standard-getstarted-receive-eph

回答1:

As I know Azure Event Hub as backplane is not supported by SignalR currently.

SignalR currently provides three backplanes: Azure Service Bus,Redis,SQL Server.

Following is the snippet from the document.

Azure Service Bus.

Service Bus is a messaging infrastructure that allows components to send messages in a loosely coupled way.

Redis. Redis is an in-memory key-value store. Redis supports a publish/subscribe ("pub/sub") pattern for sending messages.

SQL Server. The SQL Server backplane writes messages to SQL tables. The backplane uses Service Broker for efficient messaging. However, it also works if Service Broker is not enabled

There is an opened issue for supporting Azure EventHub.