我正在尝试在两个应用程序之间进行通信:
在第一个应用程序中,我做了一些类似的事情,并且没有错误地工作,它是有效的还是无效的,我没有。
public class Main {
public static void main(String[] args) {
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:/new_tutorial.xml");
applicationContext.registerShutdownHook();
}
}它的XML配置:
<int:inbound-channel-adapter channel="quakeinfotrigger.channel" expression="''">
<int:poller fixed-delay="60000" />
</int:inbound-channel-adapter>
<int:channel id="quakeinfo.channel">
<int:queue capacity="10"/>
</int:channel>
<int:channel id="quakeinfotrigger.channel" />
<int:inbound-channel-adapter channel="quakeinfotrigger.channel" expression="''">
<int:poller fixed-delay="60000" />
</int:inbound-channel-adapter>
<int-ip:udp-outbound-channel-adapter id="metoo" channel="quakeinfotrigger.channel" port="11111" host="localhost"/>
<int:logging-channel-adapter id="messageLogger" log-full-message="true" channel="quakeinfo.channel" level="ERROR">
<int:poller fixed-delay="5000" />
</int:logging-channel-adapter>在第二个应用程序中,我是这样做的:
public class InboundESB {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("/getinbound.xml");
}
}在第二个应用程序的xml代码中:
<int:inbound-channel-adapter channel="quakeinfotrigger.channel" expression="''">
<int:poller fixed-delay="60000" />
</int:inbound-channel-adapter>
<int:channel id="quakeinfotrigger.channel" />
<int:inbound-channel-adapter channel="quakeinfotrigger.channel" expression="''">
<int:poller fixed-delay="60000" />
</int:inbound-channel-adapter>
<int-ip:udp-inbound-channel-adapter id="metoo" port="11111" channel="quakeinfotrigger.channel"/>当我在第一个应用程序之后执行第二个应用程序时,它会给我一个错误:
org.springframework.integration.handler.LoggingHandler handleMessageInternal
SEVERE: org.springframework.integration.MessageDeliveryException: Dispatcher has no subscribers for channel quakeinfotrigger.channel.我想将消息从onr应用程序传递到其他应用程序,但我是spring集成的新手,所以我不知道该怎么做?对此有什么帮助吗?
发布于 2014-05-30 22:01:29
尝试下面这样的方法。你的接收器应用:
<int:channel id="quakeinfotrigger.channel">
<int:queue />
</int:channel>
<int-ip:udp-inbound-channel-adapter id="metoo" port="11111" channel="quakeinfotrigger.channel"/>
<int:service-activator input-channel="quakeinfotrigger.channel"
output-channel="logger"
ref="echoService"
method="test">
<int:poller fixed-rate="1000" />
</int:service-activator>
<bean id="echoService"
class="com.foo.bar.EchoService" />
<int:logging-channel-adapter id="logger" logger-name="com.foo.bar"/>
public class EchoService {
public String test(String input) {
return input + ":echo";
}
}
public class InboundESB {
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("/getinbound.xml");
context.registerShutdownHook();
}
}消息通过入站通道到达,当收到消息时,将调用来自echoService的test方法。回复被发送到logger通道,该通道在控制台上打印它。
您的发件人应用程序:
<int:channel id="quakeinfotrigger.channel" />
<int:gateway id="sender"
service-interface="com.foo.bar.Sender"
default-request-channel="quakeinfotrigger.channel"
/>
<int-ip:udp-outbound-channel-adapter id="metoo" channel="quakeinfotrigger.channel" port="11111" host="localhost"/>
public interface Sender {
public void sendMessage(String message);
}
public class Main {
public static void main(String[] args) {
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:/new_tutorial.xml");
applicationContext.registerShutdownHook();
Sender sender = (Sender) context.getBean("sender");
sender.sendMessage("123");
}
}Sender接口是Spring Integration API的入口点(网关)。一旦此网关上的一个方法被调用,消息就被放到通道上,并通过出站通道适配器发送。
发布于 2014-05-30 21:08:33
您没有从quakeinfotrigger消耗任何东西-您有两个轮询入站适配器和UDP入站适配器,它们都生成消息并将它们发送到该通道,但是您需要一些东西来实际处理这些消息。
https://stackoverflow.com/questions/23950032
复制相似问题