虛擬機傳輸容許客戶端在虛擬機內部進行通訊,這種方式就不須要額外搭建網絡通訊了。虛擬機傳輸的鏈接方式使用的並不是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