Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Using Perl to Publishing to Message Queues

by arunhorne (Pilgrim)
on Aug 09, 2004 at 08:49 UTC ( [id://381167]=perlquestion: print w/replies, xml ) Need Help??

arunhorne has asked for the wisdom of the Perl Monks concerning the following question:

Monks, firstly let me say that this question is highly speculative, designed to spur discussion (unless of course I have totally missed the one line answer!)

The Scenario:

We are using an integration product based around JMS queues. It is often necessary to put messages on these queues manually. For this task I see Perl as far more appropriate than Java as often these messages are stored in text files that need a level of preprocessing to parse out the message.

The Question

Although this is obviously going to be tricky, is it possible that a Perl program could publish directly to a JMS queue. Obviously this may be JMS vendor dependant due to the potentially different communication protocols used to communicate with JMS servers. I have checked CPAN and there is nothing immediately obvious. However, there are a number of modules that allow communication with a JVM so I have a small amount of hope.

Has anyone come across this problem, or a similar one of calling a Java API from Perl - I would be very interested to hear your comments.

____________
Arun
  • Comment on Using Perl to Publishing to Message Queues

Replies are listed 'Best First'.
Re: Using Perl to Publishing to Message Queues
by inman (Curate) on Aug 09, 2004 at 10:30 UTC
    Hello arunhorne

    It is increasingly the case that vendors favour Java first followed by C as the preferred method of delivering an API. This tends to exclude Perl development until someone writes the XS and delivers it as a CPAN module. Fortunately the Inline modules provide a suitable compromise in that you can have 'native language' code inside your Perl app.

    The following code uses Inline::Java to import an external Java class from a vendor API and use it in a small program. The code starts by introducing Inline::Java to the first class in AUTOSTUDY mode. This gives us a place to start while allowing us to use any class that we care to instantiate. From this point on, the coding is Perl coding in a Java style i.e. with lots of exception handling!

    #! /usr/bin/perl use strict; use warnings; use Data::Dumper; use Inline ( Java => 'STUDY', STUDY => ['com.verity.search.VSearch'], AUTOSTUDY => 1, ); use Inline::Java qw(caught) ; eval { my $search = new com::verity::search::VSearch(); $search->setServerSpec('localhost:9900'); $search->setK2UserName('user'); $search->setK2Password('password'); my $ticket = $search->k2Login();; my $colls = $search->collectionsInfo(); my $collCount = $colls->count(); foreach (0..$collCount-1) { my $coll = $colls->at($_); print "Collection: ".$coll->getAlias."\n"; } $search->addCollection ('verity_doccoll'); $search->setQueryText('*'); my $result = $search->getResult(); print "Docs Found: ", $result->{docsFound}; }; if ($@) { if (caught("java.lang.Exception")) { my $msg; $msg = ($@->getMessage()); print "Exception $msg\n"; # prints ouch! } else { # It wasn't a Java exception after all... die $@ ; } }

    Execution is slow when the code is run for the first time. Information relating to the classes is compiled and stored for later use. Subsequent execution uses this stored information. The JVM also takes a period of time to initiate which adds to startup time. Architecting your apps to do a lot of work or stay in memory between transactions will minimise this startup overhead. See the POD for details on using as a CGI for example.

    Bye!

Re: Using Perl to Publishing to Message Queues
by tachyon (Chancellor) on Aug 09, 2004 at 09:23 UTC

    Inline::Java is probably what you want. Accessing an API can be as easy as STUDYing it. See the docs.

    cheers

    tachyon

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://381167]
Approved by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (5)
As of 2024-04-25 13:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found