neon-mq-connector


Nameneon-mq-connector JSON
Version 0.8.0 PyPI version JSON
download
home_pagehttps://github.com/NeonGeckoCom/neon_mq_connector
SummaryMQ Connector for Neon Modules
upload_time2025-02-04 17:30:36
maintainerNone
docs_urlNone
authorNeonGecko
requires_python>=3.8
licenseBSD-3-Clause
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # 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`).

### Asynchronous Consumers
By default, async-based consumers handling based on `pika.SelectConnection` will
be used

#### Override use of async consumers

There are a few methods to disable use of async consumers/subscribers.

1. To disable async consumers for a particular class/object, 
set the class-attribute `async_consumers_enabled` to `False`:

   ```python
   from neon_mq_connector import MQConnector
   
   class MQConnectorChild(MQConnector):
      async_consumers_enabled = False
   ```
2. To disable the use of async consumers at runtime, set the `MQ_ASYNC_CONSUMERS`
envvar to `False`

   ```shell
   export MQ_ASYNC_CONSUMERS=false
   ```

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/NeonGeckoCom/neon_mq_connector",
    "name": "neon-mq-connector",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "NeonGecko",
    "author_email": "developers@neon.ai",
    "download_url": "https://files.pythonhosted.org/packages/d3/68/bc1127b65c38fbb4074f7b28309e53f0240c43c4f03c52bcb1732e59910a/neon_mq_connector-0.8.0.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\n### Asynchronous Consumers\nBy default, async-based consumers handling based on `pika.SelectConnection` will\nbe used\n\n#### Override use of async consumers\n\nThere are a few methods to disable use of async consumers/subscribers.\n\n1. To disable async consumers for a particular class/object, \nset the class-attribute `async_consumers_enabled` to `False`:\n\n   ```python\n   from neon_mq_connector import MQConnector\n   \n   class MQConnectorChild(MQConnector):\n      async_consumers_enabled = False\n   ```\n2. To disable the use of async consumers at runtime, set the `MQ_ASYNC_CONSUMERS`\nenvvar to `False`\n\n   ```shell\n   export MQ_ASYNC_CONSUMERS=false\n   ```\n",
    "bugtrack_url": null,
    "license": "BSD-3-Clause",
    "summary": "MQ Connector for Neon Modules",
    "version": "0.8.0",
    "project_urls": {
        "Homepage": "https://github.com/NeonGeckoCom/neon_mq_connector"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "b29e2c69e1d940fa3fa2f9abd454279b54b512e5bda92cfea5a53ef3ce00afa7",
                "md5": "a4ec450fc569b42e23e167660ea9a3e6",
                "sha256": "9e8a6b15cc6f807227087de2111112ea66c2063717b465fc62469fe333100c0a"
            },
            "downloads": -1,
            "filename": "neon_mq_connector-0.8.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "a4ec450fc569b42e23e167660ea9a3e6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 52798,
            "upload_time": "2025-02-04T17:30:35",
            "upload_time_iso_8601": "2025-02-04T17:30:35.370801Z",
            "url": "https://files.pythonhosted.org/packages/b2/9e/2c69e1d940fa3fa2f9abd454279b54b512e5bda92cfea5a53ef3ce00afa7/neon_mq_connector-0.8.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "d368bc1127b65c38fbb4074f7b28309e53f0240c43c4f03c52bcb1732e59910a",
                "md5": "a4d8d6817c981334bda7bc78d90293a7",
                "sha256": "c7480b580f56e3d19edbb4705c544422fc9d8bffc7036fca7290f18bdbea7e5e"
            },
            "downloads": -1,
            "filename": "neon_mq_connector-0.8.0.tar.gz",
            "has_sig": false,
            "md5_digest": "a4d8d6817c981334bda7bc78d90293a7",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 30365,
            "upload_time": "2025-02-04T17:30:36",
            "upload_time_iso_8601": "2025-02-04T17:30:36.758093Z",
            "url": "https://files.pythonhosted.org/packages/d3/68/bc1127b65c38fbb4074f7b28309e53f0240c43c4f03c52bcb1732e59910a/neon_mq_connector-0.8.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-02-04 17:30:36",
    "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"
}
        
Elapsed time: 0.52838s