ActiveMQ in Action(2) - Transport
关键字: activemq
2.2 Transport
ActiveMQ目前支持的transport有:VM Transport、TCP Transport、SSL Transport、Peer Transport、UDP Transport、Multicast Transport、HTTP and HTTPS Transport、Failover Transport、Fanout Transport、Discovery Transport、ZeroConf Transport等。以下简单介绍其中的几种,更多请参考Apache官方文档。
2.2.1 VM Transport
VM transport允许在VM内部通信,从而避免了网络传输的开销。这时候采用的连接不是socket连接,而是直接地方法调用。 第一个创建VM 连接的客户会启动一个embed VM broker,接下来所有使用相同的broker name的VM连接都会使用这个broker。当这个broker上所有的连接都关闭的时候,这个broker也会自动关闭。
以下是配置语法:
vm://brokerName?transportOptions
例如:vm://broker1?marshal=false&broker.persistent=false
Transport Options的可选值如下:
| Option Name | Default Value | Description |
| Marshal | false | If true, forces each command sent over the transport to be marshlled and unmarshlled using a WireFormat |
| wireFormat | default | The name of the WireFormat to use |
| wireFormat.* | All the properties with this prefix are used to configure the wireFormat | |
| create | true | If the broker should be created on demand if it does not allready exist. Only supported in ActiveMQ 4.1 |
| broker.* | All the properties with this prefix are used to configure the broker. See Configuring Wire Formats for more information |
以下是高级配置语法:
vm:(broker:(tcp://localhost)?brokerOptions)?transportOptions
vm:broker:(tcp://localhost)?brokerOptions
例如:vm:(broker:(tcp://localhost:6000)?persistent=false)?marshal=false
Transport Options的可选值如下:
| Option Name | Default Value | Description |
| marshal | false | If true, forces each command sent over the transport to be marshlled and unmarshlled using a WireFormat |
| wireFormat | default | The name of the WireFormat to use |
| wireFormat.* | All the properties with this prefix are used to configure the wireFormat |
使用配置文件的配置语法:
vm://localhost?brokerConfig=xbean:activemq.xml
例如:vm:// localhost?brokerConfig=xbean:com/test/activemq.xml
使用Spring的配置:
- <bean id="broker" class="org.apache.activemq.xbean.BrokerFactoryBean">
- <property name="config" value="classpath:org/apache/activemq/xbean/activemq.xml" />
- <property name="start" value="true" />
- </bean>
- <bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory" depends-on="broker">
- <property name="brokerURL" value="vm://localhost"/>
- </bean>
2.2.2 TCP Transport
TCP transport 允许客户端通过TCP socket连接到远程的broker。以下是配置语法:
tcp://hostname:port?transportOptions
Transport Options的可选值如下:
| Option Name | Default Value | Description |
| minmumWireFormatVersion | 0 | The minimum version wireformat that is allowed |
| trace | false | Causes all commands that are sent over the transport to be logged |
| useLocalHost | true | When true, it causes the local machines name to resolve to "localhost". |
| socketBufferSize | 64 * 1024 | Sets the socket buffer size in bytes |
| soTimeout | 0 | sets the socket timeout in milliseconds |
| connectionTimeout | 30000 | A non-zero value specifies the connection timeout in milliseconds. A zero value means wait forever for the connection to be established. Negative values are ignored. |
| wireFormat | default | The name of the WireFormat to use |
| wireFormat.* | All the properties with this prefix are used to configure the wireFormat. See Configuring Wire Formats for more information |
例如:tcp://localhost:61616?trace=false
2.2.3 Failover Transport
Failover Transport是一种重新连接的机制,它工作于其它transport的上层,用于建立可靠的传输。它的配置语法允许制定任意多个复合的URI。Failover transport会自动选择其中的一个URI来尝试建立连接。如果没有成功,那么会选择一个其它的URI来建立一个新的连接。以下是配置语法:
failover:(uri1,...,uriN)?transportOptions
failover:uri1,...,uriN
Transport Options的可选值如下:
| Option Name | Default Value | Description |
| initialReconnectDelay | 10 | How long to wait before the first reconnect attempt (in ms) |
| maxReconnectDelay | 30000 | The maximum amount of time we ever wait between reconnect attempts (in ms) |
| useExponentialBackOff | true | Should an exponential backoff be used between reconnect attempts |
| backOffMultiplier | 2 | The exponent used in the exponential backoff attempts |
| maxReconnectAttempts | 0 | If not 0, then this is the maximum number of reconnect attempts before an error is sent back to the client |
| randomize | true | use a random algorithm to choose the URI to use for reconnect from the list provided |
| backup | false | initialize and hold a second transport connection - to enable fast failover |
例如:failover:(tcp://localhost:61616,tcp://remotehost:61616)?initialReconnectDelay=100
2.2.4 Discovery transport
Discovery transport是可靠的tranport。它使用Discovery transport来定位用来连接的URI列表。以下是配置语法:
discovery:(discoveryAgentURI)?transportOptions
discovery:discoveryAgentURI
Transport Options的可选值如下:
| Option Name | Default Value | Description |
| initialReconnectDelay | 10 | How long to wait before the first reconnect attempt |
| maxReconnectDelay | 30000 | The maximum amount of time we ever wait between reconnect attempts |
| useExponentialBackOff | true | Should an exponential backoff be used btween reconnect attempts |
| backOffMultiplier | 2 | The exponent used in the exponential backoff attempts |
| maxReconnectAttempts | 0 | If not 0, then this is the maximum number of reconnect attempts before an error is sent back to the client |
例如:discovery:(multicast://default)?initialReconnectDelay=100
为了使用Discovery来发现broker,需要为broker启用discovery agent。 以下是XML配置文件中的一个例子:
- <broker name="foo">
- <transportConnectors>
- <transportConnector uri="tcp://localhost:0" discoveryUri="multicast://default"/>
- </transportConnectors>
- ...
- </broker>
在transport重连的时候,可以在connection上注册TransportListener来获得回调,例如:
- (ActiveMQConnection)connection).addTransportListener(new TransportListener() {
- public void onCommand(Object cmd) {
- }
- public void onException(IOException exp) {
- }
- public void transportInterupted() {
- // The transport has suffered an interruption from which it hopes to recover.
- }
- public void transportResumed() {
- // The transport has resumed after an interruption.
- }
- });
ActiveMQ in Action(2) - Transport的更多相关文章
- 《ActiveMQ in Action》【PDF】下载
内容介绍TheApache ActiveMQ message broker is an open source implementation ofthe Java Message Service sp ...
- ActiveMQ in Action(6) - Features
关键字: activemq 2.6 Features ActiveMQ包含了很多功能强大的特性,下面简要介绍其中的几个.2.6.1 Exclusive Consumer Queue中的消息 ...
- ActiveMQ in Action(5) - Clustering
关键字: activemq 2.5 Clustering ActiveMQ从多种不同的方面提供了集群的支持.2.5.1 Queue consumer clusters ActiveMQ支持 ...
- ActiveMQ in Action(1) - JMS
关键字: activemq 1 JMS 在介绍ActiveMQ之前,首先简要介绍一下JMS规范.1.1 JMS的基本构件1.1.1 连接工厂 连接工厂是客户用来创建连接的对象,例如Acti ...
- ActiveMQ in Action(7) - Wildcards
关键字: activemq 2.6.7 Wildcards Wildcards用来支持联合的名字分层体系(federated name hierarchies).它不是JMS规范的一部分,而是A ...
- ActiveMQ in Action(3) - Persistence
关键字: activemq 2.3 Persistence2.3.1 AMQ Message Store AMQ Message Store是ActiveMQ5.0缺省的持久化存储.Messag ...
- ActiveMQ in Action(4) - Security
关键字: activemq 2.4 Security ActiveMQ支持可插拔的安全机制,用以在不同的provider之间切换.2.4.1 Simple Authentication Plug ...
- 《ActiveMQ in Action》例子
本章内容: 介绍本书中所有例子的使用场景 使用 Maven 编译.运行例子 例子中怎么使用 ActiveMQ 简介 ActiveMQ 不仅实现了 JMS 规范中定义的所有特性,也额外提供了一些特有且有 ...
- (错误)启动ActiveMQ报错:Transport Connector could not be registered in JMX: java.io.IOException: Failed to bind to server socket: stomp://0.0.0.0:61613?
一.错误报告 很明显,端口被占用 二.解决方法 1. 在cmd中输入 netstat -ano 查看61613端口被占用情况,如果有其他进程使用,则使用 taskkill /f /pid 进程PID ...
随机推荐
- python项目练习地址
作者:Wayne Shi链接:http://www.zhihu.com/question/29372574/answer/88744491来源:知乎著作权归作者所有,转载请联系作者获得授权. 目前是3 ...
- CodeForces 706D Vasiliy's Multiset
字典树. 比较经典的题目了.把每一个数字都插入到字典树中,询问的时候如果$x$的第$i$位是$p$,那么尝试着在字典树上往$pXOR1$的节点走下去,没有$pXOR1$节点的话再走$p$的.删除操作的 ...
- PAT乙级1004. 成绩排名 (20)
读入n名学生的姓名.学号.成绩,分别输出成绩最高和成绩最低学生的姓名和学号. 输入格式:每个测试输入包含1个测试用例,格式为 第1行:正整数n 第2行:第1个学生的姓名 学号 成绩 第3行:第2个学生 ...
- 【NOIP2011提高组】选择客栈
题目不附了,是一个单纯的ST模型,但是考验各种常数优化. 最大的优化是对于同颜色的客栈来说,如果1号和2号成功配对了,那么1和3,1和4都可以成功配对,那么只要找到一对成功配对的,我们就直接加上剩下的 ...
- hdu 3669 Cross the Wall(斜率优化DP)
题目连接:hdu 3669 Cross the Wall 题意: 现在有一面无限大的墙,现在有n个人,每个人都能看成一个矩形,宽是w,高是h,现在这n个人要通过这面墙,现在只能让你挖k个洞,每个洞不能 ...
- ios GCD的使用及封装
实现代码: CGDHelper /* * Grand Central Dispatch (GCD)是Apple开发的一个多核编程的解决方法. * 系统要求:iOS4.0以上. */ #import & ...
- VC6.0 通过崩溃地址中找到异常代码行
来源:http://blog.csdn.net/mydeardingxiaoli/article/details/20371585 这是从“VC编程经验总结7”中转出来的借花献佛——如何通过崩溃地址找 ...
- 自动化辅助工具Firebug和Firepath的安装
1.安装firefox浏览器,点击主菜单,选择“附加组件” 2.搜索Firebug和firepath点击安装 3.安装后点击浏览器的主菜单-web开发者-firebug即可打开 4.或者在页面右键选择 ...
- Qt实现悬浮窗效果
当鼠标移动到头像控件时,显示悬浮窗,当鼠标离开时,悬浮窗隐藏. 1.控件选择 悬浮窗可以从QDialog派生,并将窗口的属性设置为无边框 this->setWindowFlags(this- ...
- php专业面试总结
PHP专业面试题汇总 一.PHP基础: 2 二.数据库部分 5 三.面向对象部分 9 四.ThinkPHP部分 12 五.smarty模板引擎 16 六.二次开发系统(DEDE.ecshop): 18 ...