Fuse ESB

Broker Client Connectivity Guide

Version 4.4.1

Sept. 2011
Trademark Disclaimer
Third Party Acknowledgements

Table of Contents

1. Protocol Summary
Simple Connections
Discovery Protocols
2. OpenWire Protocol
Introduction to the OpenWire Protocol
OpenWire Example
3. Stomp Protocol
Introduction to the Stomp Protocol
Protocol Details
Stomp Tutorial
Stomp Example
4. REST Protocols
Introduction to the REST Protocol
Protocol Details
REST Example
5. VM Transport
6. Failover Protocol
Static Failover
Dynamic Failover
7. Discovery Protocols
Dynamic Discovery Protocol
Discovery Agents
A. Transport Options
TCP and NIO Transports
SSL Transport
UDP Transport
Wire Format Options
Index

List of Figures

3.1. Connecting to the ActiveMQ JMX Port
3.2. Monitoring the Status of the FOO.BAR Queue
4.1. Welcome Page for Web Examples
4.2. The Send a JMS Message Form
4.3. Default Option to Browse a Queue
4.4. Option to Browse a Queue as XML
4.5. Option to Browse a Queue as Atom
4.6. Option to Browse a Queue as RSS 1.0
5.1. Clients Connected through the VM Transport

List of Tables

1.1. Protocols for Simple Connections
1.2. Summary of Discovery Protocols
2.1. Transport Protocols Supported by OpenWire
2.2. Transport Options Supported by OpenWire Protocol
3.1. Transport Protocols Supported by Stomp
3.2. Client Commands for the Stomp Protocol
3.3. Server Commands for the Stomp Protocol
4.1. HTTP RESTful Operations
4.2. URL Options Recognized by the Message Servlet
4.3. Message Servlet RESTful HTTP Operations
4.4. URL Options Recognized by the QueueBrowse Servlet
4.5. Form Properties Recognized by Message Servlet
5.1. VM Transport Broker Configuration Options
5.2. VM Transport Options
5.3. Broker Options
6.1. Failover Transport Options
6.2. Broker-side Failover Properties
7.1. Discovery Transport Options
A.1. TCP and NIO Transport Options
A.2. SSL Transport Options
A.3. SSL Transport Options
A.4. Transport Options Supported by OpenWire Protocol

List of Examples

4.1. Web Form for Sending a Message to a Queue or Topic
4.2. Configuration of an Embedded Servlet Engine
5.1. Simple VM URI Syntax
5.2. Basic VM URI
5.3. Simple URI with broker options
5.4. Advanced VM URI Syntax
5.5. Advanced VM URI
6.1. Simple Failover URI
6.2. Broker for Dynamic Failover
6.3. Failover URI for Connecting to a Failover Cluster

Table 1.1 shows the protocol combinations that messaging clients can use to connect directly to the message broker.

Table 1.1. Protocols for Simple Connections

Wire ProtocolTransport ProtocolSample URLDescription
OpenWireTCPtcp://Host:Port

Connect to the message broker endpoint at Host:Port using the OpenWire over TCP protocol.

This URL is also used to configure the transport connector in a broker.

OpenWireTCPnio://Host:PortSame as tcp, except that the New I/O (NIO) Java API is used, which provides better performance in some scenarios.
OpenWireSSLssl://Host:Port

Connect to the message broker endpoint at Host:Port using the OpenWire over SSL protocol.

This URL is also used to configure the transport connector in a broker.

OpenWireHTTPhttp://Host:Port

Connect to the message broker endpoint at Host:Port using the OpenWire over HTTP protocol (HTTP tunneling). You can use this protocol to navigate through firewalls.

This URL is also used to configure the transport connector in a broker.

OpenWireHTTPShttps://Host:Port

Connect to the message broker endpoint at Host:Port using the OpenWire over HTTPS protocol

This URL is also used to configure the transport connector in a broker.

StompTCPstomp://Host:Port

