我制作了分布式应用程序。 1. Web应用程序和2. Spring Integration Console应用程序。
我可以使用控制台应用程序将数据从一个发送到另一个并使用控制台应用程序执行后台工作,但我希望确认数据已接收到发送方的接收方。
发件人应该得到确认。
我的代码:
Web应用程序端(发件人/客户端):
xml:
<bean id="javaSerializer" class="org.springframework.core.serializer.DefaultSerializer"/>
<bean id="javaDeserializer" class="org.springframework.core.serializer.DefaultDeserializer"/>
<int-ip:tcp-connection-factory id="client" type="client" host="localhost" port="56565" single-use="true" so-timeout="10000" deserializer="javaDeserializer" serializer="javaSerializer"/>
<int:channel id="input" />
<int-ip:tcp-outbound-channel-adapter id="outboundClient" channel="input" connection-factory="client"/>
登录时代码:
ClassPathXmlApplicationContext applicationContext = new ClassPathXmlApplicationContext("classpath:/esb/sender/sender-esb.xml");
MessageChannel esbChannel = applicationContext.getBean("input",MessageChannel.class);
Message<String> esbMsg = MessageBuilder.withPayload(form.getPatronID()).build();
esbChannel.send(esbMsg);
Spring-Integration应用程序端(服务器/接收方):
xml:
<bean id="javaSerializer" class="org.springframework.core.serializer.DefaultSerializer"/>
<bean id="javaDeserializer" class="org.springframework.core.serializer.DefaultDeserializer"/>
<int-ip:tcp-connection-factory id="server" type="server" host="localhost" port="56565" single-use="true" so-timeout="10000" deserializer="javaDeserializer" serializer="javaSerializer"/>
<int-ip:tcp-inbound-channel-adapter id="inboundServer" channel="inputChannel" connection-factory="server"/>
<int:channel id="inputChannel"> <int:queue capacity="100" /></int:channel>
<int:channel id="outputChannel"/>
<int:service-activator id="loginChannel" input-channel="inputChannel" ref="ESBReceiver" method="getDataFromGL" output-channel="outputChannel">
<int:poller fixed-rate="500" error-channel="outputChannel" />
</int:service-activator>
<int:logging-channel-adapter id="esbLogger" level="DEBUG"/>
<int:wire-tap channel="esbLogger"></int:wire-tap>
获取请求的java代码:
运行app:
public static void main(String[] args) {
ApplicationContext context = new ClassPathXmlApplicationContext("/receiver/receiver-esb.xml");
}
处理请求的类:
@Component
public class ESBReceiver {
public void getDataFromGL(String msg){
System.out.println("From GL We Get :: " + msg);
System.out.println("Length :: " + msg.length());
}
}
在ESBReceiver类中我正在记录有关用户登录时间和注销时间的数据。
我想将此类的确认信息发送到我的网络应用程序。 那有可能吗?如果是,那么请指导。
答案 0 :(得分:1)
如果您只是想在服务器完成后发送回复;使用tcp网关而不是通道适配器。
如果要发送异步消息,请使用collaborating channel adapters。
答案 1 :(得分:1)
是的,正如@Gary Russell告诉你的那样,你可以使用tcp网关。
示例:
<int-ip:tcp-inbound-gateway id="inGateway"
request-channel="tcpChannel"
reply-channel="replyChannel"
connection-factory="cfServer"
reply-timeout="10000"/>
<int-ip:tcp-outbound-gateway id="outGateway"
request-channel="tcpChannel"
reply-channel="replyChannel"
connection-factory="cfClient"
request-timeout="10000"
remote-timeout="10000"/>