Spring2.5整合ActiveMQ 5.2(P2P文本消息)
项目环境:
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.Session;
/**
* 消息发送者
*
* @author leizhimin 2009-8-13 17:01:48
*/
public class MySender {
public static void main(String[] args) {
ApplicationContext ctx = new ClassPathXmlApplicationContext("/applicationContext.xml");
JmsTemplate template = (JmsTemplate) ctx.getBean("jmsTemplate");
Destination destination = (Destination) ctx.getBean("destination");
template.send(destination, new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
return session.createTextMessage("发送消息:Hello ActiveMQ Text Message!");
}
});
System.out.println("成功发送了一条JMS消息");
}
}
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext;
import org.springframework.jms.core.JmsTemplate;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.TextMessage;
/**
* 消息接收者
*
* @author leizhimin 2009-8-13 17:02:04
*/
public class MyReceiver {
public static void main(String[] args) throws JMSException {
ApplicationContext ctx = new ClassPathXmlApplicationContext("/applicationContext.xml");
JmsTemplate template = (JmsTemplate) ctx.getBean("jmsTemplate");
Destination destination = (Destination) ctx.getBean("destination");
while (true) {
TextMessage txtmsg = (TextMessage) template.receive(destination);
if (null != txtmsg)
System.out.println("收到消息内容为: " + txtmsg.getText());
else
break;
}
}
}
<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">
<!-- 配置JMS连接工厂 -->
<bean id="connectionFactory" class="org.apache.activemq.spring.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616"/>
</bean>
<!-- 配置JMS模版 -->
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="connectionFactory"/>
</bean>
<!-- 发送消息的目的地(一个队列) -->
<bean id="destination" class="org.apache.activemq.command.ActiveMQQueue">
<!-- 设置消息队列的名字 -->
<constructor-arg index="0" value="HelloWorldQueue"/>
</bean>
</beans>
Process finished with exit code 0
收到消息内容为: 发送消息:Hello ActiveMQ Text Message!
收到消息内容为: 发送消息:Hello ActiveMQ Text Message!
1、ActiveMQ检查哪些客户端连接IP地址?
2、干掉queue
3、干掉堆积的一大堆消息
4、napoli从1.4.0升级到1.4.2
(1)依赖修改
- <dependency> <groupId>com.alibaba.shared</groupId>
- <artifactId>alibaba.platform.napoli</artifactId>
- <version>1.4.0</version> </dependency>
- <dependency>
- <groupId>com.alibaba.platform.shared</groupId>
- <artifactId>napoli</artifactId>
- <version>1.4.2</version>
- <type>libd</type>
- </dependency>
- <dependency>
- <groupId>com.alibaba.external</groupId>
- <artifactId>java.j2ee</artifactId>
- <version>1.4</version>
- </dependency>
5、Napoli1.4.2 truck环境调试(2010-11-16)
Spring2.5整合ActiveMQ 5.2(P2P文本消息)相关推荐
- activimq java集成_Java消息队列-Spring整合ActiveMq
1.概述 首先和大家一起回顾一下Java 消息服务,在我之前的博客<Java消息队列-JMS概述>中,我为大家分析了: 消息服务:一个中间件,用于解决两个活多个程序之间的耦合,底层由Jav ...
- Java消息队列-Spring整合ActiveMq
1.概述 首先和大家一起回顾一下Java 消息服务,在我之前的博客<Java消息队列-JMS概述>中,我为大家分析了: 消息服务:一个中间件,用于解决两个或多个程序之间的耦合,底层由Jav ...
- java 消息队列详解_Java消息队列-Spring整合ActiveMq的详解
本篇文章主要介绍了详解Java消息队列-Spring整合ActiveMq ,小编觉得挺不错的,现在分享给大家,也给大家做个参考.一起跟随小编过来看看吧 1.概述 首先和大家一起回顾一下Java 消息服 ...
- 企业级实战02_SpringMVC整合ActiveMQ 实战需求
SpringMVC整合ActiveMQ 文章目录 一.Spring整合ActiveMQ实战 1.1. 创建一个父工程: 1.2. 引入依赖 1.3. 创建一个子项目生产者 1.4. 创建一个sprin ...
- SpringBoot整合activeMQ消息队列手动签收(Session.CLIENT_ACKNOWLEDGE)为什么失效啊?
今天在家隔离办公,不太忙,然后就琢磨起来消息队列activeMQ的消息事务来解决分布式事务,但是奈何在SpringBoot整合activeMQ时,其消费者手动签收消息时出现了问题-->当acti ...
- activeMQ基础学习和SpringBoot整合activeMQ案例
昨天仔细研究了activeMQ消息队列,也遇到了些坑,昨天晚上也写了篇文章记录坑的内容,其实上篇文章(SpringBoot整合activeMQ消息队列手动签收(Session.CLIENT_ACKNO ...
- Spring boot整合Activemq的原理
自动配置 如果未自定义ConnectionFactory Bean,则使用此配置.引入了ActiveMQXAConnectionFactoryConfiguration,ActiveMQConnect ...
- Spring整合ActiveMQ完成消息队列MQ编程
<–start–> 第一步:新建一个maven,将工程命名为activeMQ_spring.在pom.xml文件中导入相关jar包. ①spring开发和测试相关的jar包: spring ...
- Spring2.5整合JPA
在网上找了很多Spring整合JPA的文章,试着去写了很多但没有成功,主要原因可能是jar不正确导致的.花了一些时间自已写了一个小例子,Spring2.5整合JPA(Hibernate实现). 所需要 ...
- 实战07_SSM整合ActiveMQ支持多种类型消息
接上一篇:企业实战06_SSM整合ActiveMQ支持多种类型消息https://blog.csdn.net/weixin_40816738/article/details/100572147 1.S ...
最新文章
- ubuntu中安装hadoop集群
- 详细讲解JAVA中的IO流
- linux 无法找到函数定义,找到定义Linux函数的位置
- a/b测试_如何进行A / B测试?
- Android中打包含有Activity以及资源文件的jar包在工程中调用
- 树莓派与node.js —— onoff、dht
- viturbox网卡驱动_VirtualBox Host
- shell 的AWK
- stagefright
- 幼儿园数学目标_幼儿园数学区目标
- 解决hive表中comment中文乱码问题
- chrome 插件--B站自动发弹幕
- 数据分析【实践】——教育行业指标体系搭建和生命周期维护
- File xxx specified for property 'resourceFile' does not exist.解决方法
- 华中科技大学计算机考博真题,2010年华中科技大学计算机考博试题
- python: 格式化字符串f()用法
- 小程序微信头像授权、手机号授权、地理位置授权
- 小时候真傻,居然盼着长大
- KDE设区--C++的二进制兼容问题
- Word制作倒福实例教程