MQ Connector for Neon Modules
Project description
Neon MQ Connector
The Neon MQ Connector is an MQ interface for microservices.
Configuration
By default, this package will use 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 to5672
users
: A mapping of service names to credentials. Note that not all users will have permissions required to access each service.
{
"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 configurationvhost
: Virtual host to connect to; messages are all constrained to this namespace.consumers
: Dict of names toConsumerThread
objects. AConsumerThread
will accept a connection to a particularconnection
, aqueue
, and acallback_func
connection
: MQ connection to thevhost
specified above.queue
: Queue to monitor within thevhost
. Avhost
may handle multiple queues.callback_func
: Function to call when a message arrives in thequeue
Callback Functions
A callback function should have the following signature:
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:
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
).
[BETA] Asynchronous Consumers
Now there is a support for async-based consumers handling based on aio-pika
API.
Installation
To install async dependencies, run installation with [aio]
extra:
pip install neon-mq-connector[aio]
Enabling in a code
When declaring the consumer/subscriber instances, specify async_consumer
param like follows:
register_consumer(name="some_consumer",
...
async_consumer=True,)
register_subscriber(name="some_subscriber",
...
async_consumer=True,)
To set creation of async consumers/subscribers globally, set the class-attribute async_consumers_enabled
to True:
from neon_mq_connector import MQConnector
class MQConnectorChild(MQConnector):
async_consumers_enabled = True
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file neon_mq_connector-0.7.2a4.tar.gz
.
File metadata
- Download URL: neon_mq_connector-0.7.2a4.tar.gz
- Upload date:
- Size: 20.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | da4f09841702991ff19599b8c7092257e2bfcbaf981a5c54a7b949de0f13a47d |
|
MD5 | 7d75de862c6a082cc288ab15e491ae3c |
|
BLAKE2b-256 | c10b5def919e0b4ead3d35c93afc15690f918e7add58906579a07c452d0e2efb |
File details
Details for the file neon_mq_connector-0.7.2a4-py3-none-any.whl
.
File metadata
- Download URL: neon_mq_connector-0.7.2a4-py3-none-any.whl
- Upload date:
- Size: 30.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.12.7
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 9e894697c6f355775bc164d3062bc6a658600df4f84af858fdde35672d9f86ed |
|
MD5 | 98d73b4ef701a639df606c10136d0731 |
|
BLAKE2b-256 | 0674b2504a02c486f10e867f62fe33ab29834263e8078c87af40bb2e016901d2 |