一、下载安装

下载地址:http://activemq.apache.org/activemq-5158-release.html

然后解压即可,apache的东西解压后就可以使用了。

二、启动

在安装目录的bin目录下:

activemq start

就可以启动了。

访问localhost:8161就可以访问

如果你想修改用户名和密码的话,在conf/jetty-realm.properties中修改即可。

然后重启就可以。

三、demo

启动activemq 中的 demo

activemq start xbean:file:../examples/conf/activemq-demo.xml

访问:

http://localhost:8161/demo/

然后就可以收发消息了。

四、自己使用

介绍web项目中spring集成activemq

maven依赖:

    <dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-all</artifactId>
<version>5.15.0</version>
</dependency> <dependency>
<groupId>org.apache.activemq</groupId>
<artifactId>activemq-spring</artifactId>
<version>5.15.0</version>
</dependency>

applicationContext.xml

<?xml version="1.0" encoding="UTF-8"?>
<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.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd"> <!--设置注解类所在的jar包-->
<context:component-scan base-package="com.linewell" />
<!-- 连接池 -->
<bean id="pooledConnectionFactory" class="org.apache.activemq.pool.PooledConnectionFactory" destroy-method="stop">
<property name="connectionFactory">
<bean class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616"/>
</bean>
</property>
</bean> <!-- 连接工厂 -->
<bean id="activeMQConnectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory">
<property name="brokerURL" value="tcp://localhost:61616"/>
</bean> <!-- 配置消息目标 -->
<bean id="destination" class="org.apache.activemq.command.ActiveMQQueue">
<!-- 目标,在ActiveMQ管理员控制台创建 http://localhost:8161/admin/queues.jsp -->
<constructor-arg index="0" value="sagedragon.mq.queue"/>
</bean> <!-- 消息模板 -->
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate">
<property name="connectionFactory" ref="activeMQConnectionFactory"/>
<property name="defaultDestination" ref="destination"/>
<property name="messageConverter">
<bean class="org.springframework.jms.support.converter.SimpleMessageConverter"/>
</property>
</bean>
</beans>

web.xml配置

<!DOCTYPE web-app PUBLIC
"-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
"http://java.sun.com/dtd/web-app_2_3.dtd" > <web-app>
<display-name>Archetype Created Web Application</display-name>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>classpath*:applicationContext.xml</param-value>
</context-param>
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/</url-pattern>
</filter-mapping>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<servlet>
<servlet-name>MqtestServlet</servlet-name>
<servlet-class>com.linewell.servlets.MqtestServlet</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>MqtestServlet</servlet-name>
<url-pattern>/activemq/MqtestServlet</url-pattern>
</servlet-mapping>
</web-app>

发送者:

package com.linewell.activemq;

import org.springframework.jms.core.JmsTemplate;
import org.springframework.jms.core.MessageCreator;
import org.springframework.stereotype.Service; import javax.jms.JMSException;
import javax.jms.MapMessage;
import javax.jms.Message;
import javax.jms.Session;
import java.util.Date; import javax.annotation.Resource; @Service
public class SpringSender { @Resource
private JmsTemplate jmsTemplate; public void sendMsg() {
jmsTemplate.send(new MessageCreator() {
public Message createMessage(Session session) throws JMSException {
MapMessage message = session.createMapMessage();
System.out.println("开始发送消息...");
message.setString("message", "current system time: " + new Date().getTime());
return message;
}
});
}
}

接收者:

package com.linewell.activemq;

import org.springframework.context.ApplicationContext;
import org.springframework.context.support.FileSystemXmlApplicationContext;
import org.springframework.jms.core.JmsTemplate;
import org.springframework.stereotype.Service; import javax.annotation.Resource;
import java.util.Map; @Service
public class SpringReceiver { @Resource
private JmsTemplate jmsTemplate; public void receiveMsg() {
while (true) {
Map<String, Object> map = (Map<String, Object>) jmsTemplate.receiveAndConvert();
System.out.println("收到消息:" + map.get("message"));
}
}
}

