# tyo-mq-client-python
A TYO-MQ python client for TYO-MQ server.
## TYO-MQ server
please refer to [TYO-MQ Server]{https://github.com/tyolab/tyo-mq}/server.js
In short, TYO-MQ is an implementation of pub/sub message distribution service using socket.io(webscoket).
### Creating a messaging server
```javascript
var MessageServer = require("tyo-mq").server;
var mq = new MessageServer();
mq.start();
```
### Creating a message producer and consumer
```python
from tyo_mq_client.message_queue import MessageQueue
from tyo_mq_client.socket import Socket
from tyo_mq_client.logger import Logger
from tyo_mq_client.constants import Constants
subscriber = None
producer = None
ready = [False, False]
mq = MessageQueue()
producer = mq.createPublisher("TYO Lab")
# A producer can be also a consumer
subscriber = producer
def on_message_published(message):
print ("received message" + json.dumps(message))
os._exit(1)
def check ():
if (ready[0] and ready[1]):
producer.produce({"message": "Hello World"})
def subscriber_on_connect () :
Logger.log("Subscriber is connected")
ready[0] = True
subscriber.subscribe(producer.name, Constants.EVENT_DEFAULT, on_message_published, False)
def on_subscription (data) :
print ("received subscription")
producer.produce({"message1": "Hello World"})
producer.on('test', on_message_published)
producer.socket.emit('test')
producer.produce({"message2": "Hello World"}, producer.eventDefault, Constants.METHOD_BROADCAST)
def producer_on_connect () :
subscriber_on_connect()
Logger.log("Producer is connected")
ready[1] = True
producer.on_subscription_listener = on_subscription
producer.on_subscriber_lost(on_subscriber_lost)
def on_subscriber_lost (data):
message = json.dumps(data)
Logger.log('Informed that connection with a subscriber (' + message["consumer"] + ') was lost')
producer.add_on_connect_listener(producer_on_connect)
producer.connect(-1)
```
## Publish tyo-mq-client-python to pypi
```bash
python setup.py sdist
twine upload dist/*
```
## Maintainer
[Eric Tang](https://twitter.com/_e_tang) @ [TYO LAB](http://tyo.com.au)
Raw data
{
"_id": null,
"home_page": "https://github.com/tyolab/tyo-mq-client-python.git",
"name": "tyo-mq-client",
"maintainer": null,
"docs_url": null,
"requires_python": null,
"maintainer_email": null,
"keywords": "tyo-mq socket.io node.js pub/sub publisher/subscriber",
"author": "Eric Tang",
"author_email": "eric@tyo.com.au",
"download_url": "https://files.pythonhosted.org/packages/d2/c3/64391922d9c196c2ce7c643e2998f9accdc618b67e044f1e45ec453fd9e1/tyo-mq-client-0.0.7.tar.gz",
"platform": null,
"description": "# tyo-mq-client-python\nA TYO-MQ python client for TYO-MQ server.\n\n## TYO-MQ server \nplease refer to [TYO-MQ Server]{https://github.com/tyolab/tyo-mq}/server.js\n\nIn short, TYO-MQ is an implementation of pub/sub message distribution service using socket.io(webscoket).\n\n### Creating a messaging server\n\n```javascript\nvar MessageServer = require(\"tyo-mq\").server;\n\nvar mq = new MessageServer();\nmq.start();\n```\n\n### Creating a message producer and consumer\n\n```python\nfrom tyo_mq_client.message_queue import MessageQueue\nfrom tyo_mq_client.socket import Socket\nfrom tyo_mq_client.logger import Logger\nfrom tyo_mq_client.constants import Constants\n\nsubscriber = None\nproducer = None\nready = [False, False]\n\nmq = MessageQueue()\n\nproducer = mq.createPublisher(\"TYO Lab\")\n\n# A producer can be also a consumer\nsubscriber = producer\n\ndef on_message_published(message):\n print (\"received message\" + json.dumps(message))\n os._exit(1)\n\ndef check ():\n if (ready[0] and ready[1]):\n producer.produce({\"message\": \"Hello World\"})\n\ndef subscriber_on_connect () :\n Logger.log(\"Subscriber is connected\")\n ready[0] = True\n subscriber.subscribe(producer.name, Constants.EVENT_DEFAULT, on_message_published, False)\n \ndef on_subscription (data) :\n print (\"received subscription\")\n producer.produce({\"message1\": \"Hello World\"})\n producer.on('test', on_message_published)\n producer.socket.emit('test')\n producer.produce({\"message2\": \"Hello World\"}, producer.eventDefault, Constants.METHOD_BROADCAST)\n\ndef producer_on_connect () :\n subscriber_on_connect() \n\n Logger.log(\"Producer is connected\")\n ready[1] = True\n producer.on_subscription_listener = on_subscription\n producer.on_subscriber_lost(on_subscriber_lost)\n\ndef on_subscriber_lost (data):\n message = json.dumps(data)\n Logger.log('Informed that connection with a subscriber (' + message[\"consumer\"] + ') was lost')\n\nproducer.add_on_connect_listener(producer_on_connect)\nproducer.connect(-1)\n\n\n```\n\n## Publish tyo-mq-client-python to pypi\n\n```bash\npython setup.py sdist\ntwine upload dist/*\n```\n\n## Maintainer\n\n[Eric Tang](https://twitter.com/_e_tang) @ [TYO LAB](http://tyo.com.au)\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "A tyo-mq client library",
"version": "0.0.7",
"project_urls": {
"Homepage": "https://github.com/tyolab/tyo-mq-client-python.git"
},
"split_keywords": [
"tyo-mq",
"socket.io",
"node.js",
"pub/sub",
"publisher/subscriber"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "d2c364391922d9c196c2ce7c643e2998f9accdc618b67e044f1e45ec453fd9e1",
"md5": "0b6d4c0cf8a3ed37931e213a1c32c958",
"sha256": "6740d70f2d6e017f7c42cdbda99905845e1e3e070d8e94a4db5c5c9b011a9df5"
},
"downloads": -1,
"filename": "tyo-mq-client-0.0.7.tar.gz",
"has_sig": false,
"md5_digest": "0b6d4c0cf8a3ed37931e213a1c32c958",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 9529,
"upload_time": "2024-07-12T08:34:58",
"upload_time_iso_8601": "2024-07-12T08:34:58.053116Z",
"url": "https://files.pythonhosted.org/packages/d2/c3/64391922d9c196c2ce7c643e2998f9accdc618b67e044f1e45ec453fd9e1/tyo-mq-client-0.0.7.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-07-12 08:34:58",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "tyolab",
"github_project": "tyo-mq-client-python",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"requirements": [
{
"name": "python-socketio",
"specs": [
[
"==",
"4.6.1"
]
]
},
{
"name": "invisibleroads-macros",
"specs": [
[
"==",
"0.9.4.4"
]
]
}
],
"lcname": "tyo-mq-client"
}