【问题标题】:Service Bus queues with Java not always read events使用 Java 的服务总线队列并不总是读取事件
【发布时间】:2015-10-30 13:53:04
【问题描述】:

我对这个队列有一个奇怪的问题。当我使用它时,即使我在 Microsoft azure 网站上看到队列中有一个事件,它也不总是读取它。例如,4 次我得到消息为空,第 5 次消息是好的。它有效,但并非总是如此。我从这个网站了解到: https://azure.microsoft.com/pl-pl/documentation/articles/service-bus-java-how-to-use-queues/

这是我的代码(几乎与网站上的相同)。我也是用Jackson来序列化的。:

Configuration config =
            ServiceBusConfiguration.configureWithSASAuthentication(
                    engineConfiguration.getServiceBusNamespace(),
                    engineConfiguration.getServiceBusPolicyName(),
                    engineConfiguration.getServiceBusSasKeyValue(),
                    ".servicebus.windows.net"
            );

    ServiceBusContract service = ServiceBusService.create(config);

    try
    {
        ReceiveMessageOptions opts = ReceiveMessageOptions.DEFAULT;
        opts.setReceiveMode(ReceiveMode.PEEK_LOCK);

        ReceiveQueueMessageResult resultQM =
                service.receiveQueueMessage(engineConfiguration.getServiceBusQueueName(), opts);
        Something somethingObject = mapper.readValue(resultQM.getValue().getBody(), Something.class);
        service.deleteMessage(resultQM.getValue());
        return somethingObject;
    }
    catch (ServiceException e) {
        throw new RuntimeException(e);
    }
    catch (Exception e) {
        throw new RuntimeException(e);
    }

【问题讨论】:

    标签: java azure queue message-queue servicebus


    【解决方案1】:

    根据我的经验,这个问题可能是由服务总线队列锁定时间引起的,我们可以在服务总线队列的CONFIGURE选项卡中设置锁定时长,以下截图是详细信息:

    如果您的代码在“deleteMessage()”方法之前抛出了一些异常,队列消息将被锁定(azure 门户中的队列长度将包含此锁定消息),我们可以在锁定持续时间后再次获取此消息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2019-02-23
      • 2017-02-25
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-10-07
      • 2015-07-18
      相关资源
      最近更新 更多