[rabbitmq-discuss] Producing an amqp message using python and consuming that same message using java

Julien Martin balteo at gmail.com
Wed Dec 12 12:01:22 GMT 2012


*I am trying to produce an amqp message from python and consume that same
message from java/spring.*

Here is my *producer* code (python):

import pika, sys, pickle

from Person import Person

connection = pika.BlockingConnection()
channel = connection.channel()
me = Person("Juliano", 38)
pickled_me = pickle.dumps(me)

Here is my *consumer* code (java):

ApplicationContext context = new
template = context.getBean(AmqpTemplate.class);Person me = (Person)
template.receiveAndConvert("myqueue");System.out.println("Me: " +
me.getName() + ":" + me.getAge());

Here is the java class for Person:

package trc.suivi.amqp;

import java.io.Serializable;
public class Person implements Serializable {
    private static final long serialVersionUID = 1L;
    private String name;
    private int age;

    public String getName() {
        return name;

    public void setName(String name) {
        this.name = name;

    public int getAge() {
        return age;

    public void setAge(int age) {
        this.age = age;

and the corresponding python class:

class Person:
    def __init__(self, name, age):
        self.name = name
        self.age = age

(located in *trc/suivi/amqp* directory structure)

I get a *class cast exception*. I am pretty sure this has to do either with
the package/module name or with some serialization issue...

Can anyone please help?


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.rabbitmq.com/pipermail/rabbitmq-discuss/attachments/20121212/f0e34d0a/attachment.htm>

More information about the rabbitmq-discuss mailing list