Java spring消息头:解析目标名称需要DestinationResolver

Java spring消息头:解析目标名称需要DestinationResolver,java,spring-integration,Java,Spring Integration,我对springTcpOutboundGateway和Message配置有一个问题 我需要通过tcp出站网关发送tcp消息,事实上,我不需要像Bean一样拥有它,我希望在每次需要发送消息时都创建它。我想严格使用网关,因为我也想得到答案: //objects clientConnectionFactory and receiveChannel are created above TcpOutboundGateway tcpOutboundGateway = new TcpOutboundGatew

我对spring
TcpOutboundGateway
Message
配置有一个问题

我需要通过tcp出站网关发送tcp消息,事实上,我不需要像Bean一样拥有它,我希望在每次需要发送消息时都创建它。我想严格使用网关,因为我也想得到答案:

//objects clientConnectionFactory and receiveChannel are created above
TcpOutboundGateway tcpOutboundGateway = new TcpOutboundGateway();
tcpOutboundGateway.setConnectionFactory(clientConnectionFactory);
tcpOutboundGateway.setRequiresReply(true);
tcpOutboundGateway.setReplyChannel(receiveChannel);
tcpOutboundGateway.setRequestTimeout(10000);
tcpOutboundGateway.setSendTimeout(10000);
然后我通过网关发送一条消息:

MessageBuilder<byte[]> mb = MessageBuilder.withPayload(myBytes);
//I need to set this header, otherwise I receive an exception 
//no output-channel or replyChannel header available
mb.setHeader(MessageHeaders.REPLY_CHANNEL, "receiveChannel");
Message<byte[]> message = mb.build();

clientConnectionFactory.start();
tcpOutboundGateway.handleMessage(message);
clientConnectionFactory.stop();
我认为这个消息头有问题,但我不明白是什么。你知道吗,我怎样才能正确地设置它

我想在每次需要发送消息时创建它

这似乎有点过分;对于这样的应用程序,为什么要使用Spring集成位还不是很清楚

如果您解释您的用例,可能有人能够提供更好的解决方案

也就是说

//I need to set this header, otherwise I receive an exception 
//no output-channel or replyChannel header available
mb.setHeader(MessageHeaders.REPLY_CHANNEL, "receiveChannel");
将其设置为
字符串
是需要解析器的原因;它必须是通道或可用的解析程序才能解析为通道

您不必在标题中设置,您可以使用

QueueChannel channel = new QueueChannel();
tcpOutboundGateway.setOutputChannel(channel();
...
Message<?> = channel.receive(TIMEOUT);
QueueChannel=new QueueChannel();
setOutputChannel(通道();
...
消息=通道接收(超时);

如果没有
outputChannel
属性,您只需要
replyChannel
标题。

如何正确设置此标题?如果我写入
mb.setHeader(MessageHeaders.REPLY\u CHANNEL,receiveChannel);
我得到“没有可用的输出频道或replyChannel标题”-异常againI设置了输出通道,它仍然发送“无输出通道或replyChannel标头可用”-如果消息没有标头则异常您一定弄错了;只有当
outputChannel
属性为
null
时才会引发该异常;只有这样,我们才能在
replyChannel
标头中查找通道。
QueueChannel channel = new QueueChannel();
tcpOutboundGateway.setOutputChannel(channel();
...
Message<?> = channel.receive(TIMEOUT);