Spring Integration IP UDP - IN / OUTBOUND错误

时间:2014-05-30 08:19:06

标签: java spring-mvc spring-integration

我正在尝试在两个应用程序之间进行通信:

在第一个应用程序中,我做了类似这样的事情并且没有任何错误地工作,它的工作与否,我不是没有。

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集成的新手,所以我不知道该怎么做? 那么对它有什么帮助吗?

2 个答案:

答案 0 :(得分:1)

尝试以下内容。 你的接收器应用程序:

<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();
    }
}

消息来自入站通道,当收到消息时,将调用来自test的方法echoService。回复将发送到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的入口点(网关)。一旦调用了此网关上的一个方法,就会将消息放入通道并通过出站通道适配器发送。

答案 1 :(得分:0)

你没有消耗quakeinfotrigger - 你有两个轮询的入站适配器和UDP入站适配器都会产生消息并将它们发送到那个频道,但你需要一些东西来实际对消息做些什么。