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. L2-014. 列车调度(Dilworth定理)

    火车站的列车调度铁轨的结构如下图所示. Figure 两端分别是一条入口(Entrance)轨道和一条出口(Exit)轨道,它们之间有N条平行的轨道.每趟列车从入口可以选择任意一条轨道进入,最后从出口 ...

  2. oa_mvc_easyui_删除(6)

    1.删除列,添加a标签,绑定参数 <a href="javascript:void(0)" class="delete" ids="@newli ...

  3. Keepalived+Nginx+Tomcat 实现高可用Web集群

    https://www.jianshu.com/p/bc34f9101c5e Keepalived+Nginx+Tomcat 实现高可用Web集群 0.3912018.01.08 20:28:59字数 ...

  4. Mysql学习(二)之通过homebrew安装mysql后,为什么在系统偏好设置里没有mysql

    原因 用brew install packagename是用来安装命令行工具的,一般不可能影响到图形界面. mysql官方文档是通过dmg文件安装的: The MySQL Installation P ...

  5. 链接校验——是否是协议http://或https://开头的

    if(str.substr(0,7)!="http://" && str.substr(0,7)!="https://"){ return 'y ...

  6. Spark运行时的内核架构以及架构思考

    一: Spark内核架构 1,Drive是运行程序的时候有main方法,并且会创建SparkContext对象,是程序运行调度的中心,向Master注册程序,然后Master分配资源. 应用程序: A ...

  7. mybatis查询返回的对象不为null,但是属性值为null

    返回的对象不为null,但是属性值为null 代码如下: <resultMap id="BaseResultMap" type="com.trhui.ebook.d ...

  8. Chrome去掉标签页8个框

    最终效果: 解决思路: 在标签页鼠标右击弹出的菜单项中存在“查看页面源码”一项,由此可确定chrome的标签页是由一个html页面控制的,只要修改其页面源码便能去掉8个框. 经网上查阅确定了标签页的源 ...

  9. 第十篇.2、python并发编程之多进程

    一 multiprocessing模块介绍 python中的多线程无法利用多核优势,如果想要充分地使用多核CPU的资源(os.cpu_count()查看),在python中大部分情况需要使用多进程.P ...

  10. Gh0st与云安全

    黑产攻击途径升级,云服务成重灾区 在我们的印象里,黑产以及相关的肉鸡DDOS攻击总是离我们很远.可实际情况并非如此,特别是在云服务大行其道的今天. 日前,腾讯反病毒实验室就观察到了国内云服务中Gh0s ...