I am trying send a message to an Active MQ topic using Perl's Net::Stomp. On the other side a Java Client monitors the Topic and picks up the message from it. The Active MQ is based on Spring framework and I have the below defined in the Spring config.xml
<amq:transportConnectors>
<amq:transportConnector name="openwire" uri="tcp://localhost:61616" />
<amq:transportConnector name="stomp" uri="stomp://localhost:61613" />
</amq:transportConnectors>
<!-- ActiveMQ destinations to use for RTlog Messages -->
<amq:topic id="rTlogDest" physicalName="RTlogTopic" name="RTlogTopic"/>
The messages sent from Perl are not being picked up by the Java client on the other side at all.The perl code looks like below. Is there any thing wrong in it?
use Net::Stomp;
my $stomp = Net::Stomp->new({hostname => 'localhost', port => '61613'});
$stomp->connect({login => 'admin', passcode => 'password'});
#$stomp->send({destination => 'RTlogTopic', body => 'test message'});
$frame = Net::Stomp::Frame->new(
{ command => 'SEND',
headers => { 'destination' => 'RTlogTopic',
'timestamp' => time
},
body => 'test message' } );
$stomp->send_frame($frame);
$stomp->disconnect;
I have used the $stomp->send
method too (commented out above), but it doesn't work either. Then I read somewhere that STOMP needs the message to be framed and sent and hence I framed the message. The MQ Java listener works fine for messages coming into port 61616 though TCP (from other java clients), but I am not able to make it work for Perl through 61613 (multiple message producers). I googled and found that a lot of people have made it work on PHP to Java, but not a single example of Perl to Java. Is there a different way that the Stomp messages needs to be processed on the Java monitor side (consumer) or the usual onMessage implementation (like for TCP) should work?
I achieved to send a message to Activemq queue (fyi, 5.3). Below you can check the code.
First, check your destination name is ok in stomp-perl side, it should be something like '/topic/abc' to send to Amq topic abc. See http://activemq.apache.org/stomp.html
Also you can check your message is in your queue or was published into your topic by pointing a browser to: http://localhost:8161/admin or the host where your Amq is running.
Hope this helps.
Here it is the sample code:
#!/usr/bin/perl
use Net::Stomp;
my $msg = "hello world\n";
print $msg
# send a message to the queue 'xyz'
my $stomp = Net::Stomp->new( { hostname => 'localhost', port => '61613' } );
$stomp->connect( { login => 'hello', passcode => 'there' } );
$stomp->send(
{ destination => '/queue/xyz', body => $msg } );
$stomp->disconnect;