下载

到ActiveMQ官网,找到下载点。

目前,

官网为http://activemq.apache.org/

Linux版本下载点之一为:http://apache.fayea.com/activemq/5.11.1/apache-activemq-5.11.1-bin.tar.gz

启动

下载到本机,并解压

wget http://apache.fayea.com/activemq/5.11.1/apache-activemq-5.11.1-bin.tar.gz
tar -xf ./apache-activemq-5.11.1-bin.tar.gz
wget http://apache.fayea.com/activemq/5.11.1/apache-activemq-5.11.1-bin.tar.gz
tar -xf ./apache-activemq-5.11.1-bin.tar.gz

启动(当然,由于依赖于JAVA,如果你没有安装JAVA,它会提醒你的,哈哈)

cd ./apache-activemq-5.11.1-bin/bin
./activemq start
cd ./apache-activemq-5.11.1-bin/bin
./activemq start

测试启动成功与否

ActiveMQ默认监听61616端口,查此端口看看是否成功启动

netstat -an|grep 61616
netstat -an|grep 61616

如果一切顺利,会看到如下日志

[nicchagil@localhost bin]$ ./activemq start
INFO: Loading '/home/nicchagil/app/apache-activemq-5.11.1/bin/env'
INFO: Using java '/home/nicchagil/app/jdk1.7.0_71//bin/java'
INFO: Starting - inspect logfiles specified in logging.properties and log4j.prop erties to get details
INFO: pidfile created : '/home/nicchagil/app/apache-activemq-5.11.1/data/activem q.pid' (pid '4858')
[nicchagil@localhost bin]$
[nicchagil@localhost bin]$
[nicchagil@localhost bin]$
[nicchagil@localhost bin]$ netstat -an | grep 61616
tcp 0 0 :::61616 :::* LIST EN
[nicchagil@localhost bin]$
[nicchagil@localhost bin]$ ./activemq start
INFO: Loading '/home/nicchagil/app/apache-activemq-5.11.1/bin/env'
INFO: Using java '/home/nicchagil/app/jdk1.7.0_71//bin/java'
INFO: Starting - inspect logfiles specified in logging.properties and log4j.prop erties to get details
INFO: pidfile created : '/home/nicchagil/app/apache-activemq-5.11.1/data/activem q.pid' (pid '4858')
[nicchagil@localhost bin]$
[nicchagil@localhost bin]$
[nicchagil@localhost bin]$
[nicchagil@localhost bin]$ netstat -an | grep 61616
tcp 0 0 :::61616 :::* LIST EN
[nicchagil@localhost bin]$

顺便,登录下管理员页面,看看有木有问题:

URL : http://10.0.0.109:8161/admin/

ACC/PWD : admin/admin

尝试基本消息功能

接下来,用简单的点对点测试消息发送、消息接收。

引入包:

  • activemq-client-5.11.1.jar
  • geronimo-j2ee-management_1.1_spec-1.0.1.jar
  • geronimo-jms_1.1_spec-1.1.1.jar
  • hawtbuf-1.11.jar
  • slf4j-api-1.7.10.jar

消息发送

package com.nicchagil.activemq.study.No001点对点;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.ObjectMessage;
import javax.jms.Session; import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory; public class Sender { public static void main(String[] args) throws JMSException {
ConnectionFactory factory = new ActiveMQConnectionFactory(ActiveMQConnection.DEFAULT_USER, ActiveMQConnection.DEFAULT_PASSWORD, "tcp://10.0.0.109:61616");
Connection connection = factory.createConnection();
connection.start();
Session session = connection.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue("TestQueue");
MessageProducer producer = session.createProducer(destination);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
ObjectMessage message = session.createObjectMessage("hello world...");
producer.send(message);
session.commit();
System.out.println("sent...");
} }
package com.nicchagil.activemq.study.No001点对点;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.DeliveryMode;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageProducer;
import javax.jms.ObjectMessage;
import javax.jms.Session; import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory; public class Sender { public static void main(String[] args) throws JMSException {
ConnectionFactory factory = new ActiveMQConnectionFactory(ActiveMQConnection.DEFAULT_USER, ActiveMQConnection.DEFAULT_PASSWORD, "tcp://10.0.0.109:61616");
Connection connection = factory.createConnection();
connection.start();
Session session = connection.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue("TestQueue");
MessageProducer producer = session.createProducer(destination);
producer.setDeliveryMode(DeliveryMode.NON_PERSISTENT);
ObjectMessage message = session.createObjectMessage("hello world...");
producer.send(message);
session.commit();
System.out.println("sent...");
} }

