I want to check the status of the TCP Adapter(Client/Server connection factory) whether the adapter is connected or not.
This Question is posted in continuation with this Question but with some other issue.
After changing the method name :
from: isConnected()
to isClientModeConnected()
I have to change my control Bus Bean definition Earlier no output channel is configured hence its giving error
@Bean
public IntegrationFlow controlBus() {
return IntegrationFlowDefinition::controlBus;
}
Now,
@Bean
public IntegrationFlow controlBusFlow() {
return IntegrationFlows.from(directChannel())
.controlBus().channel(directChannel()).handle(System.out::println)
.get();
}
also, my control Bus command method is now,
public boolean isConnectionAdapterConnected(String connectionName) {
MessageChannel controlChannel = ac.getBean("controlBusFlow.channel#0", MessageChannel.class);
String exp = "@"+connectionName+"adapter"+".isClientModeConnected()";
boolean status = controlChannel.send(new GenericMessage<String>(exp));
return status;
}
- whether its connected or not it always return true in status
isConnectionAdapterConnected(String connectionName)
method. - But my service activator in the controlbusflow Bean definition consist of message with actual correct status it means the above status is not the status of the adapter, actual status is received in service activator defined in controlBusFlow Bean,
I have created an API in which the user calls the function to check status of adapter whether its connected or not.
Issue:
- How can I configure the application to return the status of the adpater from
isConnectionAdapterConnected(String connectionName)
method when the user calls this method as the actual status is received in Service activator of controlBusflow Bean Definition. - Also, How can I check the status of TCP adapter with server connection factory is in connected state or not as this method is only for TCP adapter with client connection factory
EDIT
By using appraoch defined by Mr. Artem Bilan , the first issue is resolved.
But for 2nd issue:
This is the integration flow which is registered at runtime with unique ID.
IntegrationFlow flow =
IntegrationFlows.from(Tcp.inboundAdapter(Tcp.netServer(port)
.serializer(customSerializer)
.deserializer(customSerializer)
.id(connectionName+"server").soTimeout(10000)))
.enrichHeaders(f->f.header("abc","abc")))
.channel(directChannel())
.handle(Jms.outboundAdapter(ConnectionFactory())
.destination("jmsInbound"))
.get();
theFlow =this.flowContext.registration(flow).id(connectionName+".flow").register();
The above flow get registered with unique id , suppose there are 3 server created then the above 3 flows will be registered (iterating the above flow 3 times in for loop) ,
so how can i get reference of AbstractServerConnectionFactory
from registered flow so that I can get openConnectionIds
.
For this purpose you need to configure a
@MessagingGateway
to send to Control Bus channel and expect reply.What you do now with the
boolean status = controlChannel.send(new GenericMessage<String>(exp));
is fully wrong. Thatstatus
is a result ofMessageChannel.send()
operation. There is nothing related to your targetisClientModeConnected()
call.What I would do is like this:
This way the
request-reply
scenario will be performed and areplyChannel
header is going to be populated into the message sent to the Control Bus. Then thisisClientModeConnected()
is going to be executed and the result will be returned to the gateway call. Than you cast it intoBoolean
and that's it!The server side is not related to the Channel Adapter at all. Only the
AbstractServerConnectionFactory
matters. See its:on the matter. That's exactly what Gary said you. I think you can wrap this call to a simple service with the
@ManagedAttribute
on the method call to let it to be performed via Control Bus.