AMQP Internal Library
Internal library for exchanging messages between services instantiated in the AWS environment.
The base used for the elaboration of the package was the PIKA library developed by the RabbitMQ team.
Installation
To use the library it is necessary to have Python3 installed on the machine and run the following command:
python3 -m pip install cosecurity-amqp-lib
Environment Variables File
AMQP_USERuser for connecting to RabbitMQAMQP_PASSWORDpassword for connecting to RabbitMQ[SERVICE_NAME]service name and respective service queue name, can be more than oneAMQP_SOCKET_TIMEOUTsocket connect timeout in secondsAMQP_HEARTBEATAMQP connection heartbeat timeout value for negotiation during connection tuning or callable which is invoked during connection tuning
if it is a local instance:
AMQP_HOSThost to connect to RabbitMQ, if localhost does not need to fill the port
if the connection is via Amazon MQ:
AMQP_BROKER_IDamqp id inside awsAWS_REGIONregion where amqp is allocated within aws
Consumers
Consumers are instances that monitor a specific queue, and if there is a change in the queue, they perform a certain action.
In this library a consumer can have more than one action/method, called primitive. In addition, each action will still have its default input set.
Each method that must be an action must be registered so that it can be triggered if there is a change in the directed queue.
Below is an example of how to create a consumer class:
from typing import Any, Dict
from cosecurity_amqp_lib.consumer import Consumer
class ConsumerExample(Consumer):
def __init__(self) -> None:
super().__init__(
name='example'
)
self.register(self.primitive_one)
self.register(self.primitive_two)
self.start()
def primitive_one(self, content:Dict[str, Any]) -> None:
print(content['hello'])
def primitive_two(self, content:Dict[str, Any]) -> None:
print(content['message'])
Producers
Producers are responsible for producing and/or posting new messages in consumer queues.
In the internal library the producers are called stub, I try their methods defined and typed based on what has already been defined as primitive in their consumer.
Below is an example of how to create a stub inside the library in the stub.py file:
class ExampleStub(Stub):
def __init__(self):
super().__init__(
destination='example'
)
def primitive_one(self) -> None:
self._send(
primitive='primitive_one',
content={
'hello': 'word'
}
)
def primitive_two(self, message:str) -> None:
self._send(
primitive='primitive_two',
content={
'message': message
}
)
Now, an example of how to use an already created stub and publish it in the library in Pypi:
from cosecurity_amqp_lib.stub import ExampleStub
example_stub = ExampleStub()
example_stub.primitive_one()
example_stub.primitive_two(message='Hello world!')
Additional arguments for queues
In the creation of the consumers it is possible to pass some additional configurations for the creation of the queue, these configurations can be found on the official RabbitMQ website. Below is a representation of how to pass an additional argument:
class ConsumerExample(Consumer):
def __init__(self) -> None:
[...]
self.start(
arguments={
'x-queue-mode': 'lazy'
}
)
Example
In the example/simple
folder we have a real case example of a stub sending an string to a consumer.
Metadata
Release files for cosecurity-amqp-lib 1.0.22
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| cosecurity-amqp-lib-1.0.22.tar.gz | 6.4 kB | Without provenance | Details for cosecurity-amqp-lib-1.0.22.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| cosecurity_amqp_lib-1.0.22-py3-none-any.whl | Python 3 | none | any | Details for cosecurity_amqp_lib-1.0.22-py3-none-any.whl |
Total release size: 14.5 kB
Release files / cosecurity-amqp-lib-1.0.22.tar.gz
| Download URL | cosecurity-amqp-lib-1.0.22.tar.gz |
|---|---|
| Size | 6.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
db9744e5fc0563d55f5644abf7ea9be5fc1b84023ce694cd7e7ef117bf5f75c0
|
|
BLAKE2b-256 checksum How to use checksums |
d1761bf9b3101a8c33cce0ad64473d74b566ef72c77824c2e0a0d0de896ae7c9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Release files / cosecurity_amqp_lib-1.0.22-py3-none-any.whl
| Download URL | cosecurity_amqp_lib-1.0.22-py3-none-any.whl |
|---|---|
| Size | 8.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5d15fef8fce7ffea366d0b5f61d9ece05669af4cdee189f1a9411463ce4a21cb
|
|
BLAKE2b-256 checksum How to use checksums |
af6ab6c74280beadf3cd7ea4deb4f4a517cd11edb21f329313147f9b8d6faa90
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.9.13
|
Security for cosecurity-amqp-lib 1.0.22
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.