猿问

c# 锐利的 proejct .net 4.5 依赖项,应该与 azure 消息队列交互

我目前正在开发一个依赖于 .net 4.5 的项目,这就是我被迫使用 Microsoft.Servicebus 的原因——因此是消息工厂


创建一个 messagefactory 对象似乎不是问题,但创建消息发送者似乎是这里的问题。


我不确定我的 azure 消息队列的实体路径是什么,也不知道应该如何查找?


我这样初始化了我的消息工厂;


public Microsoft.ServiceBus.Messaging.MessagingFactory client = Microsoft.ServiceBus.Messaging.MessagingFactory.CreateFromConnectionString(ServiceBusConnectString);

其中 servicebusconnectionstring 是从 azure 队列中提取的主要连接字符串,或遵循本指南:https : //docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-dotnet-get-started -with-queues#1-create-a-namespace-using-the-azure-portal


消息发送者是这样创建的:


Microsoft.ServiceBus.Messaging.MessageSender sender = client.CreateMessageSender(destinationQueue,queueName);

再一次,destinationQueue 和 queueName 是字符串,它们是从 azure 定义的?


要发送的消息是这样创建的:


Microsoft.ServiceBus.Messaging.BrokeredMessage message = new Microsoft.ServiceBus.Messaging.BrokeredMessage(e.ToXml());

e 只是一个对象,它具有可以将其转换为 xml 字符串的 publich 函数。


这是我发送消息的地方:


try

{

   IntegrationLogger.Write(LogLevel.Verbose, "Sending message to azure");

   sender.Send(message);

}

catch(System.Exception ex)

{

  if(ex is System.TimeoutException)

  {

    IntegrationLogger.Write(LogLevel.Error, "Timeout exeption");

  }


  if (ex is System.ArgumentException)

  {

    IntegrationLogger.Write(LogLevel.Error, "Message is empty");

  }


}

IntegrationLogger是我使用的日志功能 - 记录的最后一条消息是“向 azure 发送消息”,这意味着当我发送消息时会出错。即使 catch 也没有捕获异常?..


这里可能有什么问题?


我是否错误地使用了发件人?


慕少森
浏览 201回答 1
1回答
随时随地看视频慕课网APP
我要回答