Connect to the message broker endpoint at Host:Port using the Stomp over TCP protocol.

This URL is also used to configure the transport connector in a broker.

StompSSLstomp+ssl://Host:Port

Connect to the message broker endpoint at Host:Port using the Stomp over SSL protocol.

This URL is also used to configure the transport connector in a broker.

RESTHTTPhttp://Host:Port/ demo/message/FOO/BAR ?timeout=10000 &type=queue

Connect to the message broker endpoint at Host:Port using the REST protocol. The REST endpoint is implemented as a servlet deployed in a servlet engine.

For example, the sample URL is built up from a Web context name, demo, followed by the servlet name, message, followed by a destination name, FOO/BAR, and some query options.

This URL is not used to configure the REST transport connector in a broker. Use the <jetty> tag to configure the REST endpoint in the broker.

RESTsHTTPShttp://Host:Port/ demo/message/FOO/BAR ?timeout=10000 &type=queue 
XMPPTCPxmpp://Host:PortConfigure the transport connector in a message broker to accept XMPP connections on Host:Port (for example, from an Instant Messaging client).
VMN/Avm://BrokerNameConfigure clients to connect to a broker embedded within the same Java Virtual Machine (JVM). The BrokerName is the broker name of the embedded broker.

The discovery protocol supports a number of discovery agents, which are also specified in the form of a URI. For details of the supported discovery agents, see Discovery Agents .

Note

Although discovery agent URIs look superficially like transport URIs, they are not the same thing. A discovery agent URI can only be used in certain contexts and cannot be used directly in place of a transport URI.

OpenWire supports a number of transport options, which can be set as query options on the transport URL. For example, to specify that error messages should omit the stack trace, use a URL like the following:

tcp://localhost:61616?wireformat.stackTraceEnabled=false

Where the wireformat.stackTraceEnabled property is set to false to disable the inclusion of stack traces in error messages. Table 2.2 gives the complete list of transport options for OpenWire.


To run these examples, you require:

  • Apache Ant build tool, version 1.6 or later.

  • Standalone Fuse Message Broker package, available from fusesource.com. It is assumed that you install this package to the directory, ActiveMQInstallDir.

For full details of how to deploy a broker in the OSGi container, please read Deploying a JMS Broker in Deploying into the OSGi Container. If you have not already deployed a broker, you can create and deploy a new broker, broker1, by entering the following console command:

karaf@root> activemq:create-broker --name broker1

Add a HTTP transport connector by editing the broker configuration file (in InstallDir/deploy/broker1-broker.xml) as follows:

<beans>
  ...
  <transportConnectors>
    ...
    <transportConnector name="openwire" uri="tcp://localhost:61616"/>
    <transportConnector name="http"   uri="http://localhost:61620"/>
  </transportConnectors>
  ...
</beans>

The SUBSCRIBE command registers a client’s interest in listening to a specific destination. Like the SEND command, the SUBSCRIBE command requires a destination header. Henceforth, any messages received on the subscription are delivered as MESSAGE frames, from the server to the client. For example, the following frame shows a client subscribing to the destination, /queue/a:

SUBSCRIBE
destination: /queue/foo
ack: client
 
^@

In this case the ack header is set to client, which means that messages are considered delivered only after the client specifically acknowledges them with an ACK frame. The body of the SUBSCRIBE command is ignored.

The SUBSCRIBE command supports the following optional headers:

For full details of how to deploy a broker in the OSGi container, please read Deploying a JMS Broker in Deploying into the OSGi Container. If you have not already deployed a broker, you can create and deploy a new broker, broker1, by entering the following console command:

karaf@root> activemq:create-broker --name broker1

Normally, the default broker is configured to initialize a Stomp connector that listens on port, 61613. Look for a line like the following in the broker’s log:

INFO  TransportServerThreadSupport   - Listening for connections at:
stomp://localhost:61613

If the Stomp connector is not present in the broker, you will have to configure it—see Configure the broker for details.

