Я пытаюсь установить связь между двумя приложениями:
В 1-м приложении я делаю что-то вроде этого и работаю без ошибок, он работает или нет, а я нет.
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 интеграции, поэтому я не знаю, как это сделать? Так любая помощь на этом?
Попробуйте что-то вроде следующего. Приложение вашего приемника:
<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
из 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
является точкой входа (шлюзом) в API интеграции Spring. Когда вызывается один метод на этом шлюзе, сообщение помещается на канал и отправляется через адаптер исходящего канала.
У вас нет ничего поглощающего от quakeinfotrigger
- у вас есть два опрошенных входных адаптера и входящие адаптеры UDP, которые все производят сообщения и отправляют их на этот канал, но вам нужно что-то действительно делать с сообщениями.
NoSuchMethodException
..