【发布时间】:2016-02-26 06:50:32
【问题描述】:
我在这里有一个简单的“Hello World”示例工作流,我想在其中公开一个以纯文本响应的inbound-gateway Web 服务。我认为我将响应发送到 myReplyChannel 的方式不正确。
<int:channel id="myRequestChannel"/>
<int:channel id="myReplyChannel"/>
<int-http:inbound-gateway id="myGateway"
path="/hi"
supported-methods="GET"
request-channel="myRequestChannel"
reply-channel="myReplyChannel"/>
<int:transformer input-channel="myRequestChannel"
output-channel="myReplyChannel"
expression="'Hello World!'"/>
这在部署时有效,但是当我第一次调用该服务时,我看到此记录:
Adding {bridge:null} as a subscriber to the 'myReplyChannel' channel
Channel 'org.springframework.web.context.WebApplicationContext:myReplyChannel' has 1 subscriber(s).
started org.springframework.integration.endpoint.EventDrivenConsumer@4eef7503
看起来 Spring 在最后一分钟添加了myReplyChannel 的订阅者。我宁愿自己做正确的事。
单元测试
我写了一个简单的单元测试来调试这个..
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "classpath:hello.xml" })
public class HelloWorldTest {
@Autowired
private MessageChannel myRequestChannel;
@Test
public void test() {
myRequestChannel.send(MessageBuilder.withPayload("").build());
}
}
这个错误是:
org.springframework.messaging.MessageDeliveryException:
Dispatcher has no subscribers for channel
'org.springframework.context.support.GenericApplicationContext@64485a47.myReplyChannel'.
这对我来说就像我的配置错误,而这里 Spring 没有牵着我的手。
替代配置:
我尝试将myReplyChannel 全部删除,但日志中没有任何内容。
<int:channel id="myRequestChannel"/>
<int-http:inbound-gateway id="myGateway"
path="/ok"
supported-methods="GET"
request-channel="myRequestChannel"/>
<int:transformer input-channel="myRequestChannel" expression="'OK'"/>
这是正确的设置吗?如果有,reply-channel 参数是干什么用的?
使用此配置,我在单元测试中收到以下错误:
org.springframework.messaging.MessagingException:
org.springframework.messaging.core.DestinationResolutionException:
no output-channel or replyChannel header available
【问题讨论】:
标签: java spring spring-integration