stompclt - versatile STOMP client
stompclt [OPTIONS]
stompclt is a versatile tool to interact with messaging brokers speaking STOMP and/or message queues (see Messaging::Message::Queue) on disk.
It receives messages (see Messaging::Message) from an incoming module, optionally massaging them (i.e. filtering and/or modifying), and sends them to an outgoing module. Depending on which modules are used, the tool can perform different operations.
Here are the supported incoming modules:
Here are the supported outgoing modules:
Here are some frequently used combinations:
See the "EXAMPLES" sections for concrete examples.
execute the given Perl code on each message, see the "CALLBACK" section below for more information
pass this data to the user supplied callback code, see the "CALLBACK" section below for more information
execute the Perl code in the given file on each message, see the "CALLBACK" section below for more information
use the given configuration file, see the "CONFIGURATION FILE" section below for more information
use the given Config::General options when creating the configuration parser
process at most the given number of messages; note: when using an incoming broker, to avoid consuming more messages, it is recommended to enable the --reliable option
detach stompclt so that it becomes a daemon running in the background; debug, warning and error messages will get sent to syslog; this option can be negated
show debugging information
process messages during at most the given number of seconds and then stop; can be fractional
enable STOMP 1.1 heart-beats between stompclt and the broker(s); this option can be negated
show some help
use this authentication string (see Authen::Credential) to authenticate to the incoming broker; this option can be given multiple times
use these options in the STOMP CONNECT frame sent to the incoming broker
use these socket options when connecting to the incoming broker
set the STOMP debug flags (see Net::STOMP::Client) when interacting with the incoming broker
set the incoming broker type; this can be useful when using STOMP features which are broker specific
use this connection URI (see Net::STOMP::Client) to connect to the incoming broker
read incoming messages from the given message queue (see Messaging::Message::Queue)
initialize the outgoing module only after having received the first message; this option can be negated
show all supported options
when using an incoming message queue, loop over it; this option can be negated
show this manual
use this authentication string (see Authen::Credential) to authenticate to the outgoing broker; this option can be given multiple times
use these options in the STOMP CONNECT frame sent to the outgoing broker
use these socket options when connecting to the outgoing broker
set the STOMP debug flags (see Net::STOMP::Client) when interacting with the outgoing broker
set the outgoing broker type; this can be useful when using STOMP features which are broker specific
use this connection URI (see Net::STOMP::Client) to connect to the outgoing broker
store outgoing messages into the given message queue (see Messaging::Message::Queue)
use this pid file
set the prefetch value (i.e. the maximum number of messages to received without acknowledging them) on the incoming broker
tell another instance of stompclt (identified by its pid file, as specified by the --pidfile option) to quit
use STOMP features for more reliable messaging (i.e. client side acknowledgments and receipts) at the cost of less performance; this option can be negated
when using an incoming message queue, remove the processed messages; this option can be negated
report statistics at the end of the execution; this option can be negated
get the status of another instance of stompclt (identified by its pid file, as specified by the --pidfile option); the exit code will be zero if the instance is alive and non-zero otherwise
use these options in the STOMP SUBSCRIBE frame used with the incoming broker; this option can be given multiple times
use this timeout when interacting with the broker (e.g. getting receipts back); can be fractional
use this timeout for the client heart-beat; can be fractional (default: 40)
use this timeout when connecting to the broker; can be fractional
use this timeout when disconnecting from the broker; can be fractional (default: 60)
use this timeout when attempting to send the last bytes to the broker just before disconnecting; can be fractional (default: 60)
use this timeout in the incoming module to stop stompclt when no new messages have been received (aka drain mode); can be fractional
when stopping stompclt, use this timeout to finish interacting with the broker; can be fractional
use this timeout for the server heart-beat; can be fractional (default: 10)
use this timeout when checking the status with --status; can be fractional
use these options in the STOMP UNSUBSCRIBE frame used with the incoming broker; this option can be given multiple times and should match the --subscribe options
display version information
keep at most the given number of not-yet-acknowledged messages in memory
To list all the available options in a compact form, type:
$ stompclt -l
stompclt can read its options from a configuration file. For this, the Config::General module is used and the option names are the same as on the command line. For instance:
daemon = true pidfile = /var/run/stompclt.pid incoming-queue = path=/var/spool/stompclt outgoing-broker-uri = stomp://broker.acme.com:6163 outgoing-broker-auth = "plain name=guest pass=guest"
Alternatively, options can be nested:
<outgoing-broker> uri = stomp://broker.acme.com:6163 auth = "plain name=guest pass=guest" </outgoing-broker>
Or even:
<outgoing> <broker> uri = stomp://broker.acme.com:6163 <auth> scheme = plain name = guest pass = guest </auth> </broker> </outgoing>
The options specified on the command line have precedence over the ones found in the configuration file.
stompclt can be given Perl code to execute on all processed messages. This can be used for different purposes:
To use callbacks, the --callback-path or --callback-code option must be used. The Perl code must provide functions with the following signature:
(optional) this will be called when the program starts, with the supplied data (see the --callback-data option) as a hash reference
(mandatory) this will be called when the program has one message to process; it will be given the message (see Messaging::Message) and must return either a message (it could be the same one or a new one) or a string describing why the message has been dropped
(optional) this will be called when the program has no message to process
(optional) this will be called when the program stops
The code can be put in a file, on the command line or in the stompclt configuration file, using the "here document" syntax.
Here is an example (to be put in the stompclt configuration file) that prints on stdout a JSON array of messages:
callback-code = <<EOF my($count); sub start ($) { $count = 0; } sub check ($) { my($msg) = @_; print($count++ ? "," : "["); print($msg->serialize(), "\n"); return($msg); } sub stop () { print($count ? "]\n" : "[]\n"); } EOF
For simple callback code that only needs the check
subroutine, it is enough to supply the "inside code". If the subroutine definition is missing, the supplied code will be wrapped with:
sub check ($) { my($msg) = @_; local *hdr = $msg->header(); local *bdy = $msg->body_ref(); ... your code goes here ... return($msg); }
This allows for instance to remove the message-id
header with something like:
$ stompclt ... --callback-code 'delete($hdr{"message-id"})'
Or to filter on message bodies with:
$ stompclt ... --callback-code 'return("skip") unless $bdy =~ /error/'
In the case of an incoming broker, stompclt deals with the subscriptions defined by the --subscribe option.
Regardless of the --reliable option, subscriptions are always made using receipts. Also, if missing, an id
header is always added.
Here is for instance how to create a named durable topic subscription using Apollo:
$ stompclt ... --subscribe 'destination=/topic/foo persistent=true id=mysub'
By default, when it finishes, stompclt does not unsubscribe. It simply disconnects from the broker and the latter will perform the necessary cleanup when terminating the STOMP connection.
If the --unsubscribe option is given, even if it is empty, stompclt will explicitly unsubscribe before disconnecting, also using receipts.
Here is for instance how to destroy, when stompclt ends, the durable topic subscription created above:
$ stompclt ... --unsubscribe 'persistent=true'
There is no need to give the subscription id
in the --unsubscribe option because, by default, it comes from the matching --subscribe option.
stompclt has experimental UDP support (outgoing only). This has been tested with Apollo.
To use it, simply specify an outgoing URI that uses UDP such as:
$ stompclt ... --outgoing-broker-uri udp://broker.acme.com:6163
Features such as authentication, heart beating, reliability and socket options are not supported over UDP.
Here is an example of a configuration file for a message sender daemon (from queue to broker), forcing the persistent
header to true
(something which is highly recommended for reliable messaging) and setting the destination:
# define the source message queue <incoming-queue> path = /var/spool/sender </incoming-queue> # modify the message header on the fly callback-code = <<EOF $hdr{destination} = "/queue/app1.data"; $hdr{persistent} = "true"; EOF # define the destination broker <outgoing-broker> uri = "stomp://broker.acme.com:6163" </outgoing-broker> # miscellaneous options reliable = true pidfile = /var/run/sender.pid daemon = true loop = true remove = true
Here is an example of a configuration file for a message receiver daemon (from broker to queue):
# define the source broker <incoming-broker> uri = "stomp://broker.acme.com:6163" <auth> scheme = plain name = receiver pass = secret </auth> </incoming-broker> # define the subscriptions <subscribe> destination = /queue/app1.data </subscribe> <subscribe> destination = /queue/app2.data </subscribe> # define the destination message queue <outgoing-queue> path = /var/spool/receiver </outgoing-queue> # miscellaneous options pidfile = /var/run/receiver.pid daemon = true
Here is how to use the configuration file above with some options overridden on the command line to drain the queues in the foreground:
$ stompclt --config test.conf --no-daemon --timeout-inactivity 10
Here is an example of a configuration file for a message shoveler (from broker to broker), clearing some headers on the fly so that messages can be replayed safely:
# define the source broker <incoming-broker> uri = "stomp://broker.acme.com:6163" </incoming-broker> # define the subscriptions <subscribe> destination = /queue/app1.data </subscribe> <subscribe> destination = /queue/app2.data </subscribe> # define the destination broker <outgoing-broker> uri = "stomp://dev-broker.acme.com:6163" </outgoing-broker> # modify the message so that it can be replayed callback-code = <<EOF foreach my $name (qw(message-id timestamp expires)) { delete($hdr{$name}); } EOF
Callback code can also be used to tap messages, i.e. get a copy of all messages processed by stompclt. Here is some callback code for this purpose that could for instance be merged with the shoveling code above. It also shows how to use the --callback-data option:
callback-code = <<EOF my($queue); sub start ($) { my($data) = @_; $queue = Messaging::Message::Queue->new($data); } sub check ($) { my($msg) = @_; $queue->add_message($msg); return($msg); } EOF
Callback data must be given to specify which message queue to use:
$ stompclt --config tap.conf --callback-data "path=/tmp/tap type=DQS"
Authen::Credential, Config::General, Messaging::Message, Messaging::Message::Queue, Net::STOMP::Client.
Lionel Cons http://cern.ch/lionel.cons
Copyright (C) CERN 2012-2024