ActivemQ构建应用
Broker:相当于一个 ActiveMQ服务器实例
命令行启动参数示例如下:
1: activemq start:使用默认的 actived.xml来启动
2: activemq start xbean:file: ../onf/ actived-2.xml:使用指定的配置文件
来启动
3:如果不指定file,也就是 xbean: activemq-2.xml,那么xml必须在 classpath下面
用 ActiveMQ米构建Java应用
这里主要将用 Activemq broken作为独立的消息服务器来构建JAVA应用
ActiveMQ也支持在vm中通信基于嵌入式的 broker,能够无缝的集成其它Java应用

■嵌入式 Broker启动
1: Broker service启动 broker,示例如下:

BrokerService broker=new BrokerService();
broker.setUseJmx(true);
broker.addConnector("tcp://localhost:61616");
broker.start();

package com.mq.test.activeMQ;

import java.net.URI;

import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService;
import org.omg.CORBA.portable.ApplicationException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class InnerBroker {
public static void main(String[] args) throws Exception {
BrokerService broker=new BrokerService();
broker.setUseJmx(true);
broker.addConnector("tcp://localhost:61616");
broker.start(); }
}

2: BrokerFactory启动 broker,示例如下:

String Uri ="properties:broker.properties";
BrokerService broker1 =BrokerFactory.createBroker(new URI(Uri));
broker1.addConnector("tcp://localhost:61616");
broker1.start();

broker.properties

useJmx=true
persistent=false
brokerName=cheese

package com.mq.test.activeMQ;

import java.net.URI;

import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService;
import org.omg.CORBA.portable.ApplicationException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class InnerBroker {
public static void main(String[] args) throws Exception {
String Uri ="properties:broker.properties";
BrokerService broker1 =BrokerFactory.createBroker(new URI(Uri));
broker1.addConnector("tcp://localhost:61616");
broker1.start(); }
}

3:利用Spring集成Broker,Spring的配置文件如下:

<bean id="broker" class="org.apache.activemq.broker.BrokerService" init-method="start" destroy-method="stop">
<property name="brokerName" value="myBroker" />
<property name="persistent" value="false"></property>
<property name="transportConnectorURIs" >
<list>
<value>tcp://localhost:61616</value>
</list>
</property>
</bean>

package com.mq.test.activeMQ;

import java.net.URI;

