【问题标题】:Spring Integration IP UDP - IN/OUTBOUND ErrorSpring Integration IP UDP - IN/OUTBOUND 错误
【发布时间】:2014-05-30 08:19:05
【问题描述】:

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

在第一个应用程序中,我做了类似的事情并且没有错误地工作,它是否正常工作,我不知道。

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

【问题讨论】:

    标签: java spring-mvc spring-integration


    【解决方案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();
        }
    }
    

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

    【讨论】:

    • 我为 Sender 编写了与您类似的代码,但显示错误:NoSuchMethodException..
    • 哪个类的哪个方法会抛出这个错误?还有,它说哪个方法不存在?
    【解决方案2】:

    quakeinfotrigger 没有任何消耗 - 您有两个轮询入站适配器和 UDP 入站适配器,它们都产生消息并将它们发送到该通道,但您需要对消息进行实际处理。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多