Amqpx.Basic.publish

You're seeing just the function publish, go back to Amqpx.Basic module for more information.
Link to this function

publish(channel, exchange, routing_key, payload, options \\ [])

Specs

publish(Amqpx.Channel.t(), exchange(), routing_key(), payload(), keyword()) ::
  :ok | error()

Publishes a message to an Exchange.

This method publishes a message to a specific exchange. The message will be routed to queues as defined by the exchange configuration and distributed to any subscribers.

The parameter exchange specifies the name of the exchange to publish to. If set to empty string, it publishes to the default exchange. The routing_key parameter specifies the routing key for the message.

The payload parameter specifies the message content as a binary.

In addition to the previous parameters, the following options can be used:

Options

  • :mandatory - If set, returns an error if the broker can't route the message to a queue (default false);
  • :immediate - If set, returns an error if the broker can't deliver the message to a consumer immediately (default false);
  • :content_type - MIME Content type;
  • :content_encoding - MIME Content encoding;
  • :headers - Message headers of type Amqpx.arguments/0. Can be used with headers Exchanges;
  • :persistent - If set, uses persistent delivery mode. Messages marked as persistent that are delivered to durable queues will be logged to disk;
  • :correlation_id - application correlation identifier;
  • :priority - message priority, ranging from 0 to 9;
  • :reply_to - name of the reply queue;
  • :expiration - how long the message is valid (in milliseconds);
  • :message_id - message identifier;
  • :timestamp - timestamp associated with this message (epoch time);
  • :type - message type as a string;
  • :user_id - creating user ID. RabbitMQ will validate this against the active connection user;
  • :app_id - publishing application ID.

Examples

iex> Amqpx.Basic.publish chan, "my_exchange", "my_routing_key", "Hello World!", persistent: true
:ok