Broker:英语有代理的意思,在activemq中,Broker就相当于一个Activemq实例。

1. 命令行启动实例:

1.activemq start使用默认的activemq.xml启动

E:\activemq\apache-activemq-5.15.\bin>pwd
/e/activemq/apache-activemq-5.15./bin E:\activemq\apache-activemq-5.15.\bin>ls
activemq activemq.bat win32 wrapper.jar
activemq-admin.bat activemq.jar win64 E:\activemq\apache-activemq-5.15.\bin>activemq.bat
Java Runtime: Oracle Corporation 1.8.0_121 C:\Program Files\Java8\jdk1..0_121\jre
Heap sizes: current=1005056k free=989327k max=1005056k
JVM args: -Dcom.sun.management.jmxremote -Xms1G -Xmx1G -Djava.util.logging.config.file=logging.properties -Djava.se
urity.auth.login.config=E:\activemq\apache-activemq-5.15.\bin\..\conf\login.config -Dactivemq.classpath=E:\activemq\ap
che-activemq-5.15.\bin\..\conf;E:\activemq\apache-activemq-5.15.\bin\../conf;E:\activemq\apache-activemq-5.15.\bin\.
/conf; -Dactivemq.home=E:\activemq\apache-activemq-5.15.\bin\.. -Dactivemq.base=E:\activemq\apache-activemq-5.15.\bin
.. -Dactivemq.conf=E:\activemq\apache-activemq-5.15.\bin\..\conf -Dactivemq.data=E:\activemq\apache-activemq-5.15.\bi
\..\data -Djava.io.tmpdir=E:\activemq\apache-activemq-5.15.\bin\..\data\tmp
Extensions classpath:
[E:\activemq\apache-activemq-5.15.\bin\..\lib,E:\activemq\apache-activemq-5.15.\bin\..\lib\camel,E:\activemq\apache
activemq-5.15.\bin\..\lib\optional,E:\activemq\apache-activemq-5.15.\bin\..\lib\web,E:\activemq\apache-activemq-5.15.
\bin\..\lib\extra]
ACTIVEMQ_HOME: E:\activemq\apache-activemq-5.15.\bin\..
ACTIVEMQ_BASE: E:\activemq\apache-activemq-5.15.\bin\..
ACTIVEMQ_CONF: E:\activemq\apache-activemq-5.15.\bin\..\conf
ACTIVEMQ_DATA: E:\activemq\apache-activemq-5.15.\bin\..\data
Usage: Main [--extdir <dir>] [task] [task-options] [task data] Tasks:
browse - Display selected messages in a specified destination.
bstat - Performs a predefined query that displays useful statistics regarding the specified brok
r
consumer - Receives messages from the broker
create - Creates a runnable broker instance in the specified path.
decrypt - Decrypts given text
dstat - Performs a predefined query that displays useful tabular statistics regarding the specif
ed destination type
encrypt - Encrypts given text
export - Exports a stopped brokers data files to an archive file
list - Lists all available brokers in the specified JMX context
producer - Sends messages to the broker
purge - Delete selected destination's messages that matches the message selector
query - Display selected broker component's attributes and statistics.
start - Creates and starts a broker using a configuration file, or a broker URI.
stop - Stops a running broker specified by the broker name. Task Options (Options specific to each task):
--extdir <dir> - Add the jar files in the directory to the classpath.
--version - Display the version information.
-h,-?,--help - Display this help information. To display task specific help, use Main [task] -h,-?,--help Task Data:
- Information needed by each specific task. JMX system property options:
-Dactivemq.jmx.url=<jmx service uri> (default is: 'service:jmx:rmi:///jndi/rmi://localhost:1099/jmxrmi')
-Dactivemq.jmx.user=<user name>
-Dactivemq.jmx.password=<password> E:\activemq\apache-activemq-5.15.\bin>activemq.bat start
Java Runtime: Oracle Corporation 1.8.0_121 C:\Program Files\Java8\jdk1..0_121\jre
Heap sizes: current=1005056k free=989327k max=1005056k

启动后访问后台:

2.activemq start xbean:file:../conf/activemq2.xml   使用指定的配置文件进行启动

1.我们把con目录下的activemq2.xml重新命名为activemq2.xml

2.再次直接start启动会报错:

ERROR: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path
resource [activemq.xml]; nested exception is java.io.FileNotFoundException: class path resource [activemq.xml] cannot be
opened because it does not exist
org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resourc
e [activemq.xml]; nested exception is java.io.FileNotFoundException: class path resource [activemq.xml] cannot be opened
because it does not exist

3.我们指定启动的xml文件位置再次启动可以启动成功

activemq start xbean:file:../conf/activemq2.xml

3.如果不指定file,也就是xbean:activemq2.xml,那么activemq2.xml必须在classpath目录下

2.用activemq来构建java应用---不依赖于ActiveMQ应用,只需要jar包即可实现

  这里主要是用Activemq Broker作为独立的消息服务器来构建Java应用。简单的说,就是在java应用中启动activemq。这种方式会以进程的方式启动一个新的JVM来支持连接。

嵌入式Broker启动

  下面的启动方式都不能通过http访问连接,要想测试是否启动成功只能通过收消息和发消息来测试。

1.通过BrokerService方式启动

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

2.通过  BrokerFactory 启动

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

broker.properties内容如下:

useJmx=true
persistent=false
brokerName=QQQ

当然上面的确定方式都有对应的整合Spring之后的启动方式。

3.BrokerService方式整合spring启动

  单例模式的BrokerService,加载完成之后调用start方法即可。

    <!--Broker启动方式-->
<bean id="brokerService" class="org.apache.activemq.broker.BrokerService" init-method="start" destroy-method="stop">
<property name="brokerName" value="broker1"/>
<property name="persistent" value="false"/>
<property name="transportConnectorURIs">
<list>
<value>tcp://localhost:61616</value>
</list>
</property>
</bean>

从上面也可以看出,一个Broker可以配置多个连接的URI,如下面配置:(端口必须不同)

    <!--Broker启动方式-->
<bean id="brokerService" class="org.apache.activemq.broker.BrokerService" init-method="start" destroy-method="stop">
<property name="brokerName" value="broker1"/>
<property name="persistent" value="false"/>
<property name="transportConnectorURIs">
<list>
<value>tcp://localhost:61616</value>
<value>tcp://localhost:61618</value>
</list>
</property>
</bean>

4.通过  BrokerFactory 结合spring启动

spring的主配置文件:

    <!--Broker启动方式-->
<bean id="brokerService" class="org.apache.activemq.xbean.BrokerFactoryBean">
<property name="config" value="activemq.xml"/>
<property name="start" value="true"/>
</bean>

activemq.xml位于classpath下,内容如下:

<beans
xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://activemq.apache.org/schema/core http://activemq.apache.org/schema/core/activemq-core.xsd"> <!--
The <broker> element is used to configure the ActiveMQ broker.
-->
<broker xmlns="http://activemq.apache.org/schema/core" brokerName="localhost" dataDirectory="${activemq.data}"> <destinationPolicy>
<policyMap>
<policyEntries>
<policyEntry topic=">" >
<!-- The constantPendingMessageLimitStrategy is used to prevent
slow topic consumers to block producers and affect other consumers
by limiting the number of messages that are retained
For more information, see: http://activemq.apache.org/slow-consumer-handling.html -->
<pendingMessageLimitStrategy>
<constantPendingMessageLimitStrategy limit="1000"/>
</pendingMessageLimitStrategy>
</policyEntry>
</policyEntries>
</policyMap>
</destinationPolicy> <!--
The systemUsage controls the maximum amount of space the broker will
use before disabling caching and/or slowing down producers. For more information, see:
http://activemq.apache.org/producer-flow-control.html
-->
<systemUsage>
<systemUsage>
<storeUsage>
<storeUsage limit="100 gb"/>
</storeUsage>
<tempUsage>
<tempUsage limit="50 gb"/>
</tempUsage>
</systemUsage>
</systemUsage> <transportConnectors>
<!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
<transportConnector name="openwire" uri="tcp://localhost:61616?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
</transportConnectors>
</broker>
</beans>

3.ActiveMQ的Broker方式启动多个broker的方法

1.复制conf文件夹并重新命名为conf2

2.修改conf2文件下的activemq.xml

修改brokerName

修改持久化的数据目录

修改transportConnector的端口,要与第一个默认的不同

        <transportConnectors>
<!-- DOS protection, limit concurrent connections to 1000 and frame size to 100MB -->
<transportConnector name="openwire" uri="tcp://0.0.0.0:61617?maximumConnections=1000&amp;wireFormat.maxFrameSize=104857600"/>
</transportConnectors>

3.修改conf2\jetty.xml,主要是改端口

    <bean id="jettyPort" class="org.apache.activemq.web.WebConsolePort" init-method="start">
<!-- the default port number for the web console -->
<property name="host" value="0.0.0.0"/>
<property name="port" value="8162"/>
</bean>

4.复制bin目录下面的activemq.bat并命名为activemq2.bat(如果是linux操作系统复制activemq)

5.修改activemq2.bat中的配置文件目录:

6.启动两个broker (如果是linux还需要赋予上面复制后的文件可执行权限 chmod +x activemq2)

activemq2.bat start  和 activemq.bat start

7.http界面查看jetty服务器