activemq安装使用教程的更多相关文章

  1. IntelliJ IDEA - 热部署插件JRebel 安装使用教程

    IntelliJ IDEA - JRebel 安装使用教程 JRebel 能做什么? JRebel 是一款热部署插件.当你的 Java-web 项目在 tomcat 中 run/debug 的时候 , ...

  2. Zabbix3.x安装图解教程

    准备知识: Zabbix3.x比较之前的2.0界面有了很大的变化,但是安装部署过程与2.x基本完全一样. 1.Zabbix2.x安装图解教程 http://www.osyunwei.com/archi ...

  3. VMware vCenter Server安装图解教程

    安装说明: 1.安装VMware vCenter Server的主机操作系统为:Windows Server 2008 R2 2.在Windows Server 2008 R2中需要预先安装好SQL ...

  4. 在RedHat.Enterprise.Linux_v6.3系统中安装Oracle_11gR2教程

    在RedHat.Enterprise.Linux_v6.3系统中安装Oracle_11gR2教程 本教程提供PDF格式下载: 在RedHat.Enterprise.Linux_v6.3系统中安装Ora ...

  5. Zabbix安装图解教程

    说明: 操作系统:CentOS IP地址:192.168.21.127 Web环境:Nginx+MySQL+PHP zabbix版本:Zabbix 2.2 LTS 备注:Linux下安装zabbix需 ...

  6. MapGIS6.7安装图文教程(完美破解)

    mapgis安装比较简单,主要注意在安装的时候,先打开软件狗,然后再进行软件安装,一般就不会照成其他安装失败的现象,有时候安装之前没有打开软件狗也安装成功了,也有这情况,不过软件使用也需要软件狗的支持 ...

  7. VirtualBox安装Ubuntu教程

    1.VirtualBox虚拟机安装,及VirtualBox安装Ubuntu教程VirtualBox版本为VirtualBox-4.3.12-93733-Win.exe,Ubuntu版本为ubuntu- ...

  8. MySQL5.0版本的安装图解教程

    MySQL5.0版本的安装图解教程是给新手学习的,当前mysql5.0.96是最新的稳定版本. mysql 下载地址 http://www.jb51.net/softs/2193.html 下面的是M ...

  9. ENVI5.1安装破解教程

    原文地址:  ENVI5.1安装破解_百度经验 http://jingyan.baidu.com/article/020278118b5ded1bcd9ce57a.html   ENVI5.1_x86 ...

随机推荐

  1. Emacs常用基本操作

    按键约定 组合按键 Emacs中大量的按键操作都是各式各样的组合按键(快捷键),下面是几种通常的约定: Ctrl键:表示为C Alt键:表示为M Shift键:表示为S 组合按键:比如向下移动一行的组 ...

  2. 发展简史jQuery时间轴特效

    发展简史jQuery时间轴特效.这是一款鼠标滚动到一定的高度动画显示企业发展时间轴特效.效果图如下: 在线预览   源码下载 实现的代码. html代码: <div class="wr ...

  3. 【九天教您南方cass 9.1】 03 编码法绘制地形图

    同学们大家好,欢迎收看由老王测量上班记出品的cass9.1视频课程 我是本节课主讲老师九天. 测量空间的[九天教您南方cass]专栏是九天老师专门开设cass免费教学班.希望能帮助那些刚入行的同学,并 ...

  4. 开源网络库ACE、Boost的ASIO、libevent、libev、ZeroMQ

    开源C/C++网络库:ACE          C++语言 跨平台Boost的ASIO  C++语言 跨平台libevent     C语言   主要支持linux,新版增加了对windows的IOC ...

  5. Brainfuck反汇编(Python)

    global cs global ip global ss #global sp global ds global bp global tab global out #cs='++++++++++[& ...

  6. 非root用户如何使用docker命令

    docker命令默认只能root使用的,但我们可以赋权给其他用户,使用时先照常新建用户: [root@10 ~]# useradd docker [root@10 ~]# passwd docker ...

  7. 二、主流区块链技术特点及Hyperledger Fabric V0.6版本特点

    一.主流区块链技术特点 二.HyperLedger子项目 三.Hyperledger fabric架构 V0.6逻辑架构: V0.6区块链网络 对应的0.6版本的运行时架构: 0.6版本的架构特点是: ...

  8. 131、ThreadLocal (转载)

    http://blog.csdn.net/lufeng20/article/details/24314381 http://baike.baidu.com/link?url=7eL0qQm_5ULls ...

  9. 【typecho】解决使用分隔符 <!--more-->标签后首页文字下面出现一段空白

    使用typecho 搭建了一个站点,输出摘要时候.使用了   <!--more-->  分隔符,然后首页文章出现了一大片空白,审查元素发现.多了好多 <br> 标签 解决办法: ...

  10. Centos 解决SSH 免密码登录 以及Crontab制作定时SSH自动登录和关闭的脚本

    一.SSH免密码登录 假设要登录的机器为192.168.1.100,当前登录的机器为192.168.1.101. 首先在101的机器上生成密钥(如果已经生成可以跳过): $ ssh-keygen -t ...