Send and receive messages without thinking about it
Project description
Morp
Send messages without really thinking about it.
Installation
Use pip to install the latest stable version:
pip install morp
To install the development version:
pip install -U "git+https://github.com/Jaymon/morp#egg=morp"
1 Minute Getting Started
Send and receive a Foo
message.
First, let's set our environment variable to use the dropfile (local files suitable for development and prototyping) interface:
export MORP_DSN=dropfile:///${TMPDIR}
Second, let's create a Foo
Message class:
from morp import Message
class Foo(Message):
def target(self):
# this will be run when a Foo message is consumed
print(self.fields)
Third, let's start our message consumer in a shell:
$ morp
Fourth, let's send a message:
f = Foo()
f.some_field = 1
f.some_other_field = 2
f.send()
That's it!
DSN
You configure your connection using a dsn in the form:
InterfaceName://username:password@host:port/path?param1=value1¶m2=value2
So, to connect to Amazon SQS, you would do:
sqs://${AWS_ACCESS_KEY_ID}:${AWS_SECRET_ACCESS_KEY}@
You can also override some default values like region
and read_lock
:
sqs://${AWS_ACCESS_KEY_ID}:${AWS_SECRET_ACCESS_KEY}@?region=${AWS_DEFAULT_REGION}&read_lock=120
Encryption
If you would like to encrypt all your messages, you can pass in a key
argument to your dsn and Morp will take care of encrypting and decrypting the messages for you transparently.
Let's just modify our dsn to pass in our key:
sqs://${AWS_ACCESS_KEY_ID}:${AWS_SECRET_ACCESS_KEY}@?key=jy4XWRuEsrH98RD2VeLG62uVLCPWpdUh
That's it, every message will now be encrypted on send and decrypted on receive. If you're using SQS you can also use Amazon's key management service to handle the encryption for you.
Environment configuration
MORP_DISABLED
By default every message will be sent, if you just want to test functionality without actually sending the message you can set this environment variable to turn off all the queues.
MORP_DISABLED = 1 # queue is off
MORP_DISABLED = 0 # queue is on
MORP_PREFIX
If you would like to have your queue names prefixed with something (eg, prod
or dev
) then you can set this environment variable and it will be prefixed to the queue name.
MORP_DSN
Set this environment variable with your connection dsn so morp can automatically configure itself when the interface is first requested.
FAQ
I would like to have multiple queues
By default, Morp will send any message from any morp.Message
derived class to Message.get_name()
, you can override this behavior by giving your child class a .name
attribute:
from morp import Message
class childMsg(Message):
name = "custom-queue-name"
Now, you can have the Morp command line consumer read from that queue instead:
$ morp custom-queue-name
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
File details
Details for the file morp-5.2.2.tar.gz
.
File metadata
- Download URL: morp-5.2.2.tar.gz
- Upload date:
- Size: 20.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.10.10
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 656622cfd126bd805569b435645586bb5365e1406072346b8a5dd3252515fe7e |
|
MD5 | 4a802f8b50a6f732d5a0a2bcf7052098 |
|
BLAKE2b-256 | b24b40c24f2a01cbba02eb24f091d278846cf37c5912d39f93907ea88d1476e4 |