【发布时间】:2019-02-05 15:12:29
【问题描述】:
我正在基于 int-ip:tcp 端点编写客户端-服务器应用程序。用 Kotlin 编写的代码。 应用程序包含两个 tcp 客户端,它们应该以一定的顺序连接到服务器, 一个接一个,当第一个客户端已经建立与服务器的连接并进行了一些初始化时。
作为这种同步的解决方案,我想使用SmartLifecycleRoleController 来启动依赖 tcp 客户端的端点组。
为此,在依赖(第二个)客户端中,我将 role="rcCluster" 和 auto-startup="false" 属性添加到 tcp-outbound-channel-adapter 和 tcp-inbound-channel-adapter
<int-ip:tcp-connection-factory id="rcClientConnectionFactory"
type="client"
host="${tdirelay.host}"
port="${tdirelay.rcPort}"
single-use="false"
so-timeout="10000"
so-keep-alive="false"
serializer="rawSerializerDeserializer"
deserializer="rawSerializerDeserializer"
ssl-context-support="sslContext"/>
<int-ip:tcp-outbound-channel-adapter id="rcOutBoundAdapter"
channel="rcPacketQueueChannel"
phase="5000"
connection-factory="rcClientConnectionFactory"
role="rcCluster"
auto-startup="false"
/>
<int-ip:tcp-inbound-channel-adapter id="rcInboundAdapter"
channel="rcFromServer"
client-mode="true"
retry-interval="5000"
connection-factory="rcClientConnectionFactory"
role="rcCluster"
auto-startup="false"
/>
领先的(第一个)tcp客户端使用拦截器端点按照协议与服务器进行序言交换:
<bean id="dcInterceptorFactoryChain"
class="org.springframework.integration.ip.tcp.connection.TcpConnectionInterceptorFactoryChain">
<property name="interceptors">
<array>
<bean class="com.tcpclient.DirectCannel.DCConnectionInterceptorFactory">
</bean>
</array>
</property>
</bean>
<int-ip:tcp-connection-factory id="dcClientConnectionFactory"
type="client"
host="${tdirelay.host}"
port="${tdirelay.dcPort}"
single-use="false"
so-timeout="10000"
so-keep-alive="false"
interceptor-factory-chain="dcInterceptorFactoryChain"
serializer="rawSerializerDeserializer"
deserializer="rawSerializerDeserializer"
ssl-context-support="sslContext"
/>
我打算在我的 Interceptor 类中调用 SmartLifecycleRoleController 的 startLifecyclesInRole(String role) 和 stopLifecyclesInRole(String role) 方法。
因此,我将 @Autowired private val roleController: SmartLifecycleRoleController 添加到 InterceptorFactory,如 spring-integration/docs 中所述
我的 InterceptorFactory 是:
class DCConnectionInterceptorFactory() : TcpConnectionInterceptorFactory, ApplicationEventPublisherAware {
@Autowired
private val roleController: SmartLifecycleRoleController? = null
@Volatile
private var applicationEventPublisher: ApplicationEventPublisher? = null
override fun setApplicationEventPublisher(applicationEventPublisher: ApplicationEventPublisher) {
this.applicationEventPublisher = applicationEventPublisher
}
override fun getInterceptor(): TcpConnectionInterceptorSupport {
return DCConnectionInterceptor(this.applicationEventPublisher!!, roleController!!)
}
}
IntelliJ IDEA 发出警告: 无法自动接线。未找到“SmartLifecycleRoleController”类型的 bean
并且构建给出错误:
[task-scheduler-2] 错误 org.springframework.integration.ip.tcp.connection.ClientModeConnectionManager - 无法使用 dcClientConnectionFactory,host=localhost,port=9001 建立连接 kotlin.KotlinNullPointerException 在 com.tcpclient.DirectCannel.DCConnectionInterceptorFactory.getInterceptor(DCConnectionInterceptorFactory.kt:25)
我想我需要在xml配置文件中定义SmartLifecycleRoleController类型bean (文档中没有提到:https://docs.spring.io/spring-integration/docs/4.3.4.RELEASE/reference/html/messaging-endpoints-chapter.html#endpoint-roles)。 这个类的构造函数有参数: public SmartLifecycleRoleController(列出角色,列出生命周期) 我不知道如何在 xml 文件中填写我的案例:
如果你知道怎么做,请提供一个在xml配置文件中使用SmartLifecycleRoleController类的bean的实例。
【问题讨论】: