From bb83c86cd6b360da5763106f87266ab1fa11f030 Mon Sep 17 00:00:00 2001 From: Gerhard Gonter <ggonter@gmail.com> Date: Tue, 13 Jun 2023 20:09:03 +0200 Subject: [PATCH] added option to send announcement in standalone mode --- modules/util/Net/fanout.pm | 28 +++++++++++++++++++++++++--- 1 file changed, 25 insertions(+), 3 deletions(-) mode change 100644 => 100755 modules/util/Net/fanout.pm diff --git a/modules/util/Net/fanout.pm b/modules/util/Net/fanout.pm old mode 100644 new mode 100755 index c4de328..2a4da29 --- a/modules/util/Net/fanout.pm +++ b/modules/util/Net/fanout.pm @@ -16,9 +16,19 @@ Connect to a fanout pub/sub server to receive and send messages =head1 STANDALONE MODE -Start fanout, subscribe to three channels and monitor these: +To start fanout, call the module either this way - perl -MNet::fanout -e 'Net::fanout::main()' -- --PeerHost=fanout.example.org --PeerPort=1986 channel1 channel2 channel3 + perl -MNet::fanout -e 'Net::fanout::main()' -- ...more parameters... + +or make Net/fanout.pm executable and call it like this + + path/to/Net/fanout.pm ...more parameters... + +=head2 examples + +=head3 subscribe to three channels and monitor these + + --PeerHost=fanout.example.org --PeerPort=1986 --monitor channel1 channel2 channel3 =cut @@ -221,6 +231,8 @@ sub main my $PeerPort= 1986; my @channels= (); + my $monitor= 0; + my @messages= (); while (my $arg= shift(@ARGV)) { if ($arg =~ /^--(.+)/) @@ -228,6 +240,8 @@ sub main my ($opt, $val)= split('=', $1, 2); if ($opt eq 'PeerHost') { $PeerHost= $val || shift(@ARGV); } elsif ($opt eq 'PeerPort') { $PeerPort= $val || shift(@ARGV); } + elsif ($opt eq 'monitor') { $monitor= 1; } + elsif ($opt eq 'message') { my $msg= $val || shift(@ARGV); push (@messages, $msg); } # TODO: else report problem } else @@ -244,10 +258,18 @@ sub main $fanout->subscribe($channel); } + if (@messages && @channels) + { + foreach my $msg (@messages) + { + $fanout->announce($channels[0], $msg); + } + } + my $stdin= IO::Select->new(); $stdin->add(\*STDIN); - while (1) + while ($monitor) { my ($channel, $msg)= $fanout->receive(); if (defined ($channel)) -- GitLab