C# Windows服务失败,向事件中心发送消息时出现连接错误
我有一个有趣的问题 我已将windows服务部署到azure虚拟机。此计算机拥有将向azure事件中心发送消息的windows服务 这个问题只发生在这个特定的VM和她的妹妹身上(因为我正在准备水平扩展能力)。我只是设置了它,并在上面安装了服务。同样的服务,当从我的本地机器运行时,工作正常(相同的代码库,相同的构建,相同的配置…字面上是一个复制粘贴作业),我可以从vm访问internet(我通过internet explorer检查) 同样的服务在我退役的较旧的azure vm上运行良好。这个旧的虚拟机不是我安装的,所以我可能在新的虚拟机上遗漏了一些我无法解释的东西 我不确定到底要在这里放什么,但这是我用于发送的相关代码C# Windows服务失败,向事件中心发送消息时出现连接错误,c#,azure,windows-services,azureservicebus,azure-eventhub,C#,Azure,Windows Services,Azureservicebus,Azure Eventhub,我有一个有趣的问题 我已将windows服务部署到azure虚拟机。此计算机拥有将向azure事件中心发送消息的windows服务 这个问题只发生在这个特定的VM和她的妹妹身上(因为我正在准备水平扩展能力)。我只是设置了它,并在上面安装了服务。同样的服务,当从我的本地机器运行时,工作正常(相同的代码库,相同的构建,相同的配置…字面上是一个复制粘贴作业),我可以从vm访问internet(我通过internet explorer检查) 同样的服务在我退役的较旧的azure vm上运行良好。这个旧的
public class MessageSender
{
private static readonly string EventHubName = ConfigurationManager.AppSettings["EventHubName_v2_0"];
private static EventHubClient _client = EventHubClient.CreateFromConnectionString(ConfigurationManager.AppSettings["EventHubConnectionString"], EventHubName);
/// <summary>
/// Send a message to the EventHub if the app configuration has cloud messaging enabled and the event hub connection strings present
/// </summary>
/// <param name="message">The contents of the message being sent.</param>
/// <param name="clientId">The unique id of the client associated with this message.</param>
public static void Send(string message, string clientId)
{
var eventProperties = new Dictionary<string, string>
{
{Constants.LoggingProperties.MO_MESSAGE_CONTENTS, message},
{Constants.LoggingProperties.MO_MESSAGE_DESTINATION, EventHubName},
{Constants.LoggingProperties.CLIENT, clientId}
};
var startTime = DateTime.UtcNow;
var endTime = null as DateTime?;
try
{
var data = new EventData(Encoding.UTF8.GetBytes(message));
_client.Send(data); // <-- fails here
endTime = DateTime.UtcNow;
}
catch (Exception eventHubEx)
{
Log.Instance.TrackException(eventHubEx);
Console.WriteLine(eventHubEx.Message);
...
}
公共类MessageSender
{
私有静态只读字符串EventHubName=ConfigurationManager.AppSettings[“EventHubName_v2_0”];
私有静态EventHubClient _client=EventHubClient.CreateFromConnectionString(ConfigurationManager.AppSettings[“EventHubConnectionString”],EventHubName);
///
///如果应用程序配置已启用云消息且存在事件中心连接字符串,则向事件中心发送消息
///
///正在发送的邮件的内容。
///与此消息关联的客户端的唯一id。
公共静态void发送(字符串消息、字符串clientId)
{
var eventProperties=新字典
{
{Constants.LoggingProperties.MO_MESSAGE_CONTENTS,MESSAGE},
{Constants.LoggingProperties.MO_MESSAGE_DESTINATION,EventHubName},
{Constants.LoggingProperties.CLIENT,clientId}
};
var startTime=DateTime.UtcNow;
var endTime=null作为日期时间?;
尝试
{
var data=neweventdata(Encoding.UTF8.GetBytes(message));
_client.Send(data);//是否存在防火墙?可能存在防火墙问题。azure vnet和子网存在,但它与我们使用的所有其他服务都是同一组(它们仍然与事件中心一起工作)。本地windows vm上也有防火墙。我将尝试禁用它,并查看该帮助我是否禁用了有问题vm上的防火墙,但它仍然不工作。不过,感谢您的建议。
<add key="EventHubConnectionString" value="Endpoint=sb://xxxxx.servicebus.windows.net/;SharedAccessKeyName=xxxx;SharedAccessKey=xxxx" />
<add key="EventHubName_v2_0" value="xxxx" />