ActiveMQ中Broker的应用与启动方式的更多相关文章

  1. Android中Activity的四种启动方式

    谈到Activity的启动方式必须要说的是数据结构中的栈.栈是一种只能从一端进入存储数据的线性表,它以先进后出的原则存储数据,先进入的数据压入栈底,后进入的数据在栈顶.需要读取数据的时候就需要从顶部开 ...

  2. ubuntu中为Pycharm添加快捷启动方式

    1. sudo gedit /usr/share/applications/Pycharm.desktop 2.在文件中添加: [Desktop Entry] Type=Application Nam ...

  3. centos7中设置nginx的systemctl启动方式

    1.建立服务文件 (1)文件路径 vim /usr/lib/systemd/system/nginx.service (2)服务文件内容 [Unit] Description=nginx - high ...

  4. activemq在一台服务器上启动多个Broker

    步骤如下: 1.把整个conf文件夹复制一份,比如叫conf2 2.修改里面的activemq.xml文件 ①brokerName不能和原来的重复 ②数据存放的文件名称不能重复,比如<kahaD ...

  5. activemq的启动方式

    一.简介:ActiveMQ 是Apache出品,最流行的,能力强劲的开源消息总线.ActiveMQ 是一个完全支持JMS1.1和J2EE 1.4规范的 JMS Provider实现,尽管JMS规范出台 ...

  6. RocketMQ中Broker的启动源码分析(一)

    在RocketMQ中,使用BrokerStartup作为启动类,相较于NameServer的启动,Broker作为RocketMQ的核心可复杂得多 [RocketMQ中NameServer的启动源码分 ...

  7. RocketMQ中Broker的启动源码分析(二)

    接着上一篇博客  [RocketMQ中Broker的启动源码分析(一)] 在完成准备工作后,调用start方法: public static BrokerController start(Broker ...

  8. 性能测试之Jmeter中场景设置与启动方式

    Jmeter场景设置与启动方式 性能测试场景是用来模拟模拟真实用户操作的工作单元,所以场景设计一定要切合用户的操作逻辑,jmeter主要是通过线程组配合其他组件来一起完成场景的设置. 线程组设置 Jm ...

  9. 在ubuntu16.4中为pycharm创建桌面快捷启动方式

    在ubuntu环境中每次使用pycharm需要到它的安装目录中执行./pycharm.sh来启动pycharm.比较麻烦,既然ubuntu提供了桌面环境我们应该从分利用.哈哈哈... 上干货 我的py ...

随机推荐

  1. 利用/dev/urandom文件创建随机数

    1:/dev/urandom和/dev/random是什么 这两个文件记录Linux下的熵池,所谓熵池就是当前系统下的环境噪音,描述了一个系统的混乱程度,环境噪音由这几个方面组成,如内存的使用,文件的 ...

  2. mysql如何从全备文件中恢复单个库或者单个表

    mysql如何从全备文件中恢复单个库或者单个表 在mysql dba的日常实际工作中,一个实例下有多个库,而我们常见的备份就是全库备份.那么问题就来了,如果需要恢复单个库或者单个表,怎么办了,网上有很 ...

  3. 2016vijos 1-2 股神小L(堆)

    维护前i天的最优解,那么在后面可能会对前面几天的买卖情况进行调整 如果前面买入,买入的这个在后面一定不会卖出 如果前面卖出,卖出的这个可能会在后面变成买入,因为买这个,卖后面的会获得更多的收益 用一个 ...

  4. HDU 1028(数字拆分 分治)

    题意是求所给的数能够被拆分成的不同组合数目. 方法有三种: 一.完全背包. 限制条件:所用数字不大于 n. 目标:求分解种数(组合出 n 的方法数). 令 dp[ i ][ j ] = x 表示 用前 ...

  5. 分布式配置 SSH 免密登陆

    原地址忘记了,暂且记下 一.准备工作 1) 用客户端工具(ssh client或者putty)连接到linux服务器.在root用户下输入命令 vi /etc/hosts,用vi编辑hosts文件,如 ...

  6. 062、如何使用flannel host-gw backend(2019-04-02 周二)

    参考https://www.cnblogs.com/CloudMan6/p/7457653.html   flannel 支持多种backend,前面学习的是 vxlan backend ,host- ...

  7. 自学python 3.

    1.name = "aleX leNb" 1.a = name.strip() print(a) 2.a = name.lstrip('al') print(a) 3.a = na ...

  8. 混合app开发--js和webview之间的交互总结

    使用场景:原生APP内嵌套H5页面,app使用的是webview框架进行嵌套 这样就存在两种情况 1.原生app调用H5的方法 2.H5调用app的方法 分别讲解下,其实app与H5之间的交互式非常简 ...

  9. 905. Sort Array By Parity

    Description Given an array A of non-negative integers, return an array consisting of all the even el ...

  10. python代码块和小数据池

    id和is 在介绍代码块之前,先介绍两个方法:id和is,来看一段代码 # name = "Rose" # name1 = "Rose" # print(id( ...