用于python的wso2消息代理客户端

时间:2017-08-04 06:27:17

标签: python wso2 messagebroker

我想使用python客户端使用和发布消息到wso2消息代理。我搜索了很多,找不到专门为wso2消息代理设计的任何python客户端。

虽然我知道为rabbitmq工作的pika库可以用于wso2消息代理。

所以我编写了一个代码来将消息发布到wso2队列。我在wso2消息代理上创建了一个testqueue,并尝试使用pika库发布消息。

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")

显示消息已发布但未发布。但是在wso2消息代理中,我收到了控制台错误。

[ 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 个答案:

答案 0 :(得分:0)

以上代码缺少交换(显示为空白),而是添加amq.direct以使其正常工作。

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