我在Dispatcher has no subscribers
上收到异常outboundChannel
,无法弄清原因。我确信这很简单,我将代码剥离到下面的一个非常简单的示例中:
我的上下文是:
<bean id="requestService"
class="com.sandpit.RequestService" />
<integration:channel id="inboundChannel" />
<integration:service-activator id="service"
input-channel="inboundChannel"
output-channel="outboundChannel"
ref="requestService"
method="handleRequest" />
<integration:channel id="outboundChannel" />
<integration:gateway id="gateway"
service-interface="com.sandpit.Gateway"
default-request-channel="inboundChannel"
default-reply-channel="outboundChannel" />
<bean class="com.sandpit.GatewayTester">
<property name="gateway"
ref="gateway" />
</bean>
我的Java代码是:
public interface Gateway {
String receive();
void send(String message);
}
public class RequestService {
public String handleRequest(String request) {
return "Request received: " + request;
}
}
public class GatewayTester implements ApplicationListener<ContextRefreshedEvent> {
private Gateway gateway;
public void setGateway(Gateway gateway) {
this.gateway = gateway;
}
@Override
public void onApplicationEvent(ContextRefreshedEvent event) {
gateway.send("Hello world!");
System.out.println("FROM SERVICE: " + gateway.receive());
}
}
注意:断点确实告诉我
RequestService
实际上正在处理请求。 最佳答案
没有args的receive()
需要回复 channel 为PollableChannel
。请参见the documentation。
将<queue/>
添加到outboundChannel
。
或者,您可以将网关方法更改为String sendAndReceive(String in)
,所有方法都将按预期工作(甚至可以完全删除outboundChannel
)。
关于spring-integration - Spring集成网关 "Dispatcher has no subscribers",我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/23696630/