You must download and install the requisite packages to support the Ruby programming language before you can run the Stomp example. Install the following packages:

If you have not already done so, you also need to download and install the standalone Fuse Message Broker package from fusesource.com.

For full details of how to deploy a broker in the OSGi container, please read Deploying a JMS Broker in Deploying into the OSGi Container. If you have not already deployed a broker, you can create and deploy a new broker, broker1, by entering the following console command:

karaf@root> activemq:create-broker --name broker1

Check that the the Stomp connector is present in the broker configuration file (in InstallDir/deploy/broker1-broker.xml) as follows:

<beans>
  ...
  <transportConnectors>
    ...
    <transportConnector name="stomp"   uri="stomp://localhost:61613"/>
  </transportConnectors>
  ...
</beans>

Representational State Transfer (REST) is a software architecture designed for distributed systems, like the World Wide Web. For details of the REST architecture and the philosophy underlying it, see the REST Wikipedia article.

One of the key concepts of a RESTful architecture is that the interaction between different network nodes should take on a very simple form. In particular, the number of operations in a RESTful protocol must be kept small: for example, the REST protocol in Fuse requires just three operations.

The RESTful Web service implemented by the Fuse message servlet enables you to enqueue and dequeue messages over HTTP. You can, therefore, use the message servlet to implement message producers and message consumers as Web forms.

To interact with the Fuse message servlet, construct a URL of the following form:

http://Host:Port/WebContext/message/DestinationPath?Opt1=Val1&Opt2=Val2...

Where the URL is constructed from the following parts:

For example, the following URL can be used to fetch a message from the FOO.BAR queue, where the Web console has the default configuration:

http://localhost:8161/demo/message/FOO/BAR?type=queue&timeout=5000

Table 4.2 shows the URL options recognized by the message servlet:


Three HTTP operations—GET, POST, and DELETE—are recognized by the message servlet. The semantics of these operations are described briefly in Table 4.3 .


For details of the form properties recognized by the message servlet (for POSTing a message), see Example of posting a message .

The RESTful Web service implemented by the queueBrowse servlet enables you to monitor the contents and status of any queue or topic in the Web console. Effectively, the queueBrowse servlet is a simple management tool.

To interact with the Fuse queueBrowse servlet, construct a URL of the following form:

http://Host:Port/WebContext/queueBrowse/DestinationPath?Opt1=Val1&Opt2=Val2...

The queueBrowse URL has a similar structure to the message URL (see message servlet ), except that the queueBrowse URL is built from WebContext/queueBrowse instead of WebContext/message.

For example, the following URL can be used to browse the FOO.BAR queue, where the Web console has the default configuration:

http://localhost:8161/demo/queueBrowse/FOO/BAR

Table 4.4 shows the URL options recognized by the queueBrowse servlet:


Example 4.1 shows an example of the Web form used to send a message to the FOO.BAR queue in the Web console, as demonstrated in Send a message .


Table 4.5 describes the form properties that are recognized by the message servlet.


To consume a message from a topic or queue, send a HTTP GET operation (for example, by following a hypertext link) using the URL format described in message servlet . For example, to consume a message from the FOO.BAR queue, navigate to the following URL:

http://localhost:8161/demo/message/FOO/BAR?timeout=10000&type=queue

To browse a queue using the queueBrowse servlet, simply navigate to an URL of the appropriate form, as described in queueBrowse servlet .

For example, to browse the FOO.BAR queue in XML format:

http://localhost:8161/demo/queueBrowse/FOO/BAR?view=xml

To browse the FOO.BAR queue as an Atom 1.0 feed:

http://localhost:8161/demo/queueBrowse/FOO/BAR?view=rss&feedType=atom_1.0

To browse the FOO.BAR queue as an RSS 1.0 feed:

http://localhost:8161/demo/queueBrowse/FOO/BAR?view=rss&feedType=rss_1.0

