Red Hat DocumentationFuse Message BrokerToggle FramesPrintFeedback

Stomp Example

Overview

Fuse Message Broker provides some sample code in ActiveMQInstallDir/example/ruby that enables you to experiment with the Stomp protocol in the Ruby programming language.

Example prerequisites

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:

  • Ruby programming language—download and install the Ruby programming language from http://www.ruby-lang.org/en/downloads. Add the Ruby /bin directory to your PATH.

  • RubyGems package manager—RubyGems (http://www.rubygems.org) is a utility for installing and managing add-ons to the Ruby language. Download and install RubyGems as follows:

    1. Download a RubyGems archive file (.tgz, .zip, or .gem) from the RubyForge (http://rubyforge.org/frs/?group_id=126).

    2. Unzip the RubyGems archive.

    3. Initialize RubyGems by entering the following command:

      ruby GemsInstallDir/setup.rb
    4. Add GemsInstallDir/bin to your PATH.

  • Stomp package for Ruby—install the Stomp package for Ruby by running the following command:

    gem install stomp

    RubyGems downloads and installs the requisite package to support the Ruby Stomp client API.

Example steps

To try out the Stomp protocol, perform the following steps:

Configure the broker

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

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

Run the broker

Run the default broker by entering the following at a command line:

activemq

The default broker automatically takes its configuration from the default configuration file.

Note

The activemq script automatically sets the ACTIVEMQ_HOME and ACTIVEMQ_BASE environment variables to FuseInstallDir/fuse-message-broker-Version by default. If you want the activemq script to pick up its configuration from a non-default conf directory, you can set ACTIVEMQ_BASE explicitly in your environment. The configuration files will then be taken from $ACTIVEMQ_BASE/conf.

Run the Ruby listener

To connect the listener tool to the stomp://localhost:61613 endpoint (Stomp over TCP), change directory to ActiveMQInstallDir/example/ruby and enter the following command:

ruby listener.rb

They Ruby listener connects to the endpoint, stomp://localhost:61613, by default. You could change this endpoint address by editing the listener.rb script.

Run the Ruby publisher

To connect the publisher tool to the stomp://localhost:61613 endpoint (Stomp over TCP), change directory to ActiveMQInstallDir/example/ruby and enter the following command:

ruby publisher.rb

You should see some output like the following:

Sent 1000 messages
Sent 2000 messages
Sent 3000 messages
Sent 4000 messages
Sent 5000 messages
Sent 6000 messages
Sent 7000 messages
Sent 8000 messages
Sent 9000 messages
Sent 10000 messages
Received report: Received 10000 in 4.567 seconds, remaining: 9
Comments powered by Disqus