开发者

Python calling a MQ broker and DBus

开发者 https://www.devze.com 2023-02-07 03:20 出处:网络
My Python is worse than my Chinese (I have never seen so many smiling faces than when I try to speak Mandarin), so I need a little help:

My Python is worse than my Chinese (I have never seen so many smiling faces than when I try to speak Mandarin), so I need a little help:

I want something to listen to MQ (for topics specified in a configuration) and relay the message to dBus and in return listen to dBus (for topics specified in a configuration) and relay them back to the MQ. From poking around my conclusion is 开发者_JAVA技巧Python would be suitable. I found: MQTT.org PYMQi and Mosquitto.

So the approach seems to be valid. Now I'm looking for code samples. My main concern is to make the code efficient. Since it seems that the routine needs to run in a polling loop how do I do that in Python without bogging down my system.


PYMQi has sample code here: http://packages.python.org/pymqi/examples.html In order not to poll you might want to look at MQ Triggers. They enable an application to be launched when a message is put on a queue.


I want something to listen to MQ (for topics specified in a configuration) and relay the message to dBus and [...]

Hi stwissel,

I'd also like to mention that the upcoming 1.2 release of PyMQI will provide support for topics and subscriptions. It should really be pretty soon now, I'm fixing up some test cases literally as we speak. Just thought I'd mention it in case you were wondering whether it was possible to use those MQ features with PyMQI; well, not with 1.1 but 1.2 is just around the corner.

Cheers!


You need to be clear about whether you are using MQ (WebSphere MQ aka MQSeries), or MQTT aka WebSphere MQ Telemetry.

If you are using MQ then definitely check out PyMQI which is looking pretty nice at this point - here is a recent example of how to use this.

For MQTT which is a lightweight message protocol which can interoperate with WebSphere MQ given the correct components, then the mosquitto project provides a Python API, and there are a few examples that use it.

I'm afraid I'm not a Python expert so I'm not entirely sure how you'd optimise around the looping side of things.


I believe you don't need to poll. PyMQI provides blocking reads (and I think dBus does that too).

If you need to listen on more than one connection at once (e.g. both dBus and MQ) you still should use blocking reads, just executing each one in a separate thread and maybe communicating the results using something like Python's Queue.Queue(). This way you get the messages as soon as they arrive, without the delay imposed by polling.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号