简体   繁体   English

发送到Azure事件中心错误

[英]Sending to Azure Event Hub Error

I'm completely brand new to C#, Microsoft Azure, and basically everything. 我对C#,Microsoft Azure以及基本上所有东西都是全新的。 I'm trying to set up an Azure Event Hub that I can send data to. 我正在尝试设置一个可以向其发送数据的Azure事件中心。 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名称。 我从哪里获得了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. @Jamie Penzien,我几天坚持这个完全相同的错误,我的同事让我改变了以下部分并且它有效。

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. Eventhub名称或实体路径将只是在EventHub名称空间下找到的EventHub的名称。

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. 可以在Microsoft.Azure.EventHubs包下找到EventHubsConnectionStringBuilder。

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. 我相信这些是5671和5672端口。

Thank you to all that answered and @RayX who nailed it on the head. 感谢所有回答的人和@RayX,他们把它钉在头上。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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