LibraryToggle FramesPrintFeedback

VM Transport

The VM transport allows clients to connect to each other inside the Java Virtual Machine (JVM) without the overhead of network communication.

Overview

The VM transport enables Java clients running inside the same JVM to communicate with each other inside the JVM, without having to resort to a using a network connection. Because the clients require a broker to communicate, the VM transport can implicitly create an embedded broker the first time it is accessed. Figure 7 shows the basic architecture of the VM protocol.

Figure 7. Clients Connected through the VM Transport

three clients connected to an embedded broker

The URI used to specify the VM transport comes in two flavors to provide maximum control over how the embedded broker is configured:

  • simple—specifies the name of the embedded broker to which the client connects and allows for some basic broker configuration

  • advanced—uses a broker URI to configure the embedded broker

Embedded brokers

The VM transport uses a broker embedded in the same JVM as the clients to facilitate communication between the clients. The embedded broker can be created in several ways:

  • explicitly defining the broker in the application's configuration

  • explicitly creating the broker using the Java APIs

  • automatically when the first client attempts to connect to it using the VM transport

The VM transport uses the broker name specified in either the simple URI or in the configuration provided by the advanced URI's broker URI to determine if an embedded broker needs to be created. When a client uses the VM transport to connect to a broker, the transport checks to see if an embedded broker by that name already exists. If it does exist, the client is connected to the broker. If it does not exist, the broker is created and then the broker is connected to it.

When using explicitly created brokers there is a danger that your clients will attempt to connect to the embedded broker before it is started. If this happens, the VM transport will auto-create an instance of the broker for you. To avoid this conflict you can set the waitForStart option or the create=false option to manage how the VM transport determines when to create a new embedded broker.

Simple URI syntax

The simple VM URI is used in most situations. It allows you to specify the name of the embedded broker to which the client will connect. It also allows for some basic broker configuration.

Example 3 shows the syntax for a simple VM URI.

Example 3. Simple VM URI Syntax

vm://BrokerName?TransportOptions

  • BrokerName specifies the name of the embedded broker to which the client connects.

  • TransportOptions specifies the configuration for the transport. They are specified in the form of a query list. Table 13 lists the available options.

In addition to the transport options listed in Table 13, the simple VM URI can use the options described in Table 12 to configure the embedded broker.

Table 12. VM Transport Broker Configuration Options

OptionDescription
broker.* Properties prefixed by broker. configure the embedded broker. You can specify any of the standard broker options described in Table 14.
brokerConfig Specifies an external broker configuration file. For example, to pick up the broker configuration file, activemq.xml, you would set brokerConfig as follows: brokerConfig=xbean:activemq.xml.

[Important]Important

The broker configuration options specified on the VM URI are only meaningful if the client is responsible for instantiating the embedded broker. If the embedded broker is already started, the transport will ignore the broker configuration properties.

Example 4 shows a basic VM URI that connects to an embedded broker named broker1.

Example 4. Basic VM URI

vm://broker1

Example 5 creates and connects to an embedded broker that uses a non-persistent message store.

Example 5. Simple URI with broker options

vm://broker1?broker.persistent=false

Advanced URI syntax

The advanced VM URI provides you full control over how the embedded broker is configured. It uses a broker configuration URI similar to the one used by the administration tool to configure the embedded broker.

Example 6 shows the syntax for an advanced VM URI.

Example 6. Advanced VM URI Syntax

vm://(BrokerConfigURI)?TransportOptions

  • BrokerConfigURI is a broker configuration URI.

  • TransportOptions specifies the configuration for the transport. They are specified in the form of a query list. Table 13 lists the available options.

Example 7 creates and connects to an embedded broker configured using a broker configuration URI.

Example 7. Advanced VM URI

vm:(broker:(tcp://localhost:6000)?persistent=false)?marshal=false

Transport options

Table 13 shows options for configuring the VM transport.

Table 13. VM Transport Options

OptionDescription
marshal If true, forces each command sent over the transport to be marshalled and unmarshalled using the specified wire format. Default is false.
wireFormatThe name of the wire format to use.
wireFormat.*Properties prefixed by wireFormat. configure the specified wire format.
createSpecifies if the VM transport will create an embedded broker if one does not exist. The default is true.
waitForStart Specifies the time, in milliseconds, the VM transport will wait for an embedded broker to start before creating one. The default is -1 which specifies that the transport will not wait.

Broker options

Table 14 shows the options used to configure the broker using the simple VM URI.

Table 14. Broker Options

OptionDescription
useJmxSpecifies if JMX is enabled. Default is true.
persistentSpecifies if the broker uses persistent storage. Default is true.
populateJMSXUserIDSpecifies if the broker populates the JMSXUserID message property with the sender’s authenticated username. Default is false.
useShutdownHook Specifies if the broker installs a shutdown hook, so that it can shut down properly when it receives a JVM kill. Default is true.
brokerNameSpecifies the broker name. Default is localhost.
deleteAllMessagesOnStartupSpecifies if all the messages in the persistent store are deleted when the broker starts up. Default is false.
enableStatisticsSpecifies if statistics gathering is enabled in the broker. Default is true.

Comments powered by Disqus