一、下载安装

下载地址: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. 基于Docker的redis集群搭建

    Redis集群官方介绍:http://www.redis.cn/topics/cluster-tutorial.html 基于Docker搭建Redis集群 环境:6个节点,三主三从 制作Redis镜 ...

  2. 决策树1 -- ID3_C4.5算法

    声明: 1.本篇为个人对<2012.李航.统计学习方法.pdf>的学习总结,不得用作商用.欢迎转载,但请注明出处(即:本帖地址). 2,因为本人在学习初始时有非常多数学知识都已忘记,因此为 ...

  3. android ROM刷机updater-script单刷补丁包脚本

    ui_print(""); ui_print("-------------------------"); ui_print(" Let's Go &q ...

  4. 【转】Android开发教程 --- Android调用WS

    原文地址:http://www.cnblogs.com/jasoncc/archive/2011/12/23/2297950.html Hi,大家好! 上节我们搭建了Java版的WS,那么在Andro ...

  5. 蛋疼的mysql_ping()以及MYSQL_OPT_RECONNECT

    From: https://www.felix021.com/blog/read.php?2102 昨天@Zind同学找到我之前的一篇blog(已经修改),里面提到了mysql_ping和MYSQL_ ...

  6. 性能优化系列七:SQL优化

    一.SQL在数据库中的执行过程 二.执行计划 1. ACID 原子性:一个事务(transaction)中的所有操作,要么全部完成,要么全部不完成,不会结束在中间某个环节.事务在执行过程中发生错误,会 ...

  7. X-Frame-Options 配置

    最近在修改ASP老网站,使用是iframe框架部署上去后出现“此内容不能显示在一个框架中”错误 以下错误解决方案是需要配置:X-Frame-Options X-Frame-Options: 他的值有三 ...

  8. [Stats385] Lecture 03, Harmonic Analysis of Deep CNN

    大咖秀,注意提问环节大家的表情,深入窥探大咖的心态,很有意思. 之前有NG做访谈,现在这成了学术圈流行. Video: https://www.youtube.com/watch?v=oCohnBbm ...

  9. [Converge] Weight Initialiser

    From: http://www.cnblogs.com/denny402/p/6932956.html [, ] fully connected w = tf.Variable(tf.truncat ...

  10. [Laravel] 06 - Project: from Usercase to View

    故事背景 一.项目预览 From: https://www.imooc.com/video/12518 二.知识点 通过项目复习之前的重难点,在此列出并解决. /* implement */ 项目开始 ...