论坛首页 Java企业应用论坛

ActiveMQ5.0实战一: 安装配置ActiveMQ5.0

浏览 20033 次
精华帖 (0) :: 良好帖 (0) :: 新手帖 (0) :: 隐藏帖 (0)
作者 正文
   发表时间:2008-01-04  
/**
*作者:andyao,email:andyaoy@gmail.com
*http://andyao.iteye.com/blog/153171
*/
ActiveMQ5.0实战二: 基本配置
ActiveMQ5.0实战三:使用Spring发送,消费topic和queue消息

简介

  ActiveMQ 是开源的JMS实现,Geronimo应用服务器就是使用的ActiveMQ提供JMS服务。ActiveMQ5.0相比以前版本提供了一些非常有用的新功能:

  1. AMQ Message Store (Faster Persistence!)
  2. Cursors (To handle very large number of stored messages)
  3. Blob Messages
  4. Command Agent
  5. Enterprise Integration Patterns via Camel Integration
  6. Logging a warning if you forget to start a Connection
  7. Message Transformation
  8. Mirrored Queues
  9. Flow Control 

鉴于目前关于ActiveMQ5.0的文章比较少,故准备写一系列ActiveMQ的使用方面的文章。本篇先从安装开始。 

安装

  1. http://activemq.apache.org/download.html 下载5.0.0发行包,解压到需要安装ActiveMQ的文件夹,记为/path/to/activemq。
  2. unix环境activemq文件夹需要执行权限,执行如下命令  chmod -R 755 /path/to/activemq 

启动

  1. window环境运行/path/to/activemq/bin/activemq.bat
  2. unix环境运行/path/to/activemq/bin/activemq

测试

ActiveMQ默认使用的TCP连接端口是61616, 通过查看该端口的信息可以测试ActiveMQ是否成功启动

  1. window环境运行  netstat -an|find "61616"
  2. 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,具体的配置将在后续文章中详细说明。

   发表时间:2008-01-06  
正想了解这个,尽快出下集吧,等不及了
0 请登录后投票
   发表时间:2008-01-07  
这个东东是不是类似IBM的Mq一样的东东
0 请登录后投票
   发表时间:2008-01-07  
引用
这个东东是不是类似IBM的Mq一样的东东

可以这样说,都是实现了JMS规范.
但是IBM MQ收费,当然功能更强大。
ActiveMQ是开源的。
0 请登录后投票
   发表时间:2008-01-08  
andyao 写道
引用
这个东东是不是类似IBM的Mq一样的东东

可以这样说,都是实现了JMS规范.
但是IBM MQ收费,当然功能更强大。
ActiveMQ是开源的。

我喜欢ActiveMQ是开源的,一切好东西都要有开源的,要不然外国大厂商和会IBM mq的人牛的不行。
0 请登录后投票
   发表时间:2008-01-09  
你好啊,我现在正准备在项目中实用activemq,但是发现activemq5.0的XSD文件在springIDE中有错误,使的配置很麻烦!我用的是jvm内嵌式的,还有持久化时不能对自定义类型的对象进行保存,你碰到这些问题了吗?
0 请登录后投票
   发表时间:2008-01-09  
引用
你好啊,我现在正准备在项目中实用activemq,但是发现activemq5.0的XSD文件在springIDE中有错误,使的配置很麻烦!我用的是jvm内嵌式的,还有持久化时不能对自定义类型的对象进行保存,你碰到这些问题了吗?


你能讲清楚一点吗?
目前我们的project使用的就是ActiveMQ5.0, jvm embedder和单独的ActiveMQ5.0的服务器使用都没有问题。

目前使用的ActiveMQ5.0的XSD,没有错误
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:amq="http://activemq.org/config/1.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
 http://activemq.org/config/1.0 http://activemq.apache.org/schema/core/activemq-core-5.0.0.xsd">


引用
还有持久化时不能对自定义类型的对象进行保存

这个问题也没有碰到过,你看是不是你的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");
		}
	}
}
0 请登录后投票
   发表时间:2008-01-10  
我用你的配置和converter成功了:),但是springIDE还是有错误,不能代码提示。
springIDE2.02,spring2.5
配置:
<beans xmlns="http://www.springframework.org/schema/beans"
	xmlns:jms="http://www.springframework.org/schema/jms" xmlns:amq="http://activemq.org/config/1.0"
	xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xsi:schemaLocation="
	http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
	http://www.springframework.org/schema/jms http://www.springframework.org/schema/jms/spring-jms-2.5.xsd
	http://activemq.org/config/1.0 http://activemq.apache.org/schema/core/activemq-core-5.0.0.xsd">


我写的converter没有把pojo序列化到byte[]中就报错:
org.springframework.jms.UncategorizedJmsException: Uncategorized exception occured during JMS processing; nested exception is javax.jms.JMSException: Object is not a primitive: com.model.Item@767851f0


还有:http://activemq.apache.org/schema/core/activemq-core-5.0.0.xsd
这个和activemq5.0-core包里的spring-schemas中定义的并不一样!这样的话我的IDE就不能是实用本地的XSD吧?
  • 描述: 错误页面
  • 大小: 38.2 KB
0 请登录后投票
   发表时间:2008-01-11  
springide2.0.2支持spring2.5吗
我现在用annotation,所以基本不用springide
0 请登录后投票
论坛首页 Java企业应用版

跳转论坛:
Global site tag (gtag.js) - Google Analytics