基本的に、私は手前のポートを認識していません。私はポート番号を送信するためにホストにRESTリクエストを行います。私はポート番号を取得していますが、受信ポート番号を使用して接続ファクトリをinBoundClient
に設定できないため、先に進むことはできません。この問題を理解するには、以下のコードをご覧ください。Spring TCP統合の実行時にportとconnectionFactoryを設定する方法
私は以下のように定義されたTCP接続を持っている:
@component
public class ConfigManager {
@Autowired
@Qualifier("clientFactory")
TcpConnectionFactoryFactoryBean connFactory;
@Autowired
@Qualifier("inBoundClient")
SmartLifecycle inboundClient;
@Autowired
@Qualifier("outBoundClient")
SmartLifecycle outBoundClient;
public void initialize(Boolean canStart) {
try {
if (canStart) {
String portResponse = restTemplate.postForObject(SYSTEM_OPEN_SOCK_URI, openSockeEntity,
String.class);
int portNumber = parsePortFromJson(portResponse);
connFactory.setPort(portNumber);
TcpReceivingChannelAdapter receiver = (TcpReceivingChannelAdapter) inboundClient;
receiver.setConnectionFactory(connFactory);
receiver.start();
EventDrivenConsumer sender = (EventDrivenConsumer) outBoundClient;
sender.start();
}
} catch (Exception e) {
logger.error("Error occured while fetching data.");
}
}
}
をしかし、行receiver.setConnectionFactory(connFactory);
で:私のクラスで
<?xml version="1.0" encoding="UTF-8"?>
<context:component-scan base-package="com.tcpclient" />
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-ip="http://www.springframework.org/schema/integration/ip"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/ip http://www.springframework.org/schema/integration/ip/spring-integration-ip.xsd">
<context:annotation-config />
<!--Deserializer for incoming data on the socket -->
<bean
class="org.springframework.integration.ip.tcp.serializer.ByteArraySingleTerminatorSerializer"
id="serializeAndDeserializer">
<constructor-arg type="byte" value="0" />
</bean>
<!-- TCP Client configuration -->
<!-- Channels for communication -->
<int:channel id="tcp-client-input" />
<int:channel id="message" />
<int:channel id="message-serviceActivator" />
<int:gateway id="gateway" service-interface="com.tcpclient.ClientGateway"
default-request-channel="tcp-client-input" default-reply-channel="message" />
<int-ip:tcp-outbound-channel-adapter
id="outBoundClient" channel="tcp-client-input"
retry-interval="60000" auto-startup="false" />
<int-ip:tcp-inbound-channel-adapter
id="inBoundClient" channel="message"
client-mode="true" auto-startup="false" retry-interval="60000" />
<int:object-to-string-transformer
input-channel="message" output-channel="message-serviceActivator" />
<int:service-activator input-channel="message-serviceActivator"
method="onRtlsMessageArrival">
<bean class="com.tcpclient.HandleMessage" />
</int:service-activator>
</beans>
コンフィグマネージャ
を、私は以下しようとしています、 コンパイラエラーが発生しました。 The method setConnectionFactory(AbstractConnectionFactory) in the type TcpReceivingChannelAdapter is not applicable for the arguments (TcpConnectionFactoryFactoryBean)
。 ポートを動的に設定することができますか。
EDIT:
@Autowired
@Qualifier("outboundClient.handler")
TcpSendingMessageHandler outBoundClient;`,
outBoundClient.setConnectionFactory(connFactory);
outBoundClient.setRetryInterval(60000);
outBoundClient.afterPropertiesSet();
outBoundClient.start();
、ゲイリーの提案を1としてしかし、私はこの下のエラーがあります:
Dispatcher has no subscribers for channel 'application.tcp-client-input'.; nested exception is org.springframework.integration.MessageDispatchingException: Dispatcher has no subscribers
私は豆のgateway.send("ACK");
1を試してみてください
outBoundClient
channel="tcp-client-input"
もちろん例外が発生します... 'TcpConnectionFactoryFactoryBean'は明らかに' ConnectionFactory'ではありません。これは、 'ConnectionFactory'を生成する' FactoryBean'です。 –
@ M.Deinum、そう、私はそれに同意する。それは私がやった試行の一つに過ぎませんでした。実際はTcpNetClientConnectionFactoryです。 –