0

我正在尝试实现 Spring Cloud 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.access$1800(InstantiatingGrpcChannelProvider.java:81) ~[gax-grpc-1.66.0.jar:1.66.0]
    at com.google.api.gax.grpc.InstantiatingGrpcChannelProvider$1.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]
4

1 回答 1

2

我解决了问题,使其尽可能简单,我最终删除了 Bean DefaultPublisherFactory 并解决了问题。

于 2021-12-22T16:02:54.097 回答