To receive a message from the FOO.BAR queue, open the example welcome page in your browser, http://localhost:8161/demo, and click the link, Receive a message.

You should now see the text of the message that you sent earlier. You will probably also receive an error from your browser, if the message is not formatted as HTML or XML (which the browser expects).

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 5.1 shows the syntax for a simple VM URI.


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


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 5.2 shows a basic VM URI that connects to an embedded broker named broker1.


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


The advance 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 5.4 shows the syntax for a simple VM URI.


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


The failover protocol facilitates quick recovery from network failures. When a recoverable network error occurs the protocol catches the error and automatically attempts to reestablish the JMS connection to an alternate broker endpoint without the need to recreate all of the JMS objects associated with the JMS connection. The failover URI is composed of one or more URIs that represent different broker endpoints. By default, the protocol randomly chooses a URI from the list and attempts to establish a network connection to it. If it does not succeed, or if it subsequently fails, a new network connection is established to one of the other URIs in the list.

For true high-availability and failover capabilities, you will need to set up your brokers in a network of brokers or a master/slave cluster. See Clustering Guide.

The failover transport allows you to set up failover in one of two ways:

  • Static—the client is configured with a static list of available URIs

  • Dynamic—the brokers push information about the available broker connections

The failover protocol supports the transport options described in Table 6.1.

Table 6.1. Failover Transport Options

OptionDefaultDescription
initialReconnectDelay 10Specifies the number of milliseconds to wait before the first reconnect attempt.
maxReconnectDelay 30000Specifies the maximum amount of time, in milliseconds, to wait between reconnect attempts.
useExponentialBackOff trueSpecifies whether to use an exponential back-off between reconnect attempts.
backOffMultiplier 2Specifies the exponent used in the exponential back-off algorithm.
maxReconnectAttempts -1Specifies the maximum number of reconnect attempts before an error is returned to the client. -1 specifies unlimited attempts. 0 specifies that an initial connection attempt is made at start-up, but no attempts to failover over to a secondary broker will be made.
startupMaxReconnectAttempts 0Specifies the maximum number of reconnect attempts before an error is returned to the client on the first attempt by the client to start a connection. 0 specifies unlimited attempts.
randomize trueSpecifies if a URI is chosen at random from the list. Otherwise, the list is traversed from left to right.
backup falseSpecifies if the protocol initializes and holds a second transport connection to enable fast failover.
timeout -1Specifies the amount of time, in milliseconds, to wait before sending an error if a new connection is not established. -1 specifies an infinite timeout value.
trackMessages falseSpecifies if the protocol keeps a cache of in-flight messages that are flushed to a broker on reconnect.
maxCacheSize 131072Specifies the size, in bytes, used for the cache used to track messages.
updateURIsSupported trueSpecifies whether the client accepts updates to its list of known URIs from the connected broker. Setting this to false inhibits the client's ability to use dynamic failover. See Dynamic Failover.

Example 6.2 shows the configuration for a broker that participates in dynamic failover.

Example 6.2. Broker for Dynamic Failover

<beans ... >
  <broker>
    ...
    <networkConnectors>
1      <networkConnector uri="multicast://default" />
    </networkConnectors>
    ...
    <transportConnectors>
      <transportConnector name="openwire"
          uri="tcp://0.0.0.0:61616"
2         discoveryUri="multicast://default"
3         updateClusterClients="true"
4         updateClusterFilter="*A*,*B*" />  
    </transportConnectors>
    ...
  </broker>
</beans>

The configuration in Example 6.2 does the following:

1

Creates a network connector that connects to any discoverable broker that uses the multicast transport.

2

Makes the broker discoverable by other brokers over the multicast protocol.

3

Makes the broker update the list of available brokers for clients that connect using the failover protocol.

Note

Clients will only be updated when new brokers join the cluster, not when a broker leaves the cluster.

4

Creates a filter so that only those brokers whose names start with the letter A or the letter B are considered to belong to the failover cluster.

