|
This is done by adding the "compression" header to messages.
Currently supported compression formats are: zlib and bzip2.
Custom compression formats can be added using kombu.compression.register::
>>> compression.register(encoder, decoder, content_type, aliases={})
e.g.::
>>> compression.register(lambda x: x.encode("zlib"),
... lambda x: x.decode("zlib"),
... "application/x-zlib",
... aliases=["zlib", "gzip"])
To enable compression you use the ``compression`` argument to
:meth:`Producer.publish`. When these messages are then consumed by
kombu they will be automatically decompressed, other clients need to
decompress them manually by looking at the ``compression`` header.
Example using zlib compression:
>>> producer.publish(message, serializer="json", compression="zlib")
Example using bzip2 compression:
>>> producer.publish(message, serializer="json", compression="bz2")
|