javagoogle-cloud-pubsubspring-cloud-gcp

Spring Cloud PubSub as not shutdown properly error


I'm trying to implement Spring Cloud Pub/Sub, I followed the guide but how to take the exception low, this makes it start to consume a high level of processing, I researched a lot and they say to put the parameter awaitTerminated, but I couldn't find how to define this parameter.

Versions:

<spring-cloud-gcp.version>2.0.4</spring-cloud-gcp.version>
<spring-cloud.version>2020.0.4</spring-cloud.version>

Beans

@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);
}

Exception

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]

Solution

  • I solved the problem making it as simple as possible, I ended up deleting the Bean DefaultPublisherFactory and solved the problem.