- 浏览: 1578926 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (289)
- java 语法基础 (51)
- spring (8)
- mvc struct /Ant --build.xml (8)
- SOA (0)
- oracle 9i/10g (23)
- sql server 2000-2005 (3)
- 数据库基础知识 (6)
- 设计模式与软件架构 (10)
- Hibernate 持久化 (9)
- J2SE/J2EE/J2ME/AJAX 技术 (8)
- JSF 技术 (3)
- JAVA 图形化 (0)
- JMS (40)
- Eclipse 3.2 IDE 开发技巧 (13)
- 项目处理方法集合 (2)
- html/jsp/javascript (2)
- Unix/Linux (9)
- j2me/ARM/windriver/嵌入式 (4)
- 电信科学 (8)
- jsp (1)
- c/c++ (1)
- LZW压缩算法(java) (2)
- Android (77)
- 版本管理git/svn (2)
最新评论
-
huihai:
有demo吗?
NamingStrategy实现动态表名映射 -
cangbaotu:
推荐给大家一些有用的爬虫源码:https://github.c ...
网络爬虫(源代码参考) -
tuspark:
除了.classpath文件以外,.project文件也应该了 ...
Eclipse .classpath文件浅谈 -
tuspark:
造成eclipse自动关闭的原因有很多,这里有很多介绍:ecl ...
eclipse 自动关闭 解决方案 -
DEMONU:
网上都是这些,这种文章。。。
ActiveMQ中的消息持久性
简介
ActiveMQ 是开源的JMS实现,Geronimo应用服务器就是使用的ActiveMQ提供JMS服务。ActiveMQ5.0相比以前版本提供了一些非常有用的新功能:
- AMQ Message Store (Faster Persistence!)
- Cursors (To handle very large number of stored messages)
- Blob Messages
- Command Agent
- Enterprise Integration Patterns via Camel Integration
- Logging a warning if you forget to start a Connection
- Message Transformation
- Mirrored Queues
- Flow Control
鉴于目前关于ActiveMQ5.0的文章比较少,故准备写一系列ActiveMQ的使用方面的文章。本篇先从安装开始。
安装
- 在http://activemq.apache.org/download.html下载5.0.0发行包,解压到需要安装ActiveMQ的文件夹,记为/path/to/activemq。
- unix环境activemq文件夹需要执行权限,执行如下命令 chmod -R 755 /path/to/activemq
启动
- window环境运行/path/to/activemq/bin/activemq.bat
- unix环境运行/path/to/activemq/bin/activemq
测试
ActiveMQ默认使用的TCP连接端口是61616, 通过查看该端口的信息可以测试ActiveMQ是否成功启动
- window环境运行 netstat -an|find "61616"
- unix环境运行netstat -an|grep 61616
监控
ActiveMQ5.0版本默认启动时,启动了内置的jetty服务器,提供一个demo应用和用于监控ActiveMQ的admin应用。
admin:http://127.0.0.1:8161/admin/
demo:http://127.0.0.1:8161/demo/
点击demo应用中的“ Market data publisher”,就会发一些测试的消息。转到admin页面的topics menu下面(queue和topic的区别见 http://andyao.iteye.com/blog/153173),可以看到消息在增长。
配置
ActiveMQ5.0的配置文件在/path/to/activemq/conf目录下面。主要配置文件为activemq.xml,具体的配置将在后续文章中详细说明。
-------------------------------------------****************************************************************
持久化时不能对自定义类型的对象进行保存,看是不是你的messageConverter有问题?你的消息类型是POJO吗?
MessageConverter如下
- public class DefaultMessageConverter implements MessageConverter {
- /**
- * Logger for this class
- */
- private static final Log log = LogFactory.getLog(DefaultMessageConverter.class);
- public Message toMessage(Object obj, Session session) throws JMSException {
- if (log.isDebugEnabled()) {
- log.debug("toMessage(Object, Session) - start");
- }
- // check Type
- ActiveMQObjectMessage objMsg = (ActiveMQObjectMessage) session.createObjectMessage();
- HashMap<String, byte[]> map = new HashMap<String, byte[]>();
- try {
- // POJO must implements Seralizable
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- ObjectOutputStream oos = new ObjectOutputStream(bos);
- oos.writeObject(obj);
- map.put("POJO", bos.toByteArray());
- objMsg.setObjectProperty("Map", map);
- } catch (IOException e) {
- log.error("toMessage(Object, Session)", e);
- }
- return objMsg;
- }
- public Object fromMessage(Message msg) throws JMSException {
- if (log.isDebugEnabled()) {
- log.debug("fromMessage(Message) - start");
- }
- if (msg instanceof ObjectMessage) {
- HashMap<String, byte[]> map = (HashMap<String, byte[]>) ((ObjectMessage) msg).getObjectProperty("Map");
- try {
- // POJO must implements Seralizable
- ByteArrayInputStream bis = new ByteArrayInputStream(map.get("POJO"));
- ObjectInputStream ois = new ObjectInputStream(bis);
- Object returnObject = ois.readObject();
- return returnObject;
- } catch (IOException e) {
- log.error("fromMessage(Message)", e);
- } catch (ClassNotFoundException e) {
- log.error("fromMessage(Message)", e);
- }
- return null;
- } else {
- throw new JMSException("Msg:[" + msg + "] is not Map");
- }
- }
- }
发表评论
-
基于jms使用ActiveMQ实现异步日志功能.消息持久到oracle 10g 数据库
2008-09-18 15:05 9897package askyaya.entity;import j ... -
activemq 重新连接的机制
2008-09-18 14:39 23174最近一个项目要用到ActiveMq,并且需要最大程度的保证消息 ... -
ActiveMQ stop inactivity read check
2008-09-17 16:01 10519You can do the following to fix ... -
WSAD环境下JMS异步通信全攻略 (3)
2008-09-11 14:18 31783.5 消息驱动的Bean 在前文讨论JMS消息接收处理逻 ... -
WSAD环境下JMS异步通信全攻略 (2)
2008-09-11 13:58 3723三、JMS P2P编程 在JMS P2P通信方式中,发送程 ... -
WSAD环境下JMS异步通信全攻略 (1)
2008-09-11 13:57 4631一、JMS基本概念 1.1 P2P通信 1.2 Pub ... -
topicpublisher (jms)
2008-09-10 18:55 2890目的地类型JNDI名字连接工厂类型Topic/Queuejav ... -
ProducerTool /MessageBroker /getConnectionFactoryF
2008-09-10 18:12 2441lib: jms1.1.jar activemq-all-5. ... -
activemq例子代码 发送BytesMessage消息
2008-09-10 13:55 18326import javax.jms.Connection; im ... -
ActiveMQ in Action(7)
2008-09-10 13:44 3913ActiveMQ in Action(7) 关键字 ... -
ActiveMQ in Action(6)
2008-09-10 13:43 3692ActiveMQ in Action(6) 关键字: acti ... -
ActiveMQ in Action(5)
2008-09-10 13:42 3888ActiveMQ in Action(5) 关键字: acti ... -
ActiveMQ in Action(4)
2008-09-10 13:40 3438ActiveMQ in Action(4) 关键字: acti ... -
ActiveMQ in Action(3)
2008-09-10 13:39 3644ActiveMQ in Action(3) 关键字: acti ... -
ActiveMQ in Action(2)
2008-09-10 13:38 4182ActiveMQ in Action(2) 关键字: acti ... -
ActiveMQ in Action(1)
2008-09-10 13:37 5748ActiveMQ in Action(1) 关键字: acti ... -
为ActiveMQ服务器添加简单验证机制
2008-09-09 23:48 4158为ActiveMQ服务器添加简单验证机制 关键字: Java, ... -
Sender/receiver 消息
2008-09-09 20:28 2089Sender:import java.io.BufferedR ... -
activema.xml 配置
2008-09-09 17:44 3773/***作者:andyao,email:andyaoy@gma ... -
JMX 与系统管理
2008-09-08 10:52 1830Java SE 6 新特性: JMX 与系统管理 ...
相关推荐
最新的activemq版本,刚开始写jms,希望大家都能用到
博文链接:https://cddcdd.iteye.com/blog/170685
该资源是spring与activemq的基础整合,适合消息中间件的初学者
ActiveMQ5.13 安装与配置
linux下activemq安装包和配置文档
ActiveMQ安装及配置文档介绍了ActiveMQ的安装过程和配置。让新手踏入JMS的门槛。
Linux下,图解ActiveMQ 5.12.1 安装与配置
CentOS7安装ActiveMQ
ActiveMQ5.0 的二进制发布包中bin目录中包含一个名为activemq的脚本,直接运行这个脚本就可以启动一个broker。
activemq服务器使用的zookeeper replicable 的方式进行负载均衡以及容灾,客户端使用spring进行配置
NULL 博文链接:https://gong1208.iteye.com/blog/1555582
NULL 博文链接:https://jackyin5918.iteye.com/blog/2003358
用于ACtiveMq 配置插件配置使用,配置介绍等,适合初学者
使用Camel配置ActiveMQ路由的实践方式
activemq 配置的相关文档,助你完善activeMQ的配置
JDK Tomcat ActiveMQ 安装环境配置详细说明
activemq 配置说明与activemq入门讲解
spring activeMQ demo 配置