使用 .Net Framework .4.5.2 向 Azure 服务总线队列发送消息

家庭

我目前正在尝试向 Azure 服务总线队列发送消息,但似乎总是遇到错误。

这是我的例子。

namespace azure_queue
{
    class sendtoAzure
    {    
        public  async Task sendAsync(string message)
        {
            const string ServiceBusConnectString = "<connection-string>";
            const string QueueName = "<QueueName>";
            var AzureClient = Microsoft.ServiceBus.Messaging.QueueClient.CreateFromConnectionString(ServiceBusConnectString, QueueName);
            await AzureClient.SendAsync(new Microsoft.ServiceBus.Messaging.BrokeredMessage(message));
        }
    }
    class Program
    {

        static void Main(string[] args)
        {

            string transferObject_string = "This is a test";
            Microsoft.ServiceBus.Messaging.BrokeredMessage message = new Microsoft.ServiceBus.Messaging.BrokeredMessage(transferObject_string);
            Console.WriteLine("Sending message to azure");
            sendtoAzure client = new sendtoAzure();

            try
            {

                client.sendAsync(transferObject_string).Wait(TimeSpan.FromSeconds(60));
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("Exception: " + ex.StackTrace);
                Console.WriteLine("Message: " + ex.Message);
                Console.WriteLine("HelpLink: " + ex.HelpLink);
                Console.WriteLine("Source: " + ex.Source);
                Console.ReadLine();

                if (ex is System.TimeoutException)
                {
                    Console.WriteLine("Timeout exeption");
                }

                if (ex is System.ArgumentException)
                {
                    Console.WriteLine("Message is empty");
                }

                if (ex is System.UnauthorizedAccessException)
                {
                    Console.WriteLine("Unauthorized access!");
                }

                if (ex is Microsoft.ServiceBus.Messaging.SessionCannotBeLockedException)
                {
                    Console.WriteLine("Attempt to accept a session with a specific session ID, but the session is currently locked by another client.");
                }
            }
        Console.WriteLine("Message Sent!");
            Console.ReadLine();


        }
    }
}

我收到的错误消息是:

Sending message to azure
Exception:    at System.Threading.Tasks.Task.ThrowIfExceptional(Boolean includeTaskCanceledExceptions)
   at System.Threading.Tasks.Task.Wait(Int32 millisecondsTimeout, CancellationToken cancellationToken)
   at System.Threading.Tasks.Task.Wait()
   at azure_queue.Program.Main(String[] args) in C:\Users\keer\Source\Repos\azure_queue\azure_queue\Program.cs:line 39
Message: One or more errors occurred.
HelpLink:
Source: mscorlib

Message Sent!

我也尝试过不使用异步,并且可以正常工作,但是当我检查门户时似乎没有任何内容进入队列。这个错误是由什么引起的?

同样的例子只是 send

例子:

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.ServiceBus;
using System.Configuration;
using System.Messaging;
using System.ServiceModel;
using System.Net;


namespace azure_queue
{
    public class sendtoAzure
    {
        public string ServiceBusConnectString;
        public string QueueName;
        public Microsoft.ServiceBus.Messaging.QueueClient AzureClient;

        public sendtoAzure()
        {
            ServiceBusConnectString = "<connectionstring>";
            QueueName = "<Queue-name>";
            AzureClient = Microsoft.ServiceBus.Messaging.QueueClient.CreateFromConnectionString(ServiceBusConnectString, QueueName);
        }

        public void send (string message)
        { 
            AzureClient.Send(new Microsoft.ServiceBus.Messaging.BrokeredMessage(message));
        }
    }
    class Program
    {