import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService;
import org.omg.CORBA.portable.ApplicationException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.support.ClassPathXmlApplicationContext; public class InnerBroker {
public static void main(String[] args) throws Exception { ApplicationContext ctx =new ClassPathXmlApplicationContext("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:p="http://www.springframework.org/schema/p"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-3.2.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.2.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-3.2.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-3.2.xsd"
default-autowire="byName" default-lazy-init="false"> <bean id="broker" class="org.apache.activemq.broker.BrokerService" init-method="start" destroy-method="stop">
<property name="brokerName" value="myBroker" />
<property name="persistent" value="false"></property>
<property name="transportConnectorURIs" >
<list>
<value>tcp://localhost:61616</value>
</list>
</property>
</bean> </beans>

或者配置 BrokerFactoryBean,示例如下:
<beans>
<bean id=broker class="org. apache. activemq. xbean. BrokerFactoryBean">
<Property name="config" value="resources/activemq-simple.xml"/>
<property name="start" value="true"/>
</bean>
</beans>
■ ActiveMQ的启动:
1:可以通过在应用程序中以编码的方式启动 broker,例如: broker. start(
如果需要启动多个 broker,那么需要为 broker设置一个名字。例如
BrokerService broker= new BrokerService();
broker.setName("fred")
broker.addConnector("tcp: //localhost: 61616")
broker.start
2:还可以通过 spring来启动,前面已经演示过了

分布式-信息方式-ActiveMQ构建应用的更多相关文章

  1. 分布式-信息方式-ActiveMQ的Message dispatch高级特性之(指针) Message cursors

    Message dispatch高级特性之 Message cursors概述            ActiveMQ发送持久消息的典型处现方式是:当消息的消费者准备就绪时,消息发送系统把存储的 消息 ...

  2. 分布式-信息方式-ActiveMQ的Destination高级特性3

    虚拟destination用来创建逻辑destination,客户端可以通过它来生产和消费消息,它会把消息映射到物理destination. ActiveMQ支持2种方式: 1:虚拟主题(Virtua ...

  3. 分布式-信息方式-ActiveMQ的Destination高级特性1

    ActiveMQ的Destination高级特性 Destination高级特性----->Composite Destinations 组合队列Composite Destinations : ...

  4. 分布式-信息方式-ActiveMQ的集群

    ActiveMQ的集群Queue consumer clusters              ActiveMQ支持 Consumer对消息高可靠性的负载平衡消费,如果一个 Consumer死掉,该消 ...

  5. 分布式-信息方式-ActiveMQ静态网络连接的容错

    容错的链接Failover Protocol 前面讲述的都是client配置链接到指定的 broker上.但是,如果 Broker的链接失败怎么办呢?此时, Client有两个选项:要么立刻死掉,要么 ...

  6. 分布式-信息方式-ActiveMQ的消息存储持久化

    ActiveMQ的消息存储持久化■概述ActiveMQ不仅支持 persistent和 non-persistent两种方式,还支持消息的恢复( recovery)方式PTPQueue的存储是很简单的 ...

  7. 分布式-信息方式-ActiveMQ基础

    ActiveMQ简介 ActiveMQ是什么ActiveMQ是Apache推出的,一款开源全支持JMS.1和J2EE1.4范的JMS Provider实现的信息中间件.(message oriente ...

  8. 分布式-信息方式-ActiveMQ的Destination高级特性2

    使用filtered destinations,在xml配置如下: <destinationInterceptors> <virtualDestinationInterceptor& ...

  9. 分布式-信息方式-ActiveMQ的动态网络链接

    ActiveMQ的动态网络链接多播协议 multicast ActiveMQ使用 Multicast协议将一个 Service和其他的 Broker的 Service连接起来,IPmulticast是 ...

随机推荐

  1. sql--inner join , out join

    inner join(又叫join) out join包括left join,right join和full join(也就是left+right)

  2. 第四篇 jQuery中的事件与应用

    4.1 事件中的冒泡现象,ready()方法 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" & ...

  3. python读写txt文件

    整理平常经常用到的文件对象方法: f.readline()   逐行读取数据方法一: >>> f = open('/tmp/test.txt') >>> f.rea ...

  4. typeof,instanceof的区别,扩展知识:显示原型(prototype)与隐式类型(__protot__)

    3.typeof 和instanceof区别 1.typeof 主要用于判断对象类型 console.log(typeof null) //object console.log(typeof unde ...

  5. 互联网安全架构之常见的Web攻击手段及解决办法

    一.Web 安全常见攻击手段 XSS(跨站脚本攻击) SQL 注入 CSRF(跨站请求伪造) 上传漏洞 DDoS(分布式拒绝服务攻击)等 二.攻击手段原理及解决方案 1.XSS攻击 原理:XSS 攻击 ...

  6. ORACLE (BLOB、CLOB、NCLOB、BFILE)

    LOB类型 内置的LOB数据类型包括BLOB.CLOB.NCLOB.BFILE(外部存储)的大型化和非结构化数据,如文本.图像.视屏.空间数据存储.BLOB.CLOB.NCLOB类型 4.1 CLOB ...

  7. VirtualBox给CentOS虚拟机挂载磁盘扩大空间

    VirtualBox给CentOS虚拟机挂载磁盘扩大空间 楼主,发现虚拟机使用存储空间不够用的情况,需要改虚拟机挂载磁盘,扩容,在网上找了一波资料,于是整合记录操详细作如下: 概要步骤如下: 1.设置 ...

  8. RHEL6中LVM逻辑卷管理

    1.LVM 基本术语   物理卷(physical volume):物理卷在逻辑卷管理中处于最底层,它可以是实际物理硬盘上的分区,也可以是整个物理硬盘.   卷组(Volume Group):卷组建立 ...

  9. label smooth

    图像分类的一个trick,推导可参考这位博主https://leimao.github.io/blog/Label-Smoothing/ 知乎上的讨论https://www.zhihu.com/que ...

  10. 修正zen cart商品评论显示太短的问题

    找到includes\modules\pages\product_reviews\header_php.php $reviews_query_raw = “SELECT r.reviews_id, l ...