Topic

The Topic class for Topic publications.

class amqppy.publisher.Topic(broker)[source]

This class creates a connection to the message broker and provides a method to publish messages on one topic also known as routing_key in AMQP terms. The class instance will create on single connection to the broker for all the topic published.

Parameters:broker (str) – The URL for connection to RabbitMQ. Eg: ‘amqp://serviceuser:password@rabbit.host:5672//’
publish(exchange, routing_key, body, headers=None, persistent=True)[source]

Publish a message to the given exchange and a routing key.

Parameters:
  • exchange (str) – The exchange you want to publish the message.
  • rounting_key (str) – The rounting key to bind on
  • body (str) – The body of the message you want to publish. It should be of type unicode or string encoded with UTF-8.
  • headers (dict) – Message headers.
  • persistent (bool) – Makes message persistent. The message would not be lost after RabbitMQ restart.