shivam tiwari
shivam tiwari

Reputation: 111

Stopping TCP Adapter with Client ConnectionFactory

I am trying to stop a TCP Adapter with Client Connection Factory using a control bus command i.e @AdapterID.stop() The code for creating the flow is below:

 IntegrationFlow flow = IntegrationFlows.from(Tcp.inboundAdapter(Tcp.nioClient("127.0.0.1",3226))
             .serializer(customSerializer)
             .deserializer(customSerializer)
             .id("abc")).clientMode(true).retryInterval(1000).errorChannel("testChannel"))
             .enrichHeaders(f->f.header("abc","abc"))
             .channel(directChannel())
             .handle(Jms.outboundAdapter(ConnectionFactory())
             .destination(hostConnection.getConnectionNumber()))
             .get();

     theFlow = this.flowContext.registration(flow).id("out.flow").register(); 

When I stop the adapter using control bus as:

 public String stopConnectionAdapter(String connectionName) {
    MessageChannel controlChannel = ac.getBean("controlBus.input", MessageChannel.class); 
    String exp = "@"+connectionName+".stop()";
    controlChannel.send(new GenericMessage<String>(exp));
    return "STOPPED";
}

The Adapter is stopped but the following exception always get printed on the console

2018-06-04 11:09:45.551 ERROR 34860 --- [ask-scheduler-7] o.s.i.i.t.c.ClientModeConnectionManager  : Could not establish connection using conncr3, host=127.0.0.1, port=3226

java.io.IOException: conncr3, host=127.0.0.1, port=3226 connection factory has not been started
at org.springframework.integration.ip.tcp.connection.AbstractConnectionFactory.checkActive(AbstractConnectionFactory.java:873) ~[spring-integration-ip-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.integration.ip.tcp.connection.TcpNioClientConnectionFactory.checkActive(TcpNioClientConnectionFactory.java:68) ~[spring-integration-ip-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory.getConnection(AbstractClientConnectionFactory.java:68) ~[spring-integration-ip-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.integration.ip.tcp.connection.AbstractClientConnectionFactory.getConnection(AbstractClientConnectionFactory.java:33) ~[spring-integration-ip-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.integration.ip.tcp.connection.ClientModeConnectionManager.run(ClientModeConnectionManager.java:55) ~[spring-integration-ip-5.0.5.RELEASE.jar:5.0.5.RELEASE]
at org.springframework.scheduling.support.DelegatingErrorHandlingRunnable.run(DelegatingErrorHandlingRunnable.java:54) [spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511) [na:1.8.0_111]
at java.util.concurrent.FutureTask.runAndReset(FutureTask.java:308) [na:1.8.0_111]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$301(ScheduledThreadPoolExecutor.java:180) [na:1.8.0_111]
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:294) [na:1.8.0_111]
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142) [na:1.8.0_111]
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617) [na:1.8.0_111]
at java.lang.Thread.run(Thread.java:745) [na:1.8.0_111]

How can I stop this error and can close the connection without any exceptions and errors.

Also, What is the efficient way to handle(start and stop at runtime) these connection(Integration flow components) sequentially in expected way without any error?

Upvotes: 2

Views: 543

Answers (2)

Gary Russell
Gary Russell

Reputation: 174494

You shouldn't stop the factory; it's lifecycle is controlled by the adapter; just stop the adapter; there is no need to stop the other components.

You can also stop() the entire IntegrationFlow bean (out.flow) and it will stop the components.

Upvotes: 1

shivam tiwari
shivam tiwari

Reputation: 111

The .clientMode(true) is the culprit here. I am trying to stop the ConnectionFactory provided with id "abc" in flow definition .id("abc")).clientMode(true).retryInterval(1000).errorChannel("testChannel"))

Now, I have added an id to InboundAdapter as below: .id("abc")).clientMode(true).retryInterval(1000).errorChannel("testChannel").id("test"))

And using the control bus first close the connectionFactory then the adapter as @abc.stop() @test.stop() the above error will be resolved.

But I still don't know the appropriate way to stop the IntegrationFlow in efficient way i.e I have to provide a unique ID to each component and stop one by one using Control Bus command.

Upvotes: 1

Related Questions