Utilities#
- yapw.util.json_dumps(message)[source]#
Serialize a Python object to JSON formatted bytes.
Uses orjson if available.
- yapw.util.default_decode(body, content_type)[source]#
If the content type is “application/json”, deserializes the JSON formatted bytes to a Python object. Otherwise, returns the bytes (which the consumer callback can deserialize independently).
Uses orjson if available.
- yapw.util.default_encode(message, content_type)[source]#
Encode the decoded message to bytes.
If the content type is “application/json”, serialize the message to JSON formatted bytes.
If the message is a string, encode it to bytes.
If the message is bytes, return it.
Otherwise, serialize the message to its picked representation.
- yapw.util.basic_publish_kwargs(state, message, routing_key)[source]#
Prepare keyword arguments for
basic_publish
.
- yapw.util.basic_publish_debug_args(channel, message, keywords)[source]#
Prepare arguments for
logger.debug
related to publishing a message.- Parameters:
channel (Channel | BlockingChannel) – the channel from which to call
basic_publish
message (Any) – a decoded message
keywords (PublishKeywords) – keyword arguments for
basic_publish
- Returns:
arguments for
logger.debug
- Return type: