# Neon MQ Connector
The Neon MQ Connector is an MQ interface for microservices.
## Configuration
By default, this package will use [ovos-config](https://github.com/openvoiceos/ovos-config)
to read default configuration. In general, configuration should be passed to the
`MQConnector` object at init.
### Legacy Configuration
A global configuration for the MQ Connector may be specified at `~/.config/neon/mq_config.json`. This configuration file
may contain the following keys:
- `server`: The hostname or IP address of the MQ server to connect to. If left blank, this defaults to `"localhost"`
- `port`: The port used by the MQ server. If left blank, this defaults to `5672`
- `users`: A mapping of service names to credentials. Note that not all users will have permissions required to access each service.
```json
{
"server": "localhost",
"port": 5672,
"users": {
"<service_name>": {
"username": "<username>",
"password": "<password>"
}
}
}
```
## Services
The `MQConnector` class should be extended by a class providing some specific service.
Service classes will specify the following parameters.
- `service_name`: Name of the service, used to identify credentials in configuration
- `vhost`: Virtual host to connect to; messages are all constrained to this namespace.
- `consumers`: Dict of names to `ConsumerThread` objects. A `ConsumerThread` will accept a connection to a particular `connection`, a `queue`, and a `callback_func`
- `connection`: MQ connection to the `vhost` specified above.
- `queue`: Queue to monitor within the `vhost`. A `vhost` may handle multiple queues.
- `callback_func`: Function to call when a message arrives in the `queue`
### Callback Functions
A callback function should have the following signature:
```python
def handle_api_input(self,
channel: pika.channel.Channel,
method: pika.spec.Basic.Return,
properties: pika.spec.BasicProperties,
body: bytes):
"""
Handles input requests from MQ to Neon API
:param channel: MQ channel object (pika.channel.Channel)
:param method: MQ return method (pika.spec.Basic.Return)
:param properties: MQ properties (pika.spec.BasicProperties)
:param body: request body (bytes)
"""
```
Generally, `body` should be decoded into a `dict`, and that `dict` should contain `message_id`. The `message_id` should
be included in the body of any response to associate the response to the request.
A response may be sent via:
```python
channel.queue_declare(queue='<queue>')
channel.basic_publish(exchange='',
routing_key='<queue>',
body=<data>,
properties=pika.BasicProperties(expiration='1000')
)
```
Where `<queue>` is the queue to which the response will be published, and `data` is a `bytes` response (generally a `base64`-encoded `dict`).
Raw data
{
"_id": null,
"home_page": "https://github.com/NeonGeckoCom/neon_mq_connector",
"name": "neon-mq-connector",
"maintainer": "",
"docs_url": null,
"requires_python": "",
"maintainer_email": "",
"keywords": "",
"author": "NeonGecko",
"author_email": "developers@neon.ai",
"download_url": "https://files.pythonhosted.org/packages/db/3e/c1a0047dce99bc95bac46bae459d025e77568d23f56c2395fa59edccfa0a/neon_mq_connector-0.7.1.tar.gz",
"platform": null,
"description": "# Neon MQ Connector\nThe Neon MQ Connector is an MQ interface for microservices.\n\n## Configuration\nBy default, this package will use [ovos-config](https://github.com/openvoiceos/ovos-config)\nto read default configuration. In general, configuration should be passed to the\n`MQConnector` object at init.\n\n### Legacy Configuration\nA global configuration for the MQ Connector may be specified at `~/.config/neon/mq_config.json`. This configuration file \nmay contain the following keys:\n - `server`: The hostname or IP address of the MQ server to connect to. If left blank, this defaults to `\"localhost\"`\n - `port`: The port used by the MQ server. If left blank, this defaults to `5672`\n - `users`: A mapping of service names to credentials. Note that not all users will have permissions required to access each service.\n\n```json\n{\n \"server\": \"localhost\",\n \"port\": 5672,\n \"users\": {\n \"<service_name>\": {\n \"username\": \"<username>\",\n \"password\": \"<password>\"\n }\n }\n}\n```\n\n## Services\nThe `MQConnector` class should be extended by a class providing some specific service.\nService classes will specify the following parameters.\n - `service_name`: Name of the service, used to identify credentials in configuration\n - `vhost`: Virtual host to connect to; messages are all constrained to this namespace.\n - `consumers`: Dict of names to `ConsumerThread` objects. A `ConsumerThread` will accept a connection to a particular `connection`, a `queue`, and a `callback_func`\n - `connection`: MQ connection to the `vhost` specified above.\n - `queue`: Queue to monitor within the `vhost`. A `vhost` may handle multiple queues.\n - `callback_func`: Function to call when a message arrives in the `queue`\n\n### Callback Functions\nA callback function should have the following signature:\n```python\ndef handle_api_input(self,\n channel: pika.channel.Channel,\n method: pika.spec.Basic.Return,\n properties: pika.spec.BasicProperties,\n body: bytes):\n \"\"\"\n Handles input requests from MQ to Neon API\n\n :param channel: MQ channel object (pika.channel.Channel)\n :param method: MQ return method (pika.spec.Basic.Return)\n :param properties: MQ properties (pika.spec.BasicProperties)\n :param body: request body (bytes)\n \"\"\"\n```\nGenerally, `body` should be decoded into a `dict`, and that `dict` should contain `message_id`. The `message_id` should \nbe included in the body of any response to associate the response to the request.\nA response may be sent via:\n```python\n channel.queue_declare(queue='<queue>')\n\n channel.basic_publish(exchange='',\n routing_key='<queue>',\n body=<data>,\n properties=pika.BasicProperties(expiration='1000')\n )\n```\nWhere `<queue>` is the queue to which the response will be published, and `data` is a `bytes` response (generally a `base64`-encoded `dict`).\n",
"bugtrack_url": null,
"license": "BSD-3-Clause",
"summary": "MQ Connector for Neon Modules",
"version": "0.7.1",
"project_urls": {
"Homepage": "https://github.com/NeonGeckoCom/neon_mq_connector"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "ce00913c4a39d984f05f0dfb73b9ed9f17b75fb31e2557ab0b95b6787ef17ace",
"md5": "632aacbd9cd2d021f964c8f0d0404f5f",
"sha256": "3a4e9746fad996ec67213dee81ad97262af7d0f50cc3fff9d1ff5e0d5f2e4524"
},
"downloads": -1,
"filename": "neon_mq_connector-0.7.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "632aacbd9cd2d021f964c8f0d0404f5f",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": null,
"size": 26651,
"upload_time": "2023-12-11T20:56:45",
"upload_time_iso_8601": "2023-12-11T20:56:45.482177Z",
"url": "https://files.pythonhosted.org/packages/ce/00/913c4a39d984f05f0dfb73b9ed9f17b75fb31e2557ab0b95b6787ef17ace/neon_mq_connector-0.7.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "db3ec1a0047dce99bc95bac46bae459d025e77568d23f56c2395fa59edccfa0a",
"md5": "f6f923d770bb00084fa4aab8373ab05c",
"sha256": "d2d78183396156a9eed094e4d533fbdd3e5dd06bde2d1ea06732bd217deba724"
},
"downloads": -1,
"filename": "neon_mq_connector-0.7.1.tar.gz",
"has_sig": false,
"md5_digest": "f6f923d770bb00084fa4aab8373ab05c",
"packagetype": "sdist",
"python_version": "source",
"requires_python": null,
"size": 18082,
"upload_time": "2023-12-11T20:56:48",
"upload_time_iso_8601": "2023-12-11T20:56:48.309224Z",
"url": "https://files.pythonhosted.org/packages/db/3e/c1a0047dce99bc95bac46bae459d025e77568d23f56c2395fa59edccfa0a/neon_mq_connector-0.7.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-12-11 20:56:48",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "NeonGeckoCom",
"github_project": "neon_mq_connector",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "neon-mq-connector"
}