简体   繁体   中英

Sending to Azure Event Hub Error

I'm completely brand new to C#, Microsoft Azure, and basically everything. I'm trying to set up an Azure Event Hub that I can send data to. Right now I'm just following the tutorial that can be found here .

It builds just fine, but I receive the same exception every time. The message is the following: An existing connection was forcibly closed by the remote host. This question has been asked before but never answered.

Just to be sure I'm doing this right I'm attaching pictures with where I obtained the values for the Event Hub Connection String and the Hub Name.

Where I got the Event Hub Connection String from.

从哪里获得事件中心连接字符串。

This one is within the namespace - not the hub itself.

Where I got the Hub Name from. 我从哪里获得了Hub名称。

The code goes as follows:

private const string EventHubConnectionString = "<Connection String>";
private const string EventHubName = "eventhubtest";

Does the Hub Name have to be simply that or a path? Any ideas or help would be greatly appreciated. Thanks.

@Jamie Penzien, I had been stuck with this exact same error for days and my colleague asked me to change the following part and it worked.

var connectionStringBuilder = new EventHubsConnectionStringBuilder(EventHubConnectionString)
{
    EntityPath = EventHubName,
    TransportType = TransportType.AmqpWebSockets                
};

I am still trying to understand the reason, and it may have something to do with the company's firewall settings.

Eventhub name or Entity Path would be simply the name of EventHub found under an EventHub namespace.

You can use below code to create client:

EventHubClient eventHubClient;
var connectionStringBuilder = new EventHubsConnectionStringBuilder(EventHubConnectionString)
{
     EntityPath = EventHubName
};
eventHubClient = EventHubClient.CreateFromConnectionString(connectionStringBuilder.ToString());

EventHubsConnectionStringBuilder can be found under Microsoft.Azure.EventHubs package.

I answered my own questions. First, I needed to change the connection string and make sure it contained the entity path within it. Then when establishing the hub client I did this:

eventHubClient = EventHubClient.CreateFromConnectionString(EventHubConnectionString);

HOWEVER, I was getting this exception specifically because of a firewall issue. I have to open ports (working on it right now) to allow outbound communication to the event hub. I believe these are ports 5671 and 5672.

Thank you to all that answered and @RayX who nailed it on the head.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM