Paul.Unix has asked for the wisdom of the Perl Monks concerning the following question:

Hi We want to transfer files over AMQ and once I wrote a Perl script that uses an external tool Spazio and IBM MQ to do the same. Perl has a STOMP module to interface with AMQ but how can I send a large file without reading it into a variable? I made a test script that can put a small file on an Artemis queue which can be read by a Camel route. But what if the file does not fit in memory?
#!/home/mqm/perl5/bin/perl use strict; use warnings; use File::stat; use Net::STOMP::Client; my $mypath = "/home/mqm/perl2amq"; my $myfile = "pauls_what.bin"; my $stomp = Net::STOMP::Client->new( host => 'artemis', port => '61613 +' ); my $peer = $stomp->peer(); printf("connected to broker %s (IP %s), port %d\n", $peer->host(), $peer->addr(), $peer->port()); $stomp->connect( login => 'jboss', passcode => 'notyourstoknow' ); printf("speaking STOMP %s with server %s\n", $stomp->version(), $stomp->server() || "UNKNOWN"); my $content; open(my $fh, '<', $myfile) or die "cannot open file $myfile"; { local $/; $content = <$fh>; } close($fh); my $stat = stat($myfile); my $mylength = $stat->size; # content-length => $mylength, my $dashhost = "amqclient-source-com"; my $five = "12345"; my $stime = time(); my $my_id = "ID-$dashhost-$five-$stime-2-3"; $stomp->send( destination => "testqueue", CamelFileAbsolutePath => "$mypath/$myfile", CamelFileName => $myfile, CamelFileNameConsumed => $myfile, CamelFileNameOnly => $myfile, CamelFileParent => $mypath, CamelFilePath => "$mypath/$myfile", CamelFileRelativePath => $myfile, breadcrumbId => $my_id, "content-type" => "application/octet-stream", body => $content, ); $stomp->disconnect;

Replies are listed 'Best First'.
Re: transferring a large file with STOMP over Artemis AMQ
by NetWallah (Canon) on Aug 22, 2017 at 18:29 UTC
    The Net::Stomp protocol allows multiple "send" requests.

    Simply read the file a record at a time (do not zap $/) , and send a record at a time.

    You will probably need to modify the reciever to receive this, and , possibly setup a way to signal "Last record", or "End of file", possibly via a key-value pair that is passed.

                    All power corrupts, but we need electricity.