Spring Cloud PubSub 未正确关闭错误
Spring Cloud PubSub as not shutdown properly error
我正在尝试实施 Spring 云 Pub/Sub,我遵循了指南但是如何降低异常,这使得它开始消耗高水平的处理,我研究了一个很多,他们说要放置参数 awaitTerminated,但我找不到如何定义此参数。
版本:
<spring-cloud-gcp.version>2.0.4</spring-cloud-gcp.version>
<spring-cloud.version>2020.0.4</spring-cloud.version>
豆子
@Bean
public DefaultPublisherFactory defaultPublisherFactory(GcpProjectIdProvider gcpProjectIdProvider) {
DefaultPublisherFactory factory = new DefaultPublisherFactory(gcpProjectIdProvider);
factory.setEnableMessageOrdering(true);
factory.setEndpoint("us-east1-pubsub.googleapis.com:443");
return factory;
}
@Bean
@ServiceActivator(inputChannel = "pubSubOutputChannel")
public MessageHandler messageSender(PubSubTemplate pubsubTemplate) {
PubSubMessageHandler adapter = new PubSubMessageHandler(pubsubTemplate, "noMatter");
adapter.setFailureCallback((cause, message) ->
System.err.println("Fail to send message " + message)
);
return adapter;
}
@MessagingGateway(defaultRequestChannel = "pubSubOutputChannel")
public interface PubSubOutboundGateway {
void sendToPubSub(@Header(GcpPubSubHeaders.TOPIC) String topic, String payload);
}
异常
2021-12-22 10:01:08.246 ERROR 60276 --- [LoopGroup-80-34] i.g.i.ManagedChannelOrphanWrapper : *~*~*~ Channel ManagedChannelImpl{logId=869, target=us-east1-pubsub.googleapis.com:443} was not shutdown properly!!! ~*~*~*
Make sure to call shutdown()/shutdownNow() and wait until awaitTermination() returns true.
java.lang.RuntimeException: ManagedChannel allocation site
at io.grpc.internal.ManagedChannelOrphanWrapper$ManagedChannelReference.<init>(ManagedChannelOrphanWrapper.java:93) ~[grpc-core-1.39.0.jar:1.39.0]
at io.grpc.internal.ManagedChannelOrphanWrapper.<init>(ManagedChannelOrphanWrapper.java:53) ~[grpc-core-1.39.0.jar:1.39.0]
at io.grpc.internal.ManagedChannelOrphanWrapper.<init>(ManagedChannelOrphanWrapper.java:44) ~[grpc-core-1.39.0.jar:1.39.0]
at io.grpc.internal.ManagedChannelImplBuilder.build(ManagedChannelImplBuilder.java:634) ~[grpc-core-1.39.0.jar:1.39.0]
at io.grpc.internal.AbstractManagedChannelImplBuilder.build(AbstractManagedChannelImplBuilder.java:264) ~[grpc-core-1.39.0.jar:1.39.0]
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createSingleChannel(InstantiatingGrpcChannelProvider.java:360) ~[gax-grpc-1.66.0.jar:1.66.0]
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.access00(InstantiatingGrpcChannelProvider.java:81) ~[gax-grpc-1.66.0.jar:1.66.0]
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createSingleChannel(InstantiatingGrpcChannelProvider.java:231) ~[gax-grpc-1.66.0.jar:1.66.0]
at com.google.api.gax.grpc.ChannelPool.create(ChannelPool.java:72) ~[gax-grpc-1.66.0.jar:1.66.0]
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createChannel(InstantiatingGrpcChannelProvider.java:241) ~[gax-grpc-1.66.0.jar:1.66.0]
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.getTransportChannel(InstantiatingGrpcChannelProvider.java:219) ~[gax-grpc-1.66.0.jar:1.66.0]
at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:199) ~[gax-1.66.0.jar:1.66.0]
at com.google.cloud.pubsub.v1.stub.GrpcPublisherStub.create(GrpcPublisherStub.java:195) ~[google-cloud-pubsub-1.113.5.jar:1.113.5]
at com.google.cloud.pubsub.v1.Publisher.<init>(Publisher.java:188) ~[google-cloud-pubsub-1.113.5.jar:1.113.5]
at com.google.cloud.pubsub.v1.Publisher.<init>(Publisher.java:88) ~[google-cloud-pubsub-1.113.5.jar:1.113.5]
at com.google.cloud.pubsub.v1.Publisher$Builder.build(Publisher.java:829) ~[google-cloud-pubsub-1.113.5.jar:1.113.5]
我尽可能简单地解决了这个问题,最后我删除了 Bean
DefaultPublisherFactory 并解决了问题。
我正在尝试实施 Spring 云 Pub/Sub,我遵循了指南但是如何降低异常,这使得它开始消耗高水平的处理,我研究了一个很多,他们说要放置参数 awaitTerminated,但我找不到如何定义此参数。
版本:
<spring-cloud-gcp.version>2.0.4</spring-cloud-gcp.version>
<spring-cloud.version>2020.0.4</spring-cloud.version>
豆子
@Bean
public DefaultPublisherFactory defaultPublisherFactory(GcpProjectIdProvider gcpProjectIdProvider) {
DefaultPublisherFactory factory = new DefaultPublisherFactory(gcpProjectIdProvider);
factory.setEnableMessageOrdering(true);
factory.setEndpoint("us-east1-pubsub.googleapis.com:443");
return factory;
}
@Bean
@ServiceActivator(inputChannel = "pubSubOutputChannel")
public MessageHandler messageSender(PubSubTemplate pubsubTemplate) {
PubSubMessageHandler adapter = new PubSubMessageHandler(pubsubTemplate, "noMatter");
adapter.setFailureCallback((cause, message) ->
System.err.println("Fail to send message " + message)
);
return adapter;
}
@MessagingGateway(defaultRequestChannel = "pubSubOutputChannel")
public interface PubSubOutboundGateway {
void sendToPubSub(@Header(GcpPubSubHeaders.TOPIC) String topic, String payload);
}
异常
2021-12-22 10:01:08.246 ERROR 60276 --- [LoopGroup-80-34] i.g.i.ManagedChannelOrphanWrapper : *~*~*~ Channel ManagedChannelImpl{logId=869, target=us-east1-pubsub.googleapis.com:443} was not shutdown properly!!! ~*~*~*
Make sure to call shutdown()/shutdownNow() and wait until awaitTermination() returns true.
java.lang.RuntimeException: ManagedChannel allocation site
at io.grpc.internal.ManagedChannelOrphanWrapper$ManagedChannelReference.<init>(ManagedChannelOrphanWrapper.java:93) ~[grpc-core-1.39.0.jar:1.39.0]
at io.grpc.internal.ManagedChannelOrphanWrapper.<init>(ManagedChannelOrphanWrapper.java:53) ~[grpc-core-1.39.0.jar:1.39.0]
at io.grpc.internal.ManagedChannelOrphanWrapper.<init>(ManagedChannelOrphanWrapper.java:44) ~[grpc-core-1.39.0.jar:1.39.0]
at io.grpc.internal.ManagedChannelImplBuilder.build(ManagedChannelImplBuilder.java:634) ~[grpc-core-1.39.0.jar:1.39.0]
at io.grpc.internal.AbstractManagedChannelImplBuilder.build(AbstractManagedChannelImplBuilder.java:264) ~[grpc-core-1.39.0.jar:1.39.0]
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createSingleChannel(InstantiatingGrpcChannelProvider.java:360) ~[gax-grpc-1.66.0.jar:1.66.0]
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.access00(InstantiatingGrpcChannelProvider.java:81) ~[gax-grpc-1.66.0.jar:1.66.0]
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createSingleChannel(InstantiatingGrpcChannelProvider.java:231) ~[gax-grpc-1.66.0.jar:1.66.0]
at com.google.api.gax.grpc.ChannelPool.create(ChannelPool.java:72) ~[gax-grpc-1.66.0.jar:1.66.0]
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.createChannel(InstantiatingGrpcChannelProvider.java:241) ~[gax-grpc-1.66.0.jar:1.66.0]
at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider.getTransportChannel(InstantiatingGrpcChannelProvider.java:219) ~[gax-grpc-1.66.0.jar:1.66.0]
at com.google.api.gax.rpc.ClientContext.create(ClientContext.java:199) ~[gax-1.66.0.jar:1.66.0]
at com.google.cloud.pubsub.v1.stub.GrpcPublisherStub.create(GrpcPublisherStub.java:195) ~[google-cloud-pubsub-1.113.5.jar:1.113.5]
at com.google.cloud.pubsub.v1.Publisher.<init>(Publisher.java:188) ~[google-cloud-pubsub-1.113.5.jar:1.113.5]
at com.google.cloud.pubsub.v1.Publisher.<init>(Publisher.java:88) ~[google-cloud-pubsub-1.113.5.jar:1.113.5]
at com.google.cloud.pubsub.v1.Publisher$Builder.build(Publisher.java:829) ~[google-cloud-pubsub-1.113.5.jar:1.113.5]
我尽可能简单地解决了这个问题,最后我删除了 Bean DefaultPublisherFactory 并解决了问题。