消息接收

package com.nicchagil.activemq.study.No001点对点;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.ObjectMessage;
import javax.jms.Session; import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory; public class Receiver { public static void main(String[] args) throws JMSException {
ConnectionFactory factory = new ActiveMQConnectionFactory(ActiveMQConnection.DEFAULT_USER, ActiveMQConnection.DEFAULT_PASSWORD,
"tcp://10.0.0.109:61616");
Connection connection = factory.createConnection();
connection.start();
Session session = connection.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue("TestQueue"); MessageConsumer consumer = session.createConsumer(destination);
ObjectMessage message = (ObjectMessage)consumer.receive();
if (message != null) {
String messageString = (String)message.getObject();
System.out.println("Receive : " + messageString);
}
} }
package com.nicchagil.activemq.study.No001点对点;

import javax.jms.Connection;
import javax.jms.ConnectionFactory;
import javax.jms.Destination;
import javax.jms.JMSException;
import javax.jms.MessageConsumer;
import javax.jms.ObjectMessage;
import javax.jms.Session; import org.apache.activemq.ActiveMQConnection;
import org.apache.activemq.ActiveMQConnectionFactory; public class Receiver { public static void main(String[] args) throws JMSException {
ConnectionFactory factory = new ActiveMQConnectionFactory(ActiveMQConnection.DEFAULT_USER, ActiveMQConnection.DEFAULT_PASSWORD,
"tcp://10.0.0.109:61616");
Connection connection = factory.createConnection();
connection.start();
Session session = connection.createSession(Boolean.TRUE, Session.AUTO_ACKNOWLEDGE);
Destination destination = session.createQueue("TestQueue"); MessageConsumer consumer = session.createConsumer(destination);
ObjectMessage message = (ObjectMessage)consumer.receive();
if (message != null) {
String messageString = (String)message.getObject();
System.out.println("Receive : " + messageString);
}
} }

看到console打印出:Receive : hello world...,可知接收到消息了,内流满面啊啊啊啊。。。

关闭

查询进程id(pid),禁止其进程:

ps -ef | grep activemq
kill -9 pid
ps -ef | grep activemq
kill -9 pid

再运行Sender,她就无法连接了,哈哈哈哈哈

Exception in thread "main" javax.jms.JMSException: Could not connect to broker URL: tcp://10.0.0.109:61616. Reason: java.net.ConnectException: Connection refused: connect
Exception in thread "main" javax.jms.JMSException: Could not connect to broker URL: tcp://10.0.0.109:61616. Reason: java.net.ConnectException: Connection refused: connect

好了,基本的搭建告一段落。

荆棘

过程中,遇到一个小问题,就是我一开始是用JDK1.6去跑的,报出常见的Unsupported major.minor version 51.0

针对这个问题,这个帖子有很好的参考意义:

http://www.cnblogs.com/chinafine/articles/1935748.html

找出jar中的一个class,执行以下命令,可查出minor version、major version:

javap -verbose yourClassName
javap -verbose yourClassName

或直接查看jar中的META-INF\MANIFEST.MF。

然后对照帖子中的JDK版本,换成JDK1.7就OK了。

ActiveMQ搭建的更多相关文章

  1. activemq 搭建--集群

      linux activmemq 集群安装,配置和高可用测试       从 ActiveMQ 5.9 开始,ActiveMQ 的集群实现方式取消了传统的Master-Slave 方式,增加了基于Z ...

  2. ActiveMQ: 搭建Broker集群(cluster)

    上一篇介绍了基于Networks of Borkers的2节点HA方案,这一篇继续来折腾Networks of Brokers,当应用规模日渐增长时,2节点的broker可能仍然抗不住访问压力,这时候 ...

  3. 基于JMS的ActiveMQ搭建与实现

    1.JMS Java消息服务(Java Message Service)即JMS,是一个Java平台中关于面向消息中间件的API,用于两个程序之间,或分布式系统中发送消息,进行异步通信. JMS包括队 ...

  4. ActiveMQ消息队列集群的搭建

    1.准备activemq apache-activemq-5.12.0-bin.tar 2.解压文件 3.并将文件cp一份命名为activemq1 进入conf文件进行修改 修改属性为brokerNa ...

  5. ActiveMQ学习系列(二)----生产者客户端(java)

    上文主要简单地将activeMq搭建了起来,并且可以用web console去登录查看相关的后台功能. 本文将学习如何用java语言实现一个生产者客户端,主要参考了以下链接: http://activ ...

  6. Centos7_64环境搭建

    smb搭建参考 https://www.cnblogs.com/areyouready/p/10369917.html activeMq搭建参考 https://blog.csdn.net/u0122 ...

  7. Spring学习总结(13)——Spring+Log4j+ActiveMQ实现远程记录日志

    应用场景 随着项目的逐渐扩大,日志的增加也变得更快.Log4j是常用的日志记录工具,在有些时候,我们可能需要将Log4j的日志发送到专门用于记录日志的远程服务器,特别是对于稍微大一点的应用.这么做的优 ...

  8. 消息队列(三)Apache ActiveMQ

    在Ubuntu上安装ActiveMQ 系统初始化 $ sudo apt update $ sudo apt dist-upgrade $ sudo apt autoremove $ sudo apt ...

  9. springboot整合kafka应用

    1.kafka在消息传递的使用非常普遍,相对于activemq来说kafka的分布式管理和使用更加灵活. 2.activemq的搭建和使用可以参考: activemq搭建和springmvc的整合:h ...

随机推荐

  1. 19-spring学习-springMVC环境配置

    新建一共环境,添加spring支持,就可以开发springMVC了. 既然是springMVC,就必须为其定义相关配置. 1,springMVC所有配置都需要在applicationContext.x ...

  2. linux内核——PAE(物理地址扩展)

    引入PAE机制后,分页模式是怎样的呢? 首先,要搞明白几件事,2.6.11以上版本的linux内核中,存在4中页表(页全局目录,页上级目录,页中级目录,页表),这些页表结构是已经存在于硬盘中的,当进程 ...

  3. 理解HTTP/304响应

    理解HTTP/304响应 原文:http://www.telerik.com/automated-testing-tools/blog/eric-lawrence/12-11-06/understan ...

  4. myeclipse2014安装jad反编译插件

    myeclipse上默认不能查看class文件,需要查看的话安装反编译插件 安装步骤: 准备图中框里的两个文件 1. [net.sf.jadclipse_3.3.0.jar]文件拷贝到如下路径([D: ...

  5. brew install memcache get Error: Formulae found in multiple taps

    本篇文章由:http://xinpure.com/brew-install-memcache-get-error-formulae-found-in-multiple-taps/ 安装环境: Mac ...

  6. 温故而知新 js 点击空白处关闭气泡

    诀窍1:使用el.contains(e) 来判断点击的区域诀窍2:使用mouseup 诀窍3:完成之后,移除事件 showpopover (e) { this.popover = !this.popo ...

  7. MySQL-Transfer2.3发布

    Transfer 2.3发布,下载地址 此版本除了升级based版本外 *优化了无索引表的同步性能 *优化了slave模式下超大事务内存消耗问题 *Transfer模式相关的功能改动较多 *修复tra ...

  8. 【ecshop后台详解】系统设置-商店设置

    商店设置是我们ecshop新用户第一步先要设置的地方,因为里面相当于网站的基础.包括公司名称,电话,地址,tittle等重要的信息都是这里修改,如果这里没有修改的话,如果有访客来到你网站可能以为走错了 ...

  9. OpenCV3+Python3

    OpenCV3计算机视觉Python语言实现笔记 图像处理与OpenCV Python3与OpenCV3.3 图像处理 OpenCV文摘 基于Python3 + OpenCV3.3.1的远程监控程序 ...

  10. centos 安装部署ftp服务器

    0. 安装ftp yum install vsftpd 1. 添加ftp账户 useradd -d /home/test -g ftp -s /sbin/nologin test 命令的意思: 添加t ...