        static void Main(string[] args)
        {

            string transferObject_string = "This is a test";
            Microsoft.ServiceBus.Messaging.BrokeredMessage message = new Microsoft.ServiceBus.Messaging.BrokeredMessage(transferObject_string);
            Console.WriteLine("Sending message to azure");
            sendtoAzure client = new sendtoAzure();
            try
            {
                client.send(transferObject_string);
            }
            catch (System.Exception ex)
            {
                Console.WriteLine("Exception: " + ex.StackTrace);
                Console.WriteLine("Message: " + ex.Message);
                Console.WriteLine("HelpLink: " + ex.HelpLink);
                Console.WriteLine("Source: " + ex.Source);
                Console.WriteLine("InnerExeption: " + ex.InnerException);

                Console.ReadLine();

                if (ex is System.TimeoutException)
                {
                    Console.WriteLine("Timeout exeption");
                }

                if (ex is System.ArgumentException)
                {
                    Console.WriteLine("Message is empty");
                }

                if (ex is System.UnauthorizedAccessException)
                {
                    Console.WriteLine("Unauthorized access!");
                }

                if (ex is Microsoft.ServiceBus.Messaging.SessionCannotBeLockedException)
                {
                    Console.WriteLine("Attempt to accept a session with a specific session ID, but the session is currently locked by another client.");
                }
            }
            Console.WriteLine("Message Sent!");
            Console.ReadLine();

        }
    }
}

给出这个错误 - 包括内部执行:

Sending message to azure
Exception:    at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.RunSynchronously()
   at Microsoft.ServiceBus.Messaging.MessageSender.OnSend(TrackingContext trackingContext, IEnumerable`1 messages, TimeSpan timeout)
   at Microsoft.ServiceBus.Messaging.MessageSender.Send(TrackingContext trackingContext, IEnumerable`1 messages, TimeSpan timeout)
   at Microsoft.ServiceBus.Messaging.MessageSender.Send(BrokeredMessage message)
   at Microsoft.ServiceBus.Messaging.QueueClient.Send(BrokeredMessage message)
   at azure_queue.sendtoAzure.send(String message) in C:\Users\keer\Source\Repos\azure_queue\azure_queue\Program.cs:line 30
   at azure_queue.Program.Main(String[] args) in C:\Users\keer\Source\Repos\azure_queue\azure_queue\Program.cs:line 45
Message: 40400: Endpoint not found., Resource:sb://x-shared.servicebus.windows.net/x%20-%20test. TrackingId:fd30b288-cc6a-4360-9922-0b044e9de8f4_G28, SystemTracker:x-shared.servicebus.windows.net:x%20-%20test, Timestamp:6/28/2018 1:57:25 PM
HelpLink:
Source: Microsoft.ServiceBus
InnerExeption: System.ServiceModel.FaultException: 40400: Endpoint not found., Resource:sb://x-shared.servicebus.windows.net/x%20-%20test. TrackingId:fd30b288-cc6a-4360-9922-0b044e9de8f4_G28, SystemTracker:x-shared.servicebus.windows.net:x%20-%20test, Timestamp:6/28/2018 1:57:25 PM
   at Microsoft.ServiceBus.Messaging.Sbmp.DuplexRequestBindingElement.DuplexRequestSessionChannel.ThrowIfFaultMessage(Message wcfMessage)
   at Microsoft.ServiceBus.Messaging.Sbmp.DuplexRequestBindingElement.DuplexRequestSessionChannel.HandleMessageReceived(IAsyncResult result)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at Microsoft.ServiceBus.Messaging.Sbmp.DuplexRequestBindingElement.DuplexRequestSessionChannel.EndRequest(IAsyncResult result)
   at Microsoft.ServiceBus.Messaging.Channels.ReconnectBindingElement.ReconnectChannelFactory`1.RequestSessionChannel.RequestAsyncResult.<>c.<GetAsyncSteps>b__9_3(RequestAsyncResult thisPtr, IAsyncResult r)
   at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.StepCallback(IAsyncResult result)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at Microsoft.ServiceBus.Common.AsyncResult`1.End(IAsyncResult asyncResult)
   at Microsoft.ServiceBus.Messaging.Channels.ReconnectBindingElement.ReconnectChannelFactory`1.RequestSessionChannel.EndRequest(IAsyncResult result)
   at Microsoft.ServiceBus.Messaging.Sbmp.RedirectBindingElement.RedirectContainerChannelFactory`1.RedirectContainerSessionChannel.RequestAsyncResult.<>c__DisplayClass8_1.<GetAsyncSteps>b__4(RequestAsyncResult thisPtr, IAsyncResult r)
   at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.StepCallback(IAsyncResult result)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at Microsoft.ServiceBus.Common.AsyncResult`1.End(IAsyncResult asyncResult)
   at Microsoft.ServiceBus.Messaging.Sbmp.RedirectBindingElement.RedirectContainerChannelFactory`1.RedirectContainerSessionChannel.EndRequest(IAsyncResult result)
   at Microsoft.ServiceBus.Messaging.Channels.ReconnectBindingElement.ReconnectChannelFactory`1.RequestSessionChannel.RequestAsyncResult.<>c.<GetAsyncSteps>b__9_3(RequestAsyncResult thisPtr, IAsyncResult r)
   at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.StepCallback(IAsyncResult result)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at Microsoft.ServiceBus.Common.AsyncResult`1.End(IAsyncResult asyncResult)
   at Microsoft.ServiceBus.Messaging.Channels.ReconnectBindingElement.ReconnectChannelFactory`1.RequestSessionChannel.EndRequest(IAsyncResult result)
   at Microsoft.ServiceBus.Messaging.Sbmp.SbmpTransactionalAsyncResult`1.<>c.<GetAsyncSteps>b__18_3(TIteratorAsyncResult thisPtr, IAsyncResult a)
   at Microsoft.ServiceBus.Messaging.IteratorAsyncResult`1.StepCallback(IAsyncResult result)
--- End of stack trace from previous location where exception was thrown ---
   at Microsoft.ServiceBus.Common.AsyncResult.End[TAsyncResult](IAsyncResult result)
   at Microsoft.ServiceBus.Messaging.Sbmp.SbmpMessageSender.EndSendCommand(IAsyncResult result)
埃万德罗·保拉

我能够使用您的sendAsync()方法实现成功发送代理消息

此外,当队列不存在(例如 taskqueue1),我能够重现您的问题中所述的相同错误

Message: 40400: Endpoint not found., Resource:sb://{valid service bus namespace}.servicebus.windows.net/taskqueue1. TrackingId:7ce43d17-d339-4ded-b3be-71364a64f685_G17, SystemTracker:{valid service bus namespace}.servicebus.windows.net:taskqueue1, Timestamp:7/1/2018 1:23:04 AM...

由于存在空格(例如 %20),从您发布的异常中提取的端点中的队列名称x%20-%20test似乎无效。

sb://x-shared.servicebus.windows.net/x%20-%20test

因此,请仔细检查 Azure 服务总线队列名称是否正确/有效以及它是否退出。


此外,您使用的 Azure 服务总线 FQDN可能是正确的否则,将抛出以下异常而不是您的问题中描述的异常:

Microsoft.ServiceBus.Messaging.MessagingCommunicationException: The remote name could not be resolved: '{nonexistent service bus namespace}.servicebus.windows.net'...

本文收集自互联网,转载请注明来源。

如有侵权,请联系[email protected] 删除。

编辑于
0

我来说两句

0条评论
登录后参与评论

相关文章

来自分类Dev

使用 REST API 向 .Net Core Core 中的 Azure 服务总线队列发送消息

来自分类Dev

从 web api 向 azure 服务总线队列发送消息

来自分类Dev

如何在 C# 中使用 .NET API 获取 Azure 服务总线的队列大小

来自分类Dev

即使已停止,Azure App Service也会使用服务总线队列消息

来自分类Dev

无法接收从CRM发送到Azure Biztalk服务中的服务总线队列的RemoteExecutionContext消息

来自分类Dev

如何使用 JMS 将预定消息发送到 Azure 服务总线

来自分类Dev

Azure服务总线队列:如何从队列中读取单个消息

来自分类Dev

Azure服务总线队列-使用BrokeredMessage进行序列化

来自分类Dev

Azure服务总线队列,卡住的消息或错误的消息计数?

来自分类Dev

从码头向队列发送消息时出错(使用骆驼)

来自分类Dev

Azure服务总线队列消息在Message.Abandon之后死信

来自分类Dev

Azure服务总线-在OnMessageAsync中读取的消息到队列的末尾

来自分类Dev

Azure服务总线队列,滞留消息或错误计数?

来自分类Dev

Azure:如何从服务总线队列中删除“ DeadLettered”消息

来自分类Dev

使用javascript处理Azure函数中的服务总线错误消息

来自分类Dev

Angular 4 向服务发送消息但返回未定义

来自分类Dev

使用 Azure 服务总线在 2 个组织之间进行通信

来自分类Dev

使用.net Framework 4及更高版本(而不是.NET Core)的微服务

来自分类Dev

如何在Play Framework 2中从外部向演员发送消息?

来自分类Dev

使用Play Framework 2.3.6的Scala:向所有套接字客户端发送消息

来自分类Dev

我如何使用angular 5和asp.net core从angular向端点发送电子邮件

来自分类Dev

我在NET 5中使用Vue js向ID发送控制器,但结果为null

来自分类Dev

Azure服务总线队列OnMessageOptions

来自分类Dev

使用Java从服务器向Facebook帐户发送消息

来自分类Dev

每天发送100多个消息到Azure服务总线

来自分类Dev

使用SignalR从Azure Worker角色向客户端发送消息

来自分类Dev

如何使用 python 中的 amqp 向 Azure 事件中心发送消息

来自分类Dev

Azure服务总线队列-当消息在队列中时,QueueClient.Receive()返回空的BrokeredMessage

来自分类Dev

使用Angular 2设置ASP.NET MVC 4或5项目

Related 相关文章

  1. 1

    使用 REST API 向 .Net Core Core 中的 Azure 服务总线队列发送消息

  2. 2

    从 web api 向 azure 服务总线队列发送消息

  3. 3

    如何在 C# 中使用 .NET API 获取 Azure 服务总线的队列大小

  4. 4

    即使已停止,Azure App Service也会使用服务总线队列消息

  5. 5

    无法接收从CRM发送到Azure Biztalk服务中的服务总线队列的RemoteExecutionContext消息

  6. 6

    如何使用 JMS 将预定消息发送到 Azure 服务总线

  7. 7

    Azure服务总线队列:如何从队列中读取单个消息

  8. 8

    Azure服务总线队列-使用BrokeredMessage进行序列化

  9. 9

    Azure服务总线队列,卡住的消息或错误的消息计数?

  10. 10

    从码头向队列发送消息时出错(使用骆驼)

  11. 11

    Azure服务总线队列消息在Message.Abandon之后死信

  12. 12

    Azure服务总线-在OnMessageAsync中读取的消息到队列的末尾

  13. 13

    Azure服务总线队列,滞留消息或错误计数?

  14. 14

    Azure:如何从服务总线队列中删除“ DeadLettered”消息

  15. 15

    使用javascript处理Azure函数中的服务总线错误消息

  16. 16

    Angular 4 向服务发送消息但返回未定义

  17. 17

    使用 Azure 服务总线在 2 个组织之间进行通信

  18. 18

    使用.net Framework 4及更高版本(而不是.NET Core)的微服务

  19. 19

    如何在Play Framework 2中从外部向演员发送消息?

  20. 20

    使用Play Framework 2.3.6的Scala:向所有套接字客户端发送消息

  21. 21

    我如何使用angular 5和asp.net core从angular向端点发送电子邮件

  22. 22

    我在NET 5中使用Vue js向ID发送控制器,但结果为null

  23. 23

    Azure服务总线队列OnMessageOptions

  24. 24

    使用Java从服务器向Facebook帐户发送消息

  25. 25

    每天发送100多个消息到Azure服务总线

  26. 26

    使用SignalR从Azure Worker角色向客户端发送消息

  27. 27

    如何使用 python 中的 amqp 向 Azure 事件中心发送消息

  28. 28

    Azure服务总线队列-当消息在队列中时,QueueClient.Receive()返回空的BrokeredMessage

  29. 29

    使用Angular 2设置ASP.NET MVC 4或5项目

热门标签

归档