douyi1084 2019-01-23 11:29
浏览 158

从服务总线队列中检索消息时出错

I trying to pull messages from azure service bus queue using Go, but I got an error when running the code. Here is my code.

func Example_queue_receive() {
   ctx, cancel :=context.WithTimeout(context.Background(),10*time.Second)
   defer cancel() 
   connectionString :="Endpoint=sb://{my_service_name}.servicebus.windows.net/;SharedAccessKeyName = RootManageSharedAccessKey;SharedAccessKey={my_shared_access_key_value}" 

    // Create a client to communicate with a Service Bus Namespace.
    ns, err := servicebus.NewNamespace(servicebus.NamespaceWithConnectionString(connectionString))
    if err != nil {
        fmt.Println(err)
    }

    // Create a client to communicate with the queue.
    q, err := ns.NewQueue("MyQueueName")
    if err != nil {
       fmt.Println("FATAL: ", err)
    }

    err = q.ReceiveOne(ctx, servicebus.HandlerFunc(func(ctx context.Context, message *servicebus.Message) servicebus.DispositionAction {
         fmt.Println(string(message.Data))
         return message.Complete()
     }))
    if err != nil {
        fmt.Println("FATAL: ", err)
    }

}

This is the error:

link detached, reason: *Error{Condition: amqp:not-found}

  • 写回答

1条回答 默认 最新

  • duancuan7057 2019-01-25 10:19
    关注

    I searched for the error information in the Github repo, and I found the code ErrorNotFound MessageErrorCondition = "amqp:not-found", but there is not any explaination for the error.

    I compared it with Exception types in C# from the offical document Service Bus messaging exceptions and my testing, I think it's the same as below.

    enter image description here

    In my environment go version go1.11.3 windows/amd64, I run the similar code without an existing queue MyQueueName, I got the similar error below.

    FATAL: unhandled error link xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxxx: status code 404 and description: The messaging entity 'sb://.servicebus.windows.net/MyQueueName' could not be found. TrackingId:f9fc309d-xxxx-xxxx-xxxx-8fccd694f266_G42, SystemTracker:.servicebus.windows.MyQueueName, Timestamp:2019-01-25T09:45:28

    So I think the error means your Queue MyQueueName in your code is not existing in your Azure Service Bus, you should create it first before to use.

    Meanwhile, as @JerryLiu said, your code below has some mistakes.

    err = q.ReceiveOne(ctx, servicebus.HandlerFunc(func(ctx context.Context, message *servicebus.Message) servicebus.DispositionAction {
             fmt.Println(string(message.Data))
             return message.Complete()
         }))
    

    According to the godoc for azure-service-bus-go, the parameter type of servicebus.HanderFunc method must be HandlerFunc which is a function return error, not servicebus.DispositionAction in your code.

    enter image description here

    And the method message.Complete should be passed a parameter ctx (a context object) and return error that not match servicebus.DispositionAction. The message.CompleteAction method return servicebus.DispositionAction , but not suitable in the reciving message code. enter image description here

    Please refer to the example of godoc Example (QueueSendAndReceive) to modify your code.

    评论

报告相同问题?

悬赏问题

  • ¥15 怎么把多于硬盘空间放到根目录下
  • ¥15 Matlab问题解答有两个问题
  • ¥50 Oracle Kubernetes服务器集群主节点无法访问,工作节点可以访问
  • ¥15 LCD12864中文显示
  • ¥15 在使用CH341SER.EXE时不小心把所有驱动文件删除了怎么解决
  • ¥15 gsoap生成onvif框架
  • ¥15 有关sql server business intellige安装,包括SSDT、SSMS。
  • ¥15 stm32的can接口不能收发数据
  • ¥15 目标检测算法移植到arm开发板
  • ¥15 利用JD51设计温度报警系统