JMS for CPython via JPype?

  • Thread starter Wolfgang Keller
  • Start date
W

Wolfgang Keller

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...

TIA,

Best regards

Wolfgang Keller
 
S

Steve Menard

Wolfgang said:
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...

TIA,

Best regards

Wolfgang Keller

I am not very well versed in JMS, but unless it absolutely REQUIRE
subclassing, JPype will allow you to make full use for it without problem.

How to actually interpret the contents of the JMS message is left as an
exercise to the reader ;)

Steve
 
W

Wolfgang Keller

Hello,

and thanks for your reply.
I am not very well versed in JMS, but unless it absolutely REQUIRE
subclassing, JPype will allow you to make full use for it without problem.

How to actually interpret the contents of the JMS message is left as an
exercise to the reader ;)

Err, does JPype not provide something for interfacing with Java like CTypes
provides it for interfacing with C? I.e. working with Java/C types in
Python as if they were Python variables?

TIA,

Regards

Wolfgang Keller
 
S

Steve Menard

Wolfgang said:
Hello,

and thanks for your reply.




Err, does JPype not provide something for interfacing with Java like CTypes
provides it for interfacing with C? I.e. working with Java/C types in
Python as if they were Python variables?

TIA,

Regards

Wolfgang Keller

Indeed it does. For the most part, Java classes can be used just like
regular Python classes.

What I meant is that JMS messages can contain just about ANYTHING.
Serialized Java classes, XML, plain text, etc ... Of course, if a
regular Java program cna generate/interptet the contents, A python+Jpype
program will be able to do it too. Again, with the same caveat that
JPype does not (yet) support subclassing Java classes in python.


Steve Menard
 
D

David Morgenthaler

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
 
S

Steve Menard

David said:
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
 
D

David Morgenthaler

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

Consider it contributed. I'm glad to (finally) give something back to
c.l.py!

Dave
 
S

Steve Menard

David said:
Consider it contributed. I'm glad to (finally) give something back to
c.l.py!

Dave

Thank you very much!

I will add it to the exampels directyory for the next release.

Steve
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,567
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top