我正在使用spring-integration-ip-4.3.12。
要控制音频设备,我会通过以太网接口向此设备发送一些命令,例如setVolumeValue
/ getVolumeValue
或setMuteState
/ getMuteState
。对于通信,我使用spring-integration-ip
。
我创建了一个tcp客户端(TcpConfig.java),然后通过MessagingGateway
(TcpCommunicationHandler.java)将消息发送到外部Tcp-Server。
该命令以SET的命令0x02
和GET命令的0x04
符号开头,所有符号都以0x03
结尾。响应消息具有相同的结尾唱。为此,我为序列化程序和反序列化程序添加了ByteArraySingleTerminatorSerializer
。
现在,当我通过按下按钮发送一些消息时。之后我收到一条错误信息。见下文。
请你帮我找一下这个例外的原因吗?
TcpConfig.java:
@Bean
public AbstractClientConnectionFactory connectionFactory() {
final String hostName = configuration.getHostName();
final int port = configuration.getPort();
LOGGER.debug("[cx.service.crestron] TcpNetClientConnectionFactory trying to connect to {}:{}", hostName, port);
return new TcpNetClientConnectionFactory(hostName, port);
}
@Bean
@ServiceActivator(inputChannel = "toTcp")
public MessageHandler tcpOutGate(AbstractClientConnectionFactory connectionFactory) throws Exception {
LOGGER.debug("[cx.service.crestron] creating new TcpOutboundGateway as MessageHandler..");
final TcpOutboundGateway gate = new TcpOutboundGateway();
connectionFactory.setSerializer(serializer());
connectionFactory.setDeserializer(serializer());
connectionFactory.setSingleUse(true);
gate.setRequiresReply(true);
gate.setConnectionFactory(connectionFactory);
return gate;
}
@Bean
public ByteArraySingleTerminatorSerializer serializer() {
return new ByteArraySingleTerminatorSerializer((byte) 0x03);
}
TcpCommunicationHandler.java
@MessagingGateway(defaultRequestChannel = "toTcp")
public interface TcpCommunicationHandler extends AutoCloseable, Closeable {
public abstract byte[] executeCommand(final String command);
}
错误日志:
2017-11-17 16:36:29.111 ERROR 1656 --- [JavaFX Application Thread] o.s.i.ip.tcp.TcpOutboundGateway : Tcp Gateway exception
org.springframework.integration.MessageTimeoutException: Timed out waiting for response
at org.springframework.integration.ip.tcp.TcpOutboundGateway.handleRequestMessage(TcpOutboundGateway.java:146)
at org.springframework.integration.handler.AbstractReplyProducingMessageHandler.handleMessageInternal(AbstractReplyProducingMessageHandler.java:109)
at org.springframework.integration.handler.AbstractMessageHandler.handleMessage(AbstractMessageHandler.java:127)
at org.springframework.integration.dispatcher.AbstractDispatcher.tryOptimizedDispatch(AbstractDispatcher.java:116)
at org.springframework.integration.dispatcher.UnicastingDispatcher.doDispatch(UnicastingDispatcher.java:148)
at org.springframework.integration.dispatcher.UnicastingDispatcher.dispatch(UnicastingDispatcher.java:121)
at org.springframework.integration.channel.AbstractSubscribableChannel.doSend(AbstractSubscribableChannel.java:89)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:425)
at org.springframework.integration.channel.AbstractMessageChannel.send(AbstractMessageChannel.java:375)
at org.springframework.messaging.core.GenericMessagingTemplate.doSend(GenericMessagingTemplate.java:115)
at org.springframework.messaging.core.GenericMessagingTemplate.doSendAndReceive(GenericMessagingTemplate.java:150)
at org.springframework.messaging.core.GenericMessagingTemplate.doSendAndReceive(GenericMessagingTemplate.java:45)
at org.springframework.messaging.core.AbstractMessagingTemplate.sendAndReceive(AbstractMessagingTemplate.java:42)
at org.springframework.integration.core.MessagingTemplate.sendAndReceive(MessagingTemplate.java:97)
at org.springframework.integration.core.MessagingTemplate.sendAndReceive(MessagingTemplate.java:38)
at org.springframework.messaging.core.AbstractMessagingTemplate.convertSendAndReceive(AbstractMessagingTemplate.java:79)
at org.springframework.messaging.core.AbstractMessagingTemplate.convertSendAndReceive(AbstractMessagingTemplate.java:70)
at org.springframework.integration.gateway.MessagingGatewaySupport.doSendAndReceive(MessagingGatewaySupport.java:449)
at org.springframework.integration.gateway.MessagingGatewaySupport.sendAndReceive(MessagingGatewaySupport.java:422)
at org.springframework.integration.gateway.GatewayProxyFactoryBean.invokeGatewayMethod(GatewayProxyFactoryBean.java:478)
at org.springframework.integration.gateway.GatewayProxyFactoryBean.doInvoke(GatewayProxyFactoryBean.java:433)
at org.springframework.integration.gateway.GatewayProxyFactoryBean.invoke(GatewayProxyFactoryBean.java:424)
at org.springframework.integration.gateway.GatewayCompletableFutureProxyFactoryBean.invoke(GatewayCompletableFutureProxyFactoryBean.java:65)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:179)
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:213)