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")
To use, replace:
from carrot.connection import BrokerConnection
from carrot.messaging import Publisher, Consumer
with:
from kombu.connection import BrokerConnection
from kombu.compat import Publisher, Consumer
No longer have to specify the channel for each operation,
but instead do:
>>> exchange = Exchange("foo", "direct", channel=channel)
>>> exchange.declare()
instead of:
>>> exchange.declare(channel)
As the Exchange/Binding classes is also the specification of an
exchange/binding these instances can be unbound, meaning they
are not associated with a channel. An entity can be bound
the a channel at any time, usually this means creating a copy
of the instance so the original is not affected::
>>> exchange = Exchange("foo", "direct")
>>> bound_exchange = exchange.bind(channel)
>>> bound_exchange.declare()
>>> bound_exchange.delete()
>>> assert exchange is not bound_exchange