This document is for Kombu's development version, which can be significantly different from previous releases. Get the stable docs here: 5.3.

# Virtual AMQ Exchange Implementation - `kombu.transport.virtual.exchange`

Virtual AMQ Exchange.

Implementations of the standard exchanges defined by the AMQ protocol (excluding the headers exchange).

## Direct

class kombu.transport.virtual.exchange.DirectExchange(channel)

  Direct exchange.

  The direct exchange routes based on exact routing keys.

  deliver(message, exchange, routing_key, **kwargs)
  lookup(table, exchange, routing_key, default)

    Lookup all queues matching routing_key in exchange.

    Returns:

      str

    Return type:

      queue name, or ‘default’ if no queues matched.

  type = 'direct'

## Topic

class kombu.transport.virtual.exchange.TopicExchange(channel)

  Topic exchange.

  The topic exchange routes messages based on words separated by dots, using wildcard characters `*` (any single word), and `#` (one or more words).

  deliver(message, exchange, routing_key, **kwargs)
  key_to_pattern(rkey)

    Get the corresponding regex for any routing key.

  lookup(table, exchange, routing_key, default)

    Lookup all queues matching routing_key in exchange.

    Returns:

      str

    Return type:

      queue name, or ‘default’ if no queues matched.

  prepare_bind(queue, exchange, routing_key, arguments)

    Prepare queue-binding.

    Returns:

      Tuple[str, Pattern, str] – to be stored for bindings to this exchange.

    Return type:

      of (routing_key, regex, queue)

  type = 'topic'
  wildcards = {'#': '.*?', '*': '.*?[^\\.]'}

    map of wildcard to regex conversions

## Fanout

class kombu.transport.virtual.exchange.FanoutExchange(channel)

  Fanout exchange.

  The fanout exchange implements broadcast messaging by delivering copies of all messages to all queues bound to the exchange.

  To support fanout the virtual channel needs to store the table as shared state. This requires that the Channel.supports_fanout attribute is set to true, and the Channel._queue_bind and Channel.get_table methods are implemented.

  deliver(message, exchange, routing_key, **kwargs)
  lookup(table, exchange, routing_key, default)

    Lookup all queues matching routing_key in exchange.

    Returns:

      str

    Return type:

      queue name, or ‘default’ if no queues matched.

  type = 'fanout'

## Interface

class kombu.transport.virtual.exchange.ExchangeType(channel)

  Base class for exchanges.

  Implements the specifics for an exchange type.

  ### Arguments:

  > channel (ChannelT): AMQ Channel.

  equivalent(prev, exchange, type, durable, auto_delete, arguments)

    Return true if prev and exchange is equivalent.

  lookup(table, exchange, routing_key, default)

    Lookup all queues matching routing_key in exchange.

    Returns:

      str

    Return type:

      queue name, or ‘default’ if no queues matched.

  prepare_bind(queue, exchange, routing_key, arguments)

    Prepare queue-binding.

    Returns:

      Tuple[str, Pattern, str] – to be stored for bindings to this exchange.

    Return type:

      of (routing_key, regex, queue)

  type = None