MQ Connector for Neon Modules
Project description
Neon MQ Connector
The Neon MQ Connector is an MQ interface for microservices.
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
).
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 Distributions
Built Distribution
Hashes for neon_mq_connector-0.5.2a1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | b58c463767d3f10f0db25b6b4fc8bd7b501099de43f2217a252eeebd13a878f3 |
|
MD5 | 2bcd51f3a0a21854d5dc71efc6104bda |
|
BLAKE2b-256 | 5ccb9ed691ce2c01ba8a6fcfbded14ab6f13b4fd03d3bb43dd879744cb3ebed9 |