Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env perl
- use strict;
- use Data::Dumper;
- use Getopt::Long;
- use Net::STOMP::Client;
- $Data::Dumper::Indent = 1;
- my ($host, $message, $file, $queue);
- my ($port, $username, $password, $vhost) = (61613, "", "", "/");
- GetOptions(
- "host:s" => \$host,
- "port:i" => \$port,
- "file:s" => \$file,
- "vhost:s" => \$vhost,
- "message:s" => \$message,
- "queue:s" => \$queue,
- "username:s" => \$username,
- "password:s" => \$password,
- );
- usage("a queue is required") unless $queue;
- usage("a host is required") unless $host;
- if( $file && $message ) {
- usage("do not specify both file and message");
- } elsif( $file && ! -f $file ) {
- usage("file '$file' cannot be found");
- } elsif( ! $file && ! $message ) {
- usage("either message of file must be specified");
- }
- print "connecting to $host:$port\n";
- my $stomp = Net::STOMP::Client->new(host => $host, port => $port);
- print "logging in...\n";
- $stomp->connect(login => $username, passcode => $password, host => $vhost);
- if( $message ) {
- print "sending message...\n";
- $stomp->send( destination => $queue, body => $message );
- } else {
- print "sending contents of file '$file'...\n";
- open my $fh, '<', $file;
- $stomp->send( destination => $queue, body => do { local $/; <$fh>; } );
- close $fh;
- }
- print "disconnecting...\n";
- $stomp->disconnect;
- print "finished\n";
- sub usage {
- my $msg = shift || "";
- print <<EOF;
- $msg
- Send a message to a queue or topic
- Usage: $FindBin::Script
- --host message server
- --port message server port (default 61613)
- --message string to send
- --vhost vhost to login to (default /)
- --file read from a file and send the contents
- --username optional
- --password optional
- --queue queue to send message to
- EOF
- exit;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement