GooglePubSub:拉java示例客户端挂起

GooglePubSub:拉java示例客户端挂起,java,google-cloud-messaging,google-cloud-pubsub,Java,Google Cloud Messaging,Google Cloud Pubsub,我正在使用GooglePubSub异步从订阅的主题中提取消息 我正在使用以下示例代码: public void startStreaming() { Subscriber subscriber = null; try { SubscriptionName subscription = SubscriptionName.of("topic-test", "subscription-id-1234"

我正在使用GooglePubSub异步从订阅的主题中提取消息

我正在使用以下示例代码:

   public void startStreaming() {
        Subscriber subscriber = null;
        try {
            SubscriptionName subscription = SubscriptionName.of("topic-test",
                    "subscription-id-1234");
            ExecutorProvider executorProvider =
                    InstantiatingExecutorProvider.newBuilder()
                            .setExecutorThreadCount(1)
                            .build();

            MessageReceiver receiver =
                    new MessageReceiver() {
                        @Override
                        public void receiveMessage(PubsubMessage message, AckReplyConsumer consumer) {
                            try {
                                String msg = message.getData().toStringUtf8();
                                System.out.println(msg);
                            } catch (Exception e) {
                                throw new RuntimeException("Failed to pull messages from topic");
                            }
                            consumer.ack();
                        }
                    };
            subscriber = Subscriber
                    .newBuilder(subscription, receiver)
                    .setExecutorProvider(executorProvider)
                    .build();
            subscriber.addListener(
                    new Subscriber.Listener() {
                        @Override
                        public void failed(Subscriber.State from, Throwable failure) {
                            // Handle failure. This is called when the Subscriber encountered a fatal error and is shutting down.
                            logger.error("Subscriber is not able to hook on google pubsub topic", failure);
                        }
                    },
                    MoreExecutors.directExecutor());
            subscriber.startAsync().awaitRunning();
            // why should I put sleep here??
            Thread.sleep(60000);
        } catch (Exception e) {
        } finally {
            if (subscriber != null) {
                subscriber.stopAsync().awaitTerminated();
            }
        }
    }
它可以正常工作(接收消息)几分钟,并且不再接收消息,我确信会有消息,因为一旦我重新启动拉客户机,它就会正常读取数据

Nov 12, 2017 7:33:17 PM com.google.cloud.pubsub.v1.StreamingSubscriberConnection sendAckOperations
WARNING: failed to send acks
java.lang.IllegalStateException: call was cancelled
    at com.google.common.base.Preconditions.checkState(Preconditions.java:444)
    at io.grpc.internal.ClientCallImpl.sendMessage(ClientCallImpl.java:405)
    at io.grpc.ForwardingClientCall.sendMessage(ForwardingClientCall.java:52)
    at io.grpc.ForwardingClientCall.sendMessage(ForwardingClientCall.java:52)
    at io.grpc.stub.ClientCalls$CallToStreamObserverAdapter.onNext(ClientCalls.java:286)
    at com.google.cloud.pubsub.v1.StreamingSubscriberConnection.sendAckOperations(StreamingSubscriberConnection.java:274)
    at com.google.cloud.pubsub.v1.MessageDispatcher.processOutstandingAckOperations(MessageDispatcher.java:602)
    at com.google.cloud.pubsub.v1.MessageDispatcher.access$2100(MessageDispatcher.java:56)
    at com.google.cloud.pubsub.v1.MessageDispatcher$AckDeadlineAlarm.run(MessageDispatcher.java:529)
    at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
    at java.util.concurrent.FutureTask.run(FutureTask.java:266)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
    at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:745)
当不使用ExecutorProvider ExecutorProvider时,我得到以下日志

2017-11-12 19:08:43 [grpc-default-worker-ELG-2-3] DEBUG io.grpc.netty.NettyClientHandler [id: 0xdc0e7c4d, L:/10.8.17.4:47347 - R:pubsub.googleapis.com/1.1.1.1:111] OUTBOUND WINDOW_UPDATE: streamId=3 windowSizeIncrement=1048576
2017-11-12 19:08:43 [grpc-default-worker-ELG-2-4] DEBUG io.grpc.netty.NettyClientHandler [id: 0x330498ce, L:/10.8.17.4:47346 - R:pubsub.googleapis.com/1.1.1.1:111] OUTBOUND GO_AWAY: lastStreamId=0 errorCode=0 length=0 bytes=
2017-11-12 19:08:43 [grpc-default-worker-ELG-2-3] DEBUG io.grpc.netty.NettyClientHandler [id: 0xdc0e7c4d, L:/10.8.17.4:47347 - R:pubsub.googleapis.com/1.1.1.1:111] OUTBOUND GO_AWAY: lastStreamId=0 errorCode=0 length=0 bytes=
2017-11-12 19:08:44 [threadDeathWatcher-1-1] DEBUG io.netty.buffer.PoolThreadCache Freed 3 thread-local buffer(s) from thread: threadDeathWatcher-1-1
2017-11-12 19:08:44 [threadDeathWatcher-1-1] DEBUG io.netty.buffer.PoolThreadCache Freed 1 thread-local buffer(s) from thread: threadDeathWatcher-1-1
2017-11-12 19:08:44 [grpc-default-worker-ELG-2-3] DEBUG io.netty.buffer.PoolThreadCache Freed 153 thread-local buffer(s) from thread: grpc-default-worker-ELG-2-3
2017-11-12 19:08:44 [grpc-default-worker-ELG-2-4] DEBUG io.netty.buffer.PoolThreadCache Freed 131 thread-local buffer(s) from thread: grpc-default-worker-ELG-2-4

您能帮忙吗?

它现在工作正常,正在移除下面的

lines, 

//            if (subscriber != null) {
//                subscriber.stopAsync().awaitTerminated();
//            }
解释如下,这里是github

这真的很有意义,缺少的是谷歌云文档中的更多文档提供了更多细节,比如github线程中提供的评论

编辑: 创建Github票证是为了添加更多文档,并在下面关闭:

它现在工作正常,是为了移除下面的

lines, 

//            if (subscriber != null) {
//                subscriber.stopAsync().awaitTerminated();
//            }
解释如下,这里是github

这真的很有意义,缺少的是谷歌云文档中的更多文档提供了更多细节,比如github线程中提供的评论

编辑: 创建Github票证是为了添加更多文档,并在下面关闭: