ActiveMQ服务器之间传输对象,项目A发送对象到项目B接收发送对象《一》

上一篇文章写到对象之间传输使用线程方式 ,无法使用监听方式,最近解决了使用监听方式接收对象,本次使用配置文件方式,贴出代码供大家参考

发送端:

public void send(User user) {
// 将user对象进行传递, 0620 ypr
String path = UserController.class.getClassLoader().getResource("/")
.getPath();
System.out.println(path);
ApplicationContext applicationContext = new FileSystemXmlApplicationContext(
path + "applicationContext.xml");
JmsTemplate template = (JmsTemplate) applicationContext
.getBean("jmsTemplate");
Destination destination = (Destination) applicationContext
.getBean("destination"); // 将user中信息 加到 不可变的userNew中,进行传递 0620 ypr
final User userNew = new User();
userNew.setLoginName(user.getLoginName());
userNew.setSign("1"); // 消息发送 将userNew发送 0620 ypr
template.send(destination, new MessageCreator() {
public Message createMessage(javax.jms.Session session)
throws JMSException {
return session.createObjectMessage(userNew);
}
});
System.out.println("成功发送了一条消息");
}

发送端配置文件:

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd"
default-autowire="byName"> <bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616" />
<property name="userName" value="admin" />
<property name="password" value="admin" />
</bean> <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory" />
</bean> <bean id="destination" class="org.apache.activemq.command.ActiveMQTopic">
<!-- 设置消息队列的名字 -->
<constructor-arg index="0" value="STATUS" />
</bean>
</beans>

接收端:

/**
* 监听接收消息 0620 ypr
* @author Administrator
*
*/
public class ConsumerMessageListener implements MessageListener { @Override
public void onMessage(Message message) {
// TODO Auto-generated method stub
System.out.println("ddddddd");
System.out.println("topic收到的消息:" + message);
MessageService messageService = (MessageService)ApplicationContextHandle.getBean("messageService");
try {
//将接收到的对象强制转换为user 对象 0620 ypr
User user = (User) ((ObjectMessage) message).getObject();
String id=user.getId();
List<User> list=messageService.getId(id);
if (message != null){
// for(int i=0;i<list.size();i++){
if(list.size() ==0 && user.getSign().equals("1")){
// User s = (User) message.getObject();
System.out.println("收到的消息对象:" + user.getLoginName());
user.setCreateBy(new User("1"));
user.setUpdateBy(new User("1"));
//使用getbean 方式获取 systemService 0620 ypr //新增 user对象
messageService.xinZeng(user);
}else if(list.size()!=0 && user.getSign().equals("1")){
System.out.println("收到的消息对象:" + user.getLoginName());
messageService.xiuGai(user);
}else if(user.getSign().equals("2")){
System.out.println("收到的消息对象:" + user.getLoginName());
messageService.shanChu(user);
}
}
// } } catch (JMSException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}
}
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:task="http://www.springframework.org/schema/task"
xmlns:util="http://www.springframework.org/schema/util"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:p="http://www.springframework.org/schema/p"
xmlns:jaxrs="http://cxf.apache.org/jaxrs"
xmlns:jaxws="http://cxf.apache.org/jaxws"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/task
http://www.springframework.org/schema/task/spring-task-3.0.xsd
http://www.springframework.org/schema/util
http://www.springframework.org/schema/util/spring-util-2.5.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://cxf.apache.org/jaxrs http://cxf.apache.org/schemas/jaxrs.xsd
http://cxf.apache.org/jaxws http://cxf.apache.org/schemas/jaxws.xsd
http://cxf.apache.org/transports/http/configuration
http://cxf.apache.org/schemas/configuration/http-conf.xsd"> <bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616" />
<property name="userName" value="admin" />
<property name="password" value="admin" />
</bean> <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory" />
</bean> <bean id="mqDestination" class="org.apache.activemq.command.ActiveMQTopic">
<!-- 设置消息队列的名字 -->
<constructor-arg index="0" value="STATUS" />
</bean> <!-- 设置监听路径 0620 ypr -->
<bean id="messageListener" class="com.thinkgem.jeesite.modules.sys.listener.ConsumerMessageListener"></bean> <bean id="listenerContainer" class="org.springframework.jms.listener.SimpleMessageListenerContainer">
<property name="connectionFactory" ref="connectionFactory" />
<property name="destination" ref="mqDestination" />
<property name="messageListener" ref="messageListener" />
</bean>
</beans>

web.xml配置

<!-- Context ConfigLocation  -->
<!-- 扫描applicationContext.xml 0620 ypr -->
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:/spring-context*.xml,classpath*:/applicationContext.xml</param-value>
</context-param>

ActiveMQ服务器之间传输对象,项目A发送对象到项目B接收发送对象《二》的更多相关文章

  1. Linux 两台服务器之间传输文件和文件夹

    今天处理一个项目要迁移的问题,突然发现这么多图片怎么移过去,可能第一时间想到的是先从这台服务器下载下来,然后再上传到另外一台服务器上面去,这个方法确实是可行,但是实在是太费时间了,今天我就教大家怎么快 ...

  2. linux服务器之间传输文件的四种方式

    linux文件传输在内网渗透中至关重要,所以我在此总结一下几种Linux服务器之间传输文件的四种方式 1. scp [优点]简单方便,安全可靠:支持限速参数[缺点]不支持排除目录[用法]scp就是se ...

  3. Linux rsync配置用于服务器之间传输大量的数据

    Linux的rsync 配置,用于服务器之间远程传大量的数据   [教程主题]:rsync [课程录制]: 创E [主要内容] [1] rsync介绍 Rsync(Remote Synchronize ...

  4. Linux 两台服务器之间传输文件

    一.scp命令的使用 1.传输文件(不包括目录) 命令格式:scp 源文件路径目录/需要传输的文件 目标主机的用户名@目标主机IP/主机别名:目标主机存储目录 举个例子:scp /root/ceshi ...

  5. Android:客户端和服务器之间传输数据加密

    Android客户端与服务器进行数据传输时,一般会涉及到两类数据的加密情况,一类是只有创建者才能知道的数据,比如密码:另一类是其他比较重要的,但是可以逆向解密的数据. 第一类:密码类的数据,为了让用户 ...

  6. 利用ssh传输文件-服务器之间传输文件

    利用ssh传输文件   在linux下一般用scp这个命令来通过ssh传输文件. 1.从服务器上下载文件scp username@servername:/path/filename /var/www/ ...

  7. linux下用scp命令在两个服务器之间传输文件,利用php_scp函数进行文件传输

    在linux下利用scp进行文件传输, 从服务器下载文件 scp username@servername:/path/filename /path/filename 上传本地文件到服务器 scp /p ...

  8. 【转载】xShell5 利用 sftp 在本地和服务器之间传输文件

    sftp是Secure File TransferProtocol的缩写,安全文件传送协议.可以为传输文件提供一种安全的加密方法.sftp与 ftp有着几乎一样的语法和功能.SFTP为 SSH的一部分 ...

  9. linux服务器之间传输文件

    转载:https://www.jb51.net/article/82608.htm 1. scp(最近就使用了scp) [优点]简单方便,安全可靠:支持限速参数 [缺点]不支持排除目录[用法]scp就 ...

随机推荐

  1. Java编码问题原因以及解决

    一.文件编码 Unicode 是首选编码.Unicode 是全球范围的字符编码标准. 小结: GBK 与unicode之间的转换是通过gbk unicode映射表. UTF-8 与unicode之间的 ...

  2. NAT和DHCP

    涉及的命令 NAT 动态NAT清除:clear ip nat translation * 进入路由器环回接口:int loo 0 静态NAT清除: (config)#No ip nat inside ...

  3. oracle sqldrl命令与以及ctl文件

    具体操作如下: 第一步:先编辑好数据控制文件 xx.ctl,如test.ctl options(skip=1)   --跳过第一行(看实际情况) load data infile 'C:\Users\ ...

  4. Java九阳真经论述及愿景

    Java九阳真经论述及愿景 “他强由他强,清风拂山冈,他横由他横,明月照大江.” <倚天屠龙记>中张无忌被玄冥二老的玄冥神掌打伤后,体寒难耐,到处求解决之法.一次被韦蝠王打下山谷后,偶遇一 ...

  5. HDU 5572--An Easy Physics Problem(射线和圆的交点)

    An Easy Physics Problem Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 65536/65536 K (Java/ ...

  6. Dubbo 改造普通单体项目

    一.新建普通maven项目 1.首先,新建3个普通maven商城项目,模拟以往常见的Java单体应用开发,mall-interface是存放接口和公共代码部分,order-service-consum ...

  7. Tornado 线程池应用

    Tornado是一个异步框架,在异步操作的时候能提升程序的处理性能.但是如果在程序中碰到同步的逻辑,由于GIL的关系,会直接卡死,导致性能急剧下降. 目前对于mongodb以及redis都有比较不错的 ...

  8. 支付宝支付示例-python

    项目演示: 1.输入金额 ​ 2.扫码支付: ​ 3.支付完成: ​ ​ 具体操作步骤: 第一步:注册账号 https://openhome.alipay.com/platform/appDaily. ...

  9. PHP使用阿里大鱼发送短信验证

    目前,基本上所有的网站注册都要求手机绑定,并通过下发短信验证码方式验证手机的真实性,提高了用户的真实性.但是一般企业单独申请短信行业通道都比较困难,因此选择一家信誉好,稳定性.及时性强的第三方短信通道 ...

  10. Window10 Electron 开发环境搭建及打包exe程序

    1.安装 Electron 首先要安装Node.js     (安装方法:https://www.cnblogs.com/inkwhite/p/9685520.html) 我这里已经安装好了. 2:安 ...