google-cloud pubsub在发送确认后将消息留在队列中

时间:2018-03-05 09:31:36

标签: google-api publish-subscribe google-cloud-pubsub

我有这个订阅者代码:

    try {

        //subscriber
        syncSubscriber.createSubscriber(SdkServiceConfig.s.SUBSCRIPTION_NAME_PARTNER_REQUEST);

        final List<ReceivedMessage> messages = syncSubscriber.fetch(10, true);//get all current messages.
        List<String> ackIds = new ArrayList<>();

        for (ReceivedMessage message : messages) {
            requestToCofmanSender.receiveMessage(message.getMessage());
            ackIds.add(message.getAckId());
        }

        //preferred bulk ack, due to network performance
        syncSubscriber.sendAck(ackIds);


        requestToCofmanSender.getWazePublisher().shutdown();
    }

public void sendAck(Collection<String> ackIdList) {
    if (ackIdList != null && ackIdList.size() != 0) {
        String subscriptionName = SubscriptionName.format(this.getProjectId(), this.subscriptionId);
        AcknowledgeRequest acknowledgeRequest = AcknowledgeRequest.newBuilder().setSubscription(subscriptionName).addAllAckIds(ackIdList).build();
        this.subscriber.acknowledgeCallable().call(acknowledgeRequest);
    }
}

我在循环

中轮询pubsub队列

即使代码发送ack,我仍然会收到相同的消息。

我该怎么办?

1 个答案:

答案 0 :(得分:1)

我的问题是我在接收消息和发送确认之间有一个断点。我的pubsub被配置为10秒超时。