Spring integration 返回TCP适配器与服务器连接工厂/客户端连接工厂的连接状态

Spring integration 返回TCP适配器与服务器连接工厂/客户端连接工厂的连接状态,spring-integration,spring-integration-dsl,Spring Integration,Spring Integration Dsl,我想检查TCP适配器(客户端/服务器连接工厂)的状态,看适配器是否已连接 这个问题是在这个问题的继续,但与其他一些问题 更改方法名称后: 从:isConnected()到isClientModeConnected() 我必须更改我的控制总线Bean定义 之前没有配置输出通道,因此给出错误 @Bean public IntegrationFlow controlBus() { return IntegrationFlowDefinition::controlBus; } 现在, 另外,

我想检查TCP适配器(客户端/服务器连接工厂)的状态,看适配器是否已连接

这个问题是在这个问题的继续,但与其他一些问题

更改方法名称后: 从:
isConnected()
isClientModeConnected()

我必须更改我的控制总线Bean定义 之前没有配置输出通道,因此给出错误

 @Bean
public IntegrationFlow controlBus() {
    return IntegrationFlowDefinition::controlBus;
}
现在,

另外,我的控制总线命令方法是

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;

    } 
使用唯一id注册上述流,假设创建了3个服务器,则将注册上述3个流(在for循环中迭代上述流3次), 那么,如何从注册流中获取
AbstractServerConnectionFactory
的引用,以便获取
openconnectionid

当用户在controlBusflow Bean定义的Service activator中接收到实际状态时,如何配置应用程序以从isConnectionAdapterConnectiond(String connectionName)方法返回AdWater的状态

为此,您需要配置一个
@MessagingGateway
,以发送到控制总线通道并期望得到回复

您现在使用
boolean status=controlChannel.send(newgenericmessage(exp))执行的操作完全错误。
status
MessageChannel.send()操作的结果。没有与目标调用相关的内容

我会这样做:

@MessagingGateway(defaultRequestChannel = "controlBus.input")
public interface ControlBusGateway {

    Object execute(String command);

}

...

@Bean
public IntegrationFlow controlBus() {
     return IntegrationFlowDefinition::controlBus;
}
这样将执行
请求-回复
场景,并将
回复通道
标题填充到发送到控制总线的消息中。然后将执行此
isClientModeConnected()
,结果将返回到网关调用。然后将其转换为
布尔值
,就这样

服务器端与通道适配器根本不相关。只有
AbstractServerConnectionFactory
起作用。见其:

/**
 * Returns a list of (currently) open {@link TcpConnection} connection ids; allows,
 * for example, broadcast operations to all open connections.
 * @return the list of connection ids.
 */
public List<String> getOpenConnectionIds() {
/**
*返回(当前)打开的{@link TcpConnection}连接ID的列表;允许,
*例如,向所有打开的连接广播操作。
*@返回连接ID列表。
*/
公共列表getOpenConnectionId(){

在这个问题上。这正是Gary告诉你的。我认为你可以在方法调用中使用
@ManagedAttribute
将此调用包装为一个简单的服务,让它通过控制总线执行。

我无法解析你的第一个问题;请尝试重新表述它,显示代码和调试日志,以及你的确切意思。对于第二个问题,你可以可以在任何连接工厂上调用
GetOpenConnectionId()
(但不使用控制总线)。请查看我的答案,如果我在某个地方出错,请随时更正。感谢您的回答,我已经实施了上述方法,它可以正常工作。我有多个连接工厂,具有唯一id及其到flowContext的注册表。请查看上述流,我如何引用所需的连接工厂d执行上述所需的操作。可以使用
id()
选项配置
Tcp.netServer(port)
。您可以使用该
id
从应用程序上下文获取特定的bean。使用上述方法,它工作正常,现在我可以使用两个连接工厂检查Tcp适配器的状态(客户端/服务器)。我非常感谢spring Integration提供的良好支持,感谢您的帮助。
@MessagingGateway(defaultRequestChannel = "controlBus.input")
public interface ControlBusGateway {

    Object execute(String command);

}

...

@Bean
public IntegrationFlow controlBus() {
     return IntegrationFlowDefinition::controlBus;
}
/**
 * Returns a list of (currently) open {@link TcpConnection} connection ids; allows,
 * for example, broadcast operations to all open connections.
 * @return the list of connection ids.
 */
public List<String> getOpenConnectionIds() {