Previously we looked at connecting one producer to one consumer using a unix pipe. If we want to do many to many connections, we can use the AnyEvent Notifier
I mentioned in Connecting Software Systems.
Instead of echoing a notification that a work unit has been created to STDOUT
I write it to a socket connected to the notifier.
IO::Socket makes this absurdly easy.
use IO::Socket ':crlf'; use constant SHUTDOWN_SOCK_RW => 2; my $sock = IO::Socket::INET->new(PeerAddr => 'localhost:12345'); for (1..5) { my_log "Iteration $_"; my $filename = create_file($top); print $sock "/producer/file-creator/new-file $filename" . CRLF; my_log "PRODUCED $filename"; } $sock->shutdown(SHUTDOWN_SOCK_RW); $sock->close();
I often use a subject<SPACE>message
format to make it easy for clients to filter between important messages.
I’ll demonstrate the consumer next time.
Advertisements
Leave a Reply