ActiveMQ 安装(linux)

本文介绍如何在CentOS 5.5环境下安装ActiveMQ 5.5.1版本,并通过内置的Web控制台进行测试。文章还提供了一个简单的Java测试代码示例,用于演示如何使用ActiveMQ进行消息传递。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

ActiveMQ在linux下安装非常简单,步骤如下:

1 环境准备:

    系统环境CentOS5.5 、 JDK版本为OpenJDK1.6.0 设置JAVA_HOME。

    下载 apache-activemq-5.5.1-bin.tar.gz 。 

2 安装步骤

   上传apache-activemq-5.5.1-bin.tar.gz到服务器,解压

   tar -xvf apache-activemq-5.5.1-bin.tar.gz 

3 启动ActiveMQ

  cd apache-activemq-5.5.1

  bin/activemq start/restart

  ps -ef|grep activemq //查看activemq进程

4 测试是否成功安装

  http://192.168.110.223:8161/admin/ MQ自带的web控制台(可以在控制台测试消息的创建和消费)

5 测试代码

 MQConfig 用于初始化连接

package com.yazuo.util;

import javax.jms.Connection;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.Session;

import org.apache.activemq.ActiveMQConnectionFactory;

public class MQConfig {

	// 创建ActiveMQ连接工厂
	private static ActiveMQConnectionFactory conFactory = null;

	// connection
	private static Connection con = null;
	private static Session session = null;
	private static MessageProducer mpCorrect = null;
	private static Destination destCorrect = null;
	private static MessageProducer mpError = null;
	private static Destination destError = null;

	public static ActiveMQConnectionFactory getConFactory() {
		if (conFactory == null) {
			conFactory = new ActiveMQConnectionFactory(WeiboConstants.MQServerURL);
		}
		return conFactory;
	}

	public static Connection getConnection() throws JMSException {
		if (con == null) {
			con = getConFactory().createConnection();
		}
		return con;
	}

	public static Session getSession() throws JMSException {
		if (session == null) {
			session = getConnection().createSession(false, Session.AUTO_ACKNOWLEDGE);
		}
		return session;
	}

	public static Destination getDestCorrect() throws JMSException {
		if (destCorrect == null) {
			destCorrect = getSession().createQueue(WeiboConstants.QueueNameWeibo);
		}
		return destCorrect;
	}

	public static MessageProducer getMPCorrect() throws JMSException {
		if (mpCorrect == null) {
			mpCorrect = getSession().createProducer(getDestCorrect());
		}
		return mpCorrect;
	}

	public static Destination getDestError() throws JMSException {
		if (destError != null) {
			destError = getSession().createQueue(WeiboConstants.QueueNameWeiboError);
		}
		return destError;
	}

	public static MessageProducer getMPError() throws JMSException {
		if (mpError == null) {
			mpError = getSession().createProducer(getDestError());
		}
		return mpError;
	}
}


    

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值