JMS for CPython via JPype?

Steve Menard foo at bar.com
Sat Nov 6 19:19:49 CET 2004


David Morgenthaler wrote:
> On Tue, 2 Nov 2004 18:19:25 +0100, Wolfgang Keller
> <wolfgang.keller.nospam at gmx.de> wrote:
> 
> 
>>Hello,
>>
>>sorry for the potentially dumb question, but - would JPype make it possible 
>>for a CPython program to use JMS? It seems that JMS is going to become a
>>standard for (java-based) MOM, so as an excellent middleware language it
>>should be possible for CPython to somehow "talk" (and understand) JMS...
>>
> 
> 
> Your question intrigued me, so I gave it a try. And the anwer (at
> least for JMS Publish/Subscribe TextMessages) is YES.
> 
> The example I wrote is too long to include here, but you can get it at
> http://home.comcast.net/~david.g.morgenthaler/Jpypejms.zip. It
> includes:
> - Java classes for a publisher (src/messaging/JpypePublisher) and a
> subscriber (src/messaging/JpypeSubscriber). These Java classes, which
> do most of the dirty work of connecting to the JMS server, are used
> from python via jpype.
> - Java classes that test the publisher and subscriber
> (src/messaging/testJpepePublisher, src/messaging/testJpypeSubscriber)
> - A Java interface that is used by python for the JProxy
> - python scripts for publishing and subscribing
> - An build.xml for ant to build and run the Java classes
> 
> The  Java and python publishers and subscribers work in any reasonable
> combination (J pub/J sub, J pub/p sub, p pub/p sub, p pub/J sub, and
> even with multiple subscribers)
> 
> Unzip to a conveniently located folder. You'll find a build.xml for
> ant to build the Java. You'll have to edit (in the testers and in the
> python scripts) the naming and connection factory stuff for your
> situation. You'll also have to edit the python scripts to correctly
> locate your jvm and other classpath information. Once you're correctly
> configured, you can use ant to build and/or execute the Java (type
> "ant help"). And once the Java is built, you can try the python
> versions.
> 
> I can't imagine that this approach wouldn't work for JMS Queues. And
> while I haven't tested it, I don't see anything preventing the use of
> other message types (BinaryMessage, ObjectMessage,...).
> 
> BTW, I don't detect any noticable slowdown in the python versions from
> the Java versions (probably because of the strightforward conversion
> of python strings to Java Strings).
> 
> HTH,
> Dave
> 

Dave,

This example is amazing! would you be willing to contribute it to a 
Jpype examples/recipe repository? I think such a place would be great 
for those starting to use JPype. And as my documentation is not so good 
(yet), good examples can only help.

Thanks.

Steve Menard



More information about the Python-list mailing list