【发布时间】:2014-07-23 16:44:20
【问题描述】:
我制作了分布式应用程序。 1. Web 应用程序和 2. Spring 集成控制台应用程序。
我可以将数据从一个发送到另一个,并使用控制台应用程序进行后台工作,但我想确认接收方向发送方接收到的数据。
发件人应该得到确认。
我的代码:
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代码:
运行应用程序:
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 类中,我正在记录有关用户登录时间和注销时间的数据。
我想从这个类发送确认到我的网络应用程序。 那么有可能吗?如果是,请提供任何指导。
【问题讨论】: