虚拟机传输容许客户端在虚拟机内部进行通讯,这种方式就不须要额外搭建网络通讯了。虚拟机传输的链接方式使用的并不是socket链接,而是直接链接,这种链接由于是内部的消息通讯而带来较高的性能。html
第一个客户端链接虚拟机时将会启动内嵌的broker。以后的链接继续使用这一相同的broker。一旦链接到broker的链接都关闭,那么对应的内嵌broker将自动关闭。apache
简单的broker配置演示:网络
如下为配置虚拟机链接的语法,配置简单但只能建立少许的broker。socket
vm://brokerName?transportOptionstcp
若是你想链接一个已经实例化的内嵌broker(好比在Apache ServiceMix中)性能
请确保你的 vm://brokerName 配置中的 brokerName 与正在运行的broker一致.this
配置项说明url
Option Namespa |
Default Valueorm |
Description |
marshal |
false |
若是为true , 每一个传输都需被管理. |
wireFormat |
default |
The name of the WireFormat to use |
wireFormat.* |
|
全部的前缀配置都将用于wireFormat的配置 |
create |
true |
If the broker should be created on demand if it does not already exist. |
waitForStart |
-1 |
如1>0 将根据须要自行建立broker |
broker.* |
|
All the properties with this prefix are used to configure the broker. See Configuring Wire Formats for more information |
Example URI
vm://broker1?marshal=false&broker.persistent=false
内嵌broker的注意事项 若是你使用虚拟机传输并但愿更明白的配置内嵌broker。你能够在borker启动以前,建立一个JMS链接。若是你使用虚拟机传输并没配置的话,ActiveMQ会自动建立一个broker。 如使用Spring,你或许但愿能经过depends-on之类的属性配置。这样就能在JMS工厂类就能与内嵌broker一同使用,参考配置以下: <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>
|
Broker的高级配置
这是虚拟机链接的进阶配置。你能够经过broker配置url的方式进行配置,如:
vm:(broker:(tcp://localhost)?brokerOptions)?transportOptions
or
vm:broker:(tcp://localhost)?brokerOptions
配置项说明
Option Name |
Default Value |
Description |
marshal |
false |
If true, forces each command sent over the transport to be marshalled and unmarshalled 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:(broker:(tcp://localhost:6000)?persistent=false)?marshal=false
经过外部文件来配置举例:
vm://localhost?brokerConfig=xbean:activemq.xml