Kombu.Transport.Redis.Channel (Kombu v0.1.0)

Copy Markdown View Source

Redis virtual channel (kombu.transport.redis.Channel).

Implements Kombu's Redis broker protocol:

  • Priority queues (priority_steps = [0, 3, 6, 9]) with  (<<6, 22>>) separator
  • Exchange binding sets (_kombu.binding.<exchange>, _kombu.binding_permanent.<exchange>, _kombu.binding_deadlines)
  • Fanout Pub/Sub (/{db}.<exchange>)
  • Ack emulation via Kombu.Transport.Redis.QoS (unacked, unacked_index, unacked_mutex)
  • Queue expiration (x-expires) and binding deadline refresh/sweep Lua scripts
  • Batched publishing via Kombu.Transport.Redis.PublishBatch

Summary

Functions

Returns a specification to start this module under a supervisor.

Restores a raw message payload to its destination queue(s) in Redis, marking redelivered = true. If leftmost is true, pushes via LPUSH; otherwise pushes via RPUSH (matching redis.py).

Determines the exchange type for exchange.

Returns PEXPIRE commands for all priority keys of queue if x-expires is set.

Pops a message from queue by checking priority buckets [0, 3, 6, 9] in order via RPOP. Returns {:ok, raw_message_map} or :empty.

Returns the Pub/Sub topic for publishing to a fanout exchange.

Returns the Pub/Sub topic pattern for subscribing to fanout queue.

Fetches the routing table [{routing_key, pattern, queue}] for exchange from Redis.

Checks whether any priority list for queue exists in Redis (EXISTS pipeline).

Looks up matching destination queues for (exchange, routing_key) by querying Redis SMEMBERS.

Looks up matching destination queues for (exchange, routing_key) given table.

Computes the clamped message priority for queue, respecting x-max-priority if configured.

Creates a %Kombu.Transport.Redis.Channel{} state struct directly (useful in unit tests).

Maps an integer priority n (0..9) to its priority step bucket ([0, 3, 6, 9]).

Purges all priority lists for queue (LLEN + DEL pipeline) and returns the number of removed messages.

Pushes message (raw map) into queue at its priority bucket in Redis.

Publishes a fanout message (raw map) to the Redis Pub/Sub topic for exchange.

Returns the Redis list key for queue at priority pri. Priority 0 uses queue; non-zero step uses "#{queue}\x06\x16#{step}".

Returns the total length of queue across all priority steps (LLEN pipeline).

Strips any <pri> suffix from a Redis queue key.

Types

t()

@type t() :: %Kombu.Transport.Redis.Channel{
  ack_emulation: term(),
  active_fanout_queues: term(),
  active_queues: term(),
  auto_delete_queues: term(),
  binding_expiry_refreshed_at: term(),
  bindings_swept_at: term(),
  body_encoding: term(),
  broker_state: term(),
  channel_id: term(),
  client: term(),
  closed: term(),
  consumers: term(),
  deadletter_queue: term(),
  do_restore: term(),
  expires: term(),
  fanout_buffer: term(),
  fanout_patterns: term(),
  fanout_prefix: term(),
  fanout_queues: term(),
  fanout_to_queue: term(),
  global_keyprefix: term(),
  keyprefix_binding_deadlines: term(),
  keyprefix_binding_permanent: term(),
  keyprefix_fanout: term(),
  keyprefix_queue: term(),
  max_priorities: term(),
  no_ack_consumers: term(),
  priority_steps: term(),
  qos: term(),
  queue_cycle: term(),
  queue_order_strategy: term(),
  sep: term(),
  virtual_host: term()
}

Functions

child_spec(init_arg)

Returns a specification to start this module under a supervisor.

See Supervisor.

default_priority_steps()

do_restore_message(state, payload, exchange, routing_key, leftmost \\ false)

Restores a raw message payload to its destination queue(s) in Redis, marking redelivered = true. If leftmost is true, pushes via LPUSH; otherwise pushes via RPUSH (matching redis.py).

exchange_type(state, exchange)

Determines the exchange type for exchange.

expire_commands_for_queue(state, queue)

Returns PEXPIRE commands for all priority keys of queue if x-expires is set.

get(state, queue)

Pops a message from queue by checking priority buckets [0, 3, 6, 9] in order via RPOP. Returns {:ok, raw_message_map} or :empty.

get_publish_topic(state, exchange, routing_key \\ "")

Returns the Pub/Sub topic for publishing to a fanout exchange.

get_subscribe_topic(state, queue)

Returns the Pub/Sub topic pattern for subscribing to fanout queue.

get_table(state, exchange)

Fetches the routing table [{routing_key, pattern, queue}] for exchange from Redis.

has_queue?(state, queue)

Checks whether any priority list for queue exists in Redis (EXISTS pipeline).

lookup(state, exchange, routing_key, default \\ nil)

Looks up matching destination queues for (exchange, routing_key) by querying Redis SMEMBERS.

lookup_with_table(state, exchange, routing_key, table, default \\ nil)

Looks up matching destination queues for (exchange, routing_key) given table.

message_priority_for_queue(state, message, queue)

Computes the clamped message priority for queue, respecting x-max-priority if configured.

new_state(opts \\ [])

Creates a %Kombu.Transport.Redis.Channel{} state struct directly (useful in unit tests).

priority(steps, n)

@spec priority(t() | [integer()], integer()) :: integer()

Maps an integer priority n (0..9) to its priority step bucket ([0, 3, 6, 9]).

purge(state, queue)

Purges all priority lists for queue (LLEN + DEL pipeline) and returns the number of removed messages.

put(state, queue, message)

Pushes message (raw map) into queue at its priority bucket in Redis.

put_fanout(state, exchange, message, routing_key \\ "")

Publishes a fanout message (raw map) to the Redis Pub/Sub topic for exchange.

q_for_pri(steps, queue, pri)

@spec q_for_pri(t() | [integer()], String.t(), integer()) :: String.t()

Returns the Redis list key for queue at priority pri. Priority 0 uses queue; non-zero step uses "#{queue}\x06\x16#{step}".

sep()

size(state, queue)

Returns the total length of queue across all priority steps (LLEN pipeline).

start_link(opts \\ [])

unq_for_pri(queue_key)

@spec unq_for_pri(String.t()) :: String.t()

Strips any <pri> suffix from a Redis queue key.