Example 6.3 shows the URI for a client that uses the failover protocol to connect to the broker and its cluster.


A discovery URI must conform to the following syntax:

discovery://(DiscoveryAgentUri)?TransportOptions

Where the discovery agent URI, DiscoveryAgentUri, identifies a discovery agent, as described in Discovery agents above. The transport options, ?TransportOptions, are specified in the form of a query list (where the supported options are described in Table 7.1 ). If no transport options are required, you can use the following alternative syntax:

discovery://DiscoveryAgentUri

The list of transport options, TransportOptions, in the discovery URI can also be used to set options on the discovered transports. If you set an option not listed in Table 7.1, the URI parser attempts to inject the option setting into every one of the discovered endpoints.

For example, if you set the TCP connectionTimeout option to 10 seconds, as follows:

discovery://(multicast://default)?connectionTimeout=10000

The 10 second timeout setting is injected into every discovered TCP endpoint.

The zeroconf discovery agent is derived from Apple’s Bonjour Networking technology, which defines the zeroconf protocol as a mechanism for discovering services on a network. Fuse Message Broker bases its implementation of the zeroconf discovery agent on JmDSN, which is a service discovery protocol that is layered over IP/multicast and is compatible with Apple Bonjour. To enable the protocol, a multicast discovery agent must be configured on each broker you want to advertise and messaging clients must be configured to use a discovery URI.

The URI for a zeroconf discovery agent must conform to the following syntax:

zeroconf://GroupID

Where the GroupID is an alphanumeric identifier. All participants in the same discovery network must use the same GroupID.

For example, to use a zeroconf discovery agent on the client side, where the client needs to connect to the groupA group, you would construct a discovery URL like the following:

discovery://(zeroconf://groupA)

Note

Your local network (LAN) must be configured appropriately for the IP/multicast protocol to work. If your clients fail to discover a broker using the zeroconf protocol, this could be because IP/multicast is not set up on your network.

The TCP transport is used for creating OpenWire/TCP endpoints. The NIO transport is similar to the TCP transport, except that it uses the Java New I/O (NIO) socket library, which can provide better scalability when used on the server side. TCP and NIO have the same transport options.

When setting a client-side option, the name of the options is exactly as given in Table A.1. For example, to enable tracing on a client TCP endpoint, set the trace option as follows:

tcp://fusesource.com:61616?trace=true

When setting a server-side option, there are two alternative option syntaxes as follows:

TCP listener socket options

To configure options on the TCP listener socket, add the transport. prefix to the option names shown in Table A.1. For example, to enable tracing on a TCP listener socket, set the trace option as follows:

tcp://fusesource.com:61616?transport.trace=true
TCP connection socket options

To configure options on a TCP connection socket (which is spawned from the listener socket whenever the server accepts a new TCP connection), use the option name exactly as given in Table A.1. For example, to enable tracing on a TCP connection socket, set the trace option as follows:

tcp://fusesource.com:61616?trace=true

Table A.1 shows the options supported by the TCP and the NIO URIs.

Table A.1. TCP and NIO Transport Options

