carrot.objects.
BaseMessageSerializer
(message: carrot.objects.Message)¶A class that defines how to convert a RabbitMQ message into an executable python function from your Django project, and back again
Parameters: | message (Message) – the RabbitMQ message |
---|
body
() → str¶Returns the content to be added to the RabbitMQ message body
By default, this implementation returns a simple dict in the following format:
{
'args': ('tuple', 'of', 'positional', 'arguments'),
'kwargs': {
'keyword1': 'value',
'keyword2': True
}
}
get_task
(properties: pika.spec.BasicProperties, body: bytes) → Callable¶Identifies the python function to be executed from the content of the RabbitMQ message. By default, Carrot returns the value of the self.type_header header in the properties.
Once this string has been found, carrot uses importlib to return a callable python function.
properties
() → dict¶Returns a dict from which a pika.BasicProperties
object can be created
In this implementation, the following is returned: - headers - content message_type - priority - message id - message message_type
publish
(connection: pika.adapters.blocking_connection.BlockingConnection, channel: pika.channel.Channel) → None¶Publishes a message to the channel
publish_kwargs
() → dict¶Returns a dictionary of keyword arguments to be passed to channel.basic_publish. In this implementation, the exchange, routing key and message body are returned
serialize_arguments
(body: str) → Tuple[tuple, dict]¶Extracts positional and keyword arguments to be sent to a function from the message body
carrot.objects.
DefaultMessageSerializer
(message: carrot.objects.Message)¶carrot.objects.
Message
(task: str, virtual_host: carrot.objects.VirtualHost = None, queue: str = 'default', routing_key: str = None, exchange: str = '', priority: int = 0, task_args: tuple = (), task_kwargs: Union[str, dict] = None)¶A message to publish to RabbitMQ. Takes the following parameters:
Note
Your RabbitMQ queue must support message priority for the priority parameter to have any affect. You need to define the x-max-priority header when creating your RabbitMQ queue to do this. See Priority Queue Support for more details. Carrot applies a maximum priority of 255 by default to all queues it creates automatically.
Warning
You should not attempt to create instances of this object yourself. You should use the
carrot.utilities.create_msg()
function instead
connection_channel
¶Gets or creates the queue, and returns a tuple containing the object’s VirtualHost’s blocking connection, and its channel
publish
(pika_log_level: int = 40) → Any¶Publishes the message to RabbitMQ queue and creates a MessageLog object so the progress of the task can be tracked in the Django project’s database