activemq安装使用教程
一、下载安装
下载地址: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安装使用教程的更多相关文章
- IntelliJ IDEA - 热部署插件JRebel 安装使用教程
IntelliJ IDEA - JRebel 安装使用教程 JRebel 能做什么? JRebel 是一款热部署插件.当你的 Java-web 项目在 tomcat 中 run/debug 的时候 , ...
- Zabbix3.x安装图解教程
准备知识: Zabbix3.x比较之前的2.0界面有了很大的变化,但是安装部署过程与2.x基本完全一样. 1.Zabbix2.x安装图解教程 http://www.osyunwei.com/archi ...
- VMware vCenter Server安装图解教程
安装说明: 1.安装VMware vCenter Server的主机操作系统为:Windows Server 2008 R2 2.在Windows Server 2008 R2中需要预先安装好SQL ...
- 在RedHat.Enterprise.Linux_v6.3系统中安装Oracle_11gR2教程
在RedHat.Enterprise.Linux_v6.3系统中安装Oracle_11gR2教程 本教程提供PDF格式下载: 在RedHat.Enterprise.Linux_v6.3系统中安装Ora ...
- Zabbix安装图解教程
说明: 操作系统:CentOS IP地址:192.168.21.127 Web环境:Nginx+MySQL+PHP zabbix版本:Zabbix 2.2 LTS 备注:Linux下安装zabbix需 ...
- MapGIS6.7安装图文教程(完美破解)
mapgis安装比较简单,主要注意在安装的时候,先打开软件狗,然后再进行软件安装,一般就不会照成其他安装失败的现象,有时候安装之前没有打开软件狗也安装成功了,也有这情况,不过软件使用也需要软件狗的支持 ...
- VirtualBox安装Ubuntu教程
1.VirtualBox虚拟机安装,及VirtualBox安装Ubuntu教程VirtualBox版本为VirtualBox-4.3.12-93733-Win.exe,Ubuntu版本为ubuntu- ...
- MySQL5.0版本的安装图解教程
MySQL5.0版本的安装图解教程是给新手学习的,当前mysql5.0.96是最新的稳定版本. mysql 下载地址 http://www.jb51.net/softs/2193.html 下面的是M ...
- ENVI5.1安装破解教程
原文地址: ENVI5.1安装破解_百度经验 http://jingyan.baidu.com/article/020278118b5ded1bcd9ce57a.html ENVI5.1_x86 ...
随机推荐
- LeetCode: Permutation Sequence 解题报告
Permutation Sequence https://oj.leetcode.com/problems/permutation-sequence/ The set [1,2,3,…,n] cont ...
- Qt动态库静态库的创建、使用、多级库依赖、动态库改成静态库等详细说明
本文描述的是windows系统下,通过qtcreator在pro文件中添加动态库与静态库的方法: 1.添加动态库(直接添加动态库文件.dll,非子项目) 通过qtcreator创建动态库的方法就不在此 ...
- Log4j2在项目中的常用配置
~~~~~~~~~~~~~~~~~~~~log4j2.xml文件内容 <?xml version="1.0" encoding="UTF-8"?>& ...
- 斯坦福2011秋季 iPad and iPhone Application Development 资源
1. MVC and Introduction to Objective-C (September 27, 2011) - HD 2. My First iOS App (September 29, ...
- 【问题集】redis.clients.jedis.exceptions.JedisDataException: ERR value is not an integer or out of range
redis.clients.jedis.exceptions.JedisDataException: ERR value is not an integer or out of range incrm ...
- C#实现如何判断一个数组中是否有重复的元素
如何判断一个数组中是否有重复的元素 实现判断数组中是否包含有重复的元素方法 这里用C#代码给出实例 方法一:可以新建一个hashtable利用hashtable的Contains方法进行查找 /// ...
- 【译】python configparser中默认值的设定
在做某一个项目时,在读配置文件中,当出现配置文件中没有对应项目时,如果要设置默认值,以前的做法是如下的: try: apple = config.get(section, 'apple') excep ...
- Linux下的tr编辑器命令详解
通过使用 tr,您可以非常容易地实现 sed 的许多最基本功能.您可以将 tr 看作为 sed 的(极其)简化的变体:它可以用一个字符来替换另一个字符,或者可以完全除去一些字符.您也可以用它来除去重复 ...
- day_4_27 py
''' 2018-4-27 19:57:29 其实这些都是讲的类和对象的 self(在定义方法的时候默认的参数)就相当于java里面的this关键字, this.name=name class 类名: ...
- KMP 算法详解
之前模模糊糊的理解了KMP,结果由于并不是完全弄清楚而导致自己在一道题目上疯狂的T,似乎是next函数写的有问题,于是痛心疾首的回来写一篇报告,警示自己 对KMP来说,匹配串的next数组是重中之重, ...