OptionDefaultDescription
minmumWireFormatVersion0The minimum wire format version that is allowed.
tracefalseCauses all commands sent over the transport to be logged.
daemonfalseSpecifies whether the transport thread runs as a daemon or not. Useful to enable when embedding in a Spring container or in a web container, to allow the container to shut down properly.
useLocalHosttrueWhen true, causes the local machine's name to resolve to localhost.
socketBufferSize64*1024Sets the socket buffer size in bytes.
keepAlivefalseWhen true, enables TCP KeepAlive on the broker connection. Useful to ensure that inactive consumers do not time out.
soTimeout0Sets the socket timeout in milliseconds
connectionTimeout30000A 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.
closeAsynctrueThe false value causes all sockets to be closed synchronously.
soLingerMIN_INTEGERWhen > -1, enables the SoLinger socket option with this value. When equal to -1, disables SoLinger. (from 5.6.0).
maximumConnectionsMAX_VALUEThe maximum number of sockets the broker is allowed to create.
diffServ0(Client only) The preferred Differentiated Services traffic class to be set on outgoing packets, as described in RFC 2475. Valid integer values are [0,64). Valid string values are EF, AF[1-3][1-4] or CS[0-7]. With JDK 6, only works when the Java Runtime uses the IPv4 stack, which can be done by setting the java.net.preferIPv4Stack system property to true. Cannot be used at the same time as the typeOfService option.
typeOfService0(Client only) The preferred type of service value to be set on outgoing packets. Valid integer values are [0,256). With JDK 6, only works when the Java Runtime uses the IPv4 stack, which can be done by setting the java.net.preferIPv4Stack system property to true. Cannot be used at the same time as the diffServ option.
wireFormat The name of the wire format to use.
wireFormat.* All the properties with this prefix are used to configure the wireFormat. See Table A.4 for more information.

Table A.4 shows the wire format options supported by the OpenWire protocol.

Table A.4. Transport Options Supported by OpenWire Protocol

OptionDefaultDescriptionNegotiation policy
wireformat .stackTraceEnabledtrue

Should the stack trace of an exception occuring on the broker be sent to the client?

Set to false if either side is false.

wireformat .tcpNoDelayEnabledfalse

Provides a hint to the peer that TCP nodelay should be enabled on the communications Socket.

Set to false if either side is false.

wireformat .cacheEnabledtrue

Should commonly repeated values be cached so that less marshalling occurs?

Set to false if either side is false.

wireformat .cacheSize1024

If cacheEnabled is true, this property specifies the maximum number of values to cache.

Use the smaller of the two values.

wireformat .tightEncodingEnabledtrue

Should wire size be optimized over CPU usage?

Set to false if either side is false.

wireformat .prefixPacketSizetrue

Should the size of the packet be prefixed before each packet is marshalled?

Set to true if both sides are true.

wireformat .maxInactivityDuration30000

The maximum inactivity duration (before which the socket is considered dead) in milliseconds. On some platforms it can take a long time for a socket to appear to die, so we allow the broker to kill connections if they are inactive for a period of time. Set to a value <= 0 to disable inactivity monitoring.

Use the smaller of the two values.

wireformat .maxInactivityDurationInitalDelay10000The initial delay in starting the maximum inactivity checks. Note: The mis-spelling, Inital, is a typographic error in the source code.  

D

dynamic failover, Dynamic Failover
broker configuration, Broker-side configuration
client configuration, Client-side configuration

E

embedded broker, Embedded brokers
brokerName, Broker options
configuration, Broker options
deleteAllMessagesOnStartup, Broker options
enableStatistics, Broker options
persistent, Broker options
populateJMSXUserID, Broker options
useJmx, Broker options
useShutdownHook, Broker options

F

failover, Failover Protocol
backOffMultiplier, Transport options
backup, Transport options
broker properties, Broker-side configuration
dynamic, Dynamic Failover
initialReconnectDelay, Transport options
maxCacheSize, Transport options
maxReconnectAttempts, Transport options
maxReconnectDelay, Transport options
randomize, Transport options
startupMaxReconnectAttempts, Transport options
static, Static Failover
timeout, Transport options
trackMessages, Transport options
updateURIsSupported, Transport options
useExponentialBackOff, Transport options
failover URI, Failover URI
transport options, Transport options

S

static failover, Static Failover

V

VM
advanced URI, Advanced URI syntax
broker configuration, Simple URI syntax
broker name, Simple URI syntax
broker.*, Simple URI syntax
brokerConfig, Simple URI syntax
create, Embedded brokers, Transport options
embedded broker, Embedded brokers
marshal, Transport options
simple URI, Simple URI syntax
waitForStart, Embedded brokers, Transport options
wireFormat, Transport options
VM URI
advanced, Advanced URI syntax
simple, Simple URI syntax