Skip to content

gmallard/stomp-demo

Repository files navigation

Stomp Messaging Client Examples

Notes

Initial examples were based on the code suplied with the stompserver gem, and with tests from the stomp gem. This has been expanded as described subsequently.

The default configuration in this project uses a non-default port for the stompserver Ruby gem. This is because I already have a running instance of ActiveMQ. My system is set up as follows:

  • stompserver_ng

    port => 51613

  • AMQ

    port => 61613

  • Apollo

    port => 62613

  • RabbitMQ

    port => 41613

stomp Message Protocol

Documentation of the stomp message protocol can be found here:

Software Versions

This project’s code should function with a variety of versions of:

  • The ruby stomp gem

  • Ruby versions

  • Various servers, various versions

Note: currently all examples use the STOMP 1.0 protocol level by default.

stompserver_ng Note

A version of server code modified for 1.9.0+ is available by:

* git clone git://github.com/gmallard/stompserver_ng.git

Rdoc Generation

To generate rdoc for this project, use:

  • rake doc:rdoc

Basic Producer and Consumer Tests

The basic producer (putter) and consumer (getter) clients are found in the basic subdirectory of this project. The objective of these tests is to:

  • Start a basic message getter.

  • Send messages to the basic message getter.

To run these tests:

  • Terminal 1: ruby basic/queue_get.rb

  • Terminal 1: Observe output

  • Terminal 2: ruby basic/queue_put.rb

  • Terminal 2: Observe output

Alternate run method:

  • Terminal 1: rake basic:getter

  • Terminal 1: Observe output

  • Terminal 2: rake basic:putter

  • Terminal 2: Observe output

Queued EOF Producer and Consumer Tests

The queued EOF producer (putter) and consumer (getter) clients are found in the queue-eof subdirectory of this project. The objective of these tests is to:

  • Start a message getter which continuously waits for messages.

  • Ends when a special EOF messsage is encountered on the input queue.

  • Send many messages to the message getter.

  • Eventually send the special EOF message.

To run these tests:

  • Terminal 1: ruby queue-eof/queue_get.rb

  • Terminal 2: ruby queue-eof/queue_put.rb

  • Terminal 1: Observe output

  • Terminal 2: Repeat the queue_put step one or many times

  • Terminal 1: Observe output

  • Terminal 2: ruby queue-eof/queue_put.rb TRUE

  • Terminal 1: Observe output

Note: when TRUE is passed to the message putter, it must be the first command line parameter passed. Any command line parameter overrides should be coded later.

Alternate run method:

  • Terminal 1: rake qeof:getter

  • Terminal 2: rake qeof:putter

  • Terminal 1: Observe output

  • Terminal 2: Repeat the queue_put step one or many times

  • Terminal 1: Observe output

  • Terminal 2: rake qeof:putter_true

  • Terminal 1: Observe output

Single Producer and Threaded Consumer Test

Show an example with the following characteristics:

  • A putter knows how many getters (n) will be processing messages

  • The putter evenly distributes messages across (n) queues

  • (n) getter threads are started, and process messages

To run these tests:

  • Terminal 1: ruby threaded/getters_demo.rb

  • Terminal 1: Observe output

Alternate run method:

  • Terminal 1: rake threaded:getters

  • Terminal 1: Observe output

stomp Monitor Demonstration

Show an example of a stomp server monitor, as described in the stompserver rdoc’s.

To run this demonstration:

  • Terminal 1: ruby monitor/stompmon.rb

  • Terminal X: Run individual putter tests to place messages on queues

  • Terminal 1: Observe queue statistics updates every five seconds

Alternate run method:

  • Terminal 1: rake monitor:monitor

  • Terminal X: Run individual putter tests to place messages on queues

  • Terminal 1: Observe queue statistics updates every five seconds

Note

This demonstration is stompserver specific. It should run on Active MQ, but will display nothing of interest (this is untested).

stomp Connection Object Demonstration

Show an example of using a stomp connection object to send and receive messages synchronously.

To run this demonstration:

  • Terminal 1: ruby connection/send_recv.rb

  • Terminal 1: Observe output

Alternate run method:

Terminal 1: rake conn:sendreceive

  • Terminal 1: Observe output

Utilities

Provide utilities for working with the code in this project.

Clear Queue

This utility can be used to drain / clear a queue of all messages.

To run the clear queue utility:

  • ruby utils/clearq.rb “/queue/qname”

The full name of the queue to clear must be provided as the first command line argument.

Overriding Parameters in the Configuration File

Command line parameters can override those specified in the props.yaml configuration file. A summary of the command line overrides allowed is shown here:

-u userid

The user id to connect to the server with.

–user=userid

Same as -u.

-p password

The server password to use.

–password=password

Same as -p.

-s servername

The server name to connect to. An IP address may be used.

–server=servername

Same as -s.

-P portnumber

The port the server is serving from.

–port=portnumber

Same as -P.

-h

Get help on the command line options, and exit.

–help

Same as -h.

Environment Parameter Overrides

The ability to override:

  • queue names for putters and getters

  • putter message counts

is provided. A simple example of using this is:

  • MAX_MSGS=100 QNAME=“/queue/special” ruby basic/queue_put.rb

Again, this capability is not provided for in the rake executions of the examples.

Eventmachine Examples

Several examples of using the ruby eventmachine gem’s stomp support have been added.

About

Demonstrate stomp clients using stompserver and Active MQ.

Resources

License

Stars

Watchers

Forks

Packages

No packages published