- 浏览: 478324 次
- 性别:
- 来自: 大连
文章分类
最新评论
-
龘龘龘:
TrueBrian 写道有个问题,Sample 1中,为了控制 ...
What's New on Java 7 Phaser -
龘龘龘:
楼主总结的不错。
What's New on Java 7 Phaser -
TrueBrian:
有个问题,Sample 1中,为了控制线程的启动时机,博主实际 ...
What's New on Java 7 Phaser -
liguanqun811:
不知道楼主是否对zookeeper实现的分布式锁进行过性能测试 ...
Distributed Lock -
hobitton:
mysql的get lock有版本限制,否则get lock可 ...
Distributed Lock
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>
如果persistent是true,那么ActiveMQ会在当前目录下创建一个缺省值是activemq-data的目录用于持久化保存数据。需要注意的是,如果程序中启动了多个不同名字的VM broker,那么可能会有如下警告:Failed to start jmx connector: Cannot bind to URL [rmi://localhost:1099/jmxrmi]: javax.naming.NameAlreadyBoundException…可以通过在transportOptions中追加broker.useJmx=false来禁用JMX来避免这个警告。
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 | D efault 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>
在使用Failover Transport或Discovery transport等能够自动重连的transport的时候,需要注意的是:设想有两个broker,它们都启用AMQ Message Store作为持久化存储,有一个producer和一个consumer连接到某个queue。当因其中一个broker失效时而切换到另一个broker的时候,如果失效的broker的queue中还有未被consumer消费的消息,那么这个queue里的消息仍然滞留在失效broker的中,直到失效的broker被修复并重新切换回这个被修复的broker后,之前被保留的消息才会被consumer消费掉。如果被处理的消息有时序限制,那么应用程序就需要处理这个问题。另外也可以通过ActiveMQ集群来解决这个问题。
在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. } });
发表评论
-
Terracotta in Action (3)
2009-03-25 09:20 50793 Inside Terracotta 3.1 Core T ... -
Terracotta in Action (2)
2009-03-21 21:09 46072. Terracotta Eclipse Plugin ... -
Terracotta in Action (1)
2009-03-19 21:52 62291. Introduction Terraco ... -
OpenEJB (4)
2008-05-11 09:05 3133本文部分内容节选自Enterprise JavaBeans 3 ... -
OpenEJB (3)
2008-05-11 09:04 2686本文部分内容节选自Enterprise JavaBeans 3 ... -
OpenEJB (2)
2008-05-11 09:03 3277本文部分内容节选自Enterprise JavaBeans 3 ... -
OpenEJB (1)
2008-05-10 22:39 5066本文部分内容节选自Enterprise JavaBeans 3 ... -
OpenJPA (7)
2008-03-25 21:56 351310 Miscellaneous Features 10 ... -
OpenJPA (6)
2008-03-23 21:33 62498 Object Locking 8.1 Configu ... -
OpenJPA (5)
2008-03-18 22:38 49577 Inheritance 对象使用引用以便关联到其 ... -
OpenJPA (4)
2008-03-11 23:27 70366 Query 6.1 JPQL Queries 6.1. ... -
OpenJPA (3)
2008-03-09 23:09 51924 EntityManagerFactory 4.1 Ove ... -
OpenJPA (2)
2008-03-05 23:59 72473 Metadata 通过javax.persist ... -
OpenJPA (1)
2008-03-04 23:11 68271 Overview Apache OpenJPA是 ... -
ActiveMQ in Action (7)
2008-02-27 14:33 126262.6.7 Wildcards Wil ... -
ActiveMQ in Action (6)
2008-02-26 15:22 137242.6 Features ActiveMQ包含了很多 ... -
ActiveMQ in Action (5)
2008-02-26 00:35 135252.5 Clustering ActiveMQ从多种 ... -
ActiveMQ in Action (4)
2008-02-26 00:21 112042.4 Security ActiveMQ ... -
ActiveMQ in Action (3)
2008-02-26 00:16 105852.3 Persistence 2.3.1 AMQ Mess ... -
ActiveMQ in Action (1)
2008-02-25 23:18 237791 JMS 在介绍ActiveMQ ...
相关推荐
ActiveMQ In Action及其源码 本来想免费提供下载的,但是发现csdn不能选择0积分下载,坑的很
ActiveMQ in Action pdf英文原版加源代码压缩包。 Apache ActiveMQ in Action is a thorough, practical guide to implementing message-oriented systems in Java using ActiveMQ. The book lays out the core of ...
ActiveMQ in Action的开发文档
这是最新版的《ActiveMQ in Action》包括第7、9、11、13等章节
activeMq in action 使用activeMq开发JMS的简单讲述,activeMq in action 使用activeMq开发JMS的简单讲述
ActiveMQ in Action 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
ActiveMQ In Action翻译笔记-更新版2011
activemq in action PDF 英文版 源代码 合二为一,目前好像只有英文版,源代码一起发布的少。我收集到了,分享给大家。 这本书讲得真是不错,英文看起来也不难,希望对你有帮助 。
ActiveMQ In Action的精简版
ActiveMQ 不仅实现了 JMS 规范中定义的所有特性,也额外提供了一些特有且有用的特性。我们会在 3.1 小节详细列说这些特性,并且书中剩余的章节还会继续讨论这些特性。为了演示这些特性,我们创建了两个基于实际业务...
ActiveMQ_in_Action_中文ActiveMQ_in_Action_中文ActiveMQ_in_Action_中文ActiveMQ_in_Action_中文
ActiveMQ in Action
经典的学习ActiveMQ的书籍。这本书讲得真是不错,英文看起来也不难,希望对你有帮助 。
ActiveMQ In Action.zip
ActiveMQ_in_Action.pdf 教程文档
activemq in action - activemq in action
ActiveMQ_in_Action_中文.zip
ActiveMQ+In+Action翻译笔记-+更新版2011.pdf
ActionMQ In Action 就是网上可以下载的那个版本, 不知道作者是谁,和英文版的书应该不是一回事。在原版的基础上增加了书签,可以看的更方便。这本书对ActiveMQ入门到一般的管理非常有帮助。