0
votes

I want to consume and publish messages to wso2 message broker using python client. I have searched a lot and could not find any python client specially designed for wso2 message broker.

Although I came to know that pika library that work for rabbitmq can work for wso2 message broker.

So I wrote a code to publish messages to wso2 queue. I created a testqueue on wso2 message broker and tried to publish message using pika library.

import pika

params = pika.URLParameters("amqp://admin:admin@localhost:5672/%2F")
connection = pika.BlockingConnection(params)
channel = connection.channel()
# channel.queue_declare(queue="testqueue", durable=True, exclusive=False, auto_delete=False)
if channel.basic_publish(exchange='', routing_key='testqueue',
                         body='New message for testing',
                         properties=pika.BasicProperties(content_type='text/plain', delivery_mode=1),
                         mandatory=True):
    print(" Message was published sucessfully")
else:
    print("message could not be published")

It is showing Message was published but it is not being published. But in the wso2 message broker, I am getting console error.

[ Sequence: 24976 ] Exception occurred while processing inbound events.Event type: MESSAGE_EVENT
java.lang.NullPointerException
    at java.util.HashSet.<init>(HashSet.java:118)
    at org.wso2.andes.kernel.router.QueueMessageRouter.getMatchingStorageQueues(QueueMessageRouter.java:88)
    at org.wso2.andes.kernel.disruptor.inbound.MessagePreProcessor.preProcessIncomingMessage(MessagePreProcessor.java:214)
    at org.wso2.andes.kernel.disruptor.inbound.MessagePreProcessor.updateRoutingInformation(MessagePreProcessor.java:190)
    at org.wso2.andes.kernel.disruptor.inbound.MessagePreProcessor.onEvent(MessagePreProcessor.java:75)
    at org.wso2.andes.kernel.disruptor.inbound.MessagePreProcessor.onEvent(MessagePreProcessor.java:49)
    at com.lmax.disruptor.BatchEventProcessor.run(BatchEventProcessor.java:128)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
    at java.lang.Thread.run(Thread.java:748)
1

1 Answers

1
votes

Above code was missing exchange (going as blank) , instead added amq.direct to make it work.

channel.publish(exchange='amq.direct', 
        routing_key='testqueue', 
        body='Hello World!',
        properties=pika.BasicProperties(content_type='text/plain', delivery_mode=1)
)