Class: AMQP::Client::Exchange

Inherits:
Object
  • Object
show all
Defined in:
lib/amqp/client/exchange.rb

Overview

High level representation of an exchange

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client, name) ⇒ Exchange

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Should only be initialized from the Client



11
12
13
14
# File 'lib/amqp/client/exchange.rb', line 11

def initialize(client, name)
  @client = client
  @name = name
end

Instance Attribute Details

#nameObject (readonly)

Returns the value of attribute name.



7
8
9
# File 'lib/amqp/client/exchange.rb', line 7

def name
  @name
end

Instance Method Details

#bind(source, binding_key: "", arguments: {}) ⇒ Exchange

Bind to another exchange

Parameters:

  • source (String, Exchange)

    Name of the exchange to bind to, or the exchange object itself

  • binding_key (String) (defaults to: "")

    Binding key on which messages that match might be routed (defaults to empty string)

  • arguments (Hash) (defaults to: {})

    Message headers to match on (only relevant for header exchanges)

Returns:



43
44
45
46
47
# File 'lib/amqp/client/exchange.rb', line 43

def bind(source, binding_key: "", arguments: {})
  source = source.name unless source.is_a?(String)
  @client.exchange_bind(source:, destination: @name, binding_key:, arguments:)
  self
end

#deletenil

Delete the exchange

Returns:

  • (nil)


62
63
64
65
# File 'lib/amqp/client/exchange.rb', line 62

def delete
  @client.delete_exchange(@name)
  nil
end

#publish(body, routing_key: "", **properties) ⇒ Exchange

Publish to the exchange, wait for confirm

Parameters:

  • body (Object)

    The message body will be encoded if any matching codec is found in the client’s codec registry

  • routing_key (String) (defaults to: "")

    Routing key for the message

  • properties (Hash)

    a customizable set of options

Options Hash (**properties):

  • mandatory (Boolean)

    The message will be returned if the message can’t be routed to a queue

  • persistent (Boolean)

    Same as delivery_mode: 2

  • content_type (String)

    Content type of the message body

  • content_encoding (String)

    Content encoding of the body

  • headers (Hash<String, Object>)

    Custom headers

  • delivery_mode (Integer)

    2 for persisted message, transient messages for all other values

  • priority (Integer)

    A priority of the message (between 0 and 255)

  • correlation_id (String)

    A correlation id, most often used used for RPC communication

  • reply_to (String)

    Queue to reply RPC responses to

  • expiration (Integer, String)

    Number of seconds the message will stay in the queue

  • message_id (String)

    Can be used to uniquely identify the message, e.g. for deduplication

  • timestamp (Date)

    Often used for the time the message was originally generated

  • type (String)

    Can indicate what kind of message this is

  • user_id (String)

    Can be used to verify that this is the user that published the message

  • app_id (String)

    Can be used to indicates which app that generated the message

Returns:

Raises:



23
24
25
26
# File 'lib/amqp/client/exchange.rb', line 23

def publish(body, routing_key: "", **properties)
  @client.publish(body, exchange: @name, routing_key:, **properties)
  self
end

#publish_and_forget(body, routing_key: "", **properties) ⇒ Exchange

Publish to the exchange, without waiting for confirm

Parameters:

  • body (Object)

    The message body will be encoded if any matching codec is found in the client’s codec registry

  • routing_key (String) (defaults to: "")

    Routing key for the message

  • properties (Hash)

    a customizable set of options

Options Hash (**properties):

  • mandatory (Boolean)

    The message will be returned if the message can’t be routed to a queue

  • persistent (Boolean)

    Same as delivery_mode: 2

  • content_type (String)

    Content type of the message body

  • content_encoding (String)

    Content encoding of the body

  • headers (Hash<String, Object>)

    Custom headers

  • delivery_mode (Integer)

    2 for persisted message, transient messages for all other values

  • priority (Integer)

    A priority of the message (between 0 and 255)

  • correlation_id (String)

    A correlation id, most often used used for RPC communication

  • reply_to (String)

    Queue to reply RPC responses to

  • expiration (Integer, String)

    Number of seconds the message will stay in the queue

  • message_id (String)

    Can be used to uniquely identify the message, e.g. for deduplication

  • timestamp (Date)

    Often used for the time the message was originally generated

  • type (String)

    Can indicate what kind of message this is

  • user_id (String)

    Can be used to verify that this is the user that published the message

  • app_id (String)

    Can be used to indicates which app that generated the message

Returns:

Raises:



33
34
35
36
# File 'lib/amqp/client/exchange.rb', line 33

def publish_and_forget(body, routing_key: "", **properties)
  @client.publish_and_forget(body, exchange: @name, routing_key:, **properties)
  self
end

#unbind(source, binding_key: "", arguments: {}) ⇒ Exchange

Unbind from another exchange

Parameters:

  • source (String, Exchange)

    Name of the exchange to unbind from, or the exchange object itself

  • binding_key (String) (defaults to: "")

    Binding key which the queue is bound to the exchange with (defaults to empty string)

  • arguments (Hash) (defaults to: {})

    Arguments matching the binding that’s being removed

Returns:



54
55
56
57
58
# File 'lib/amqp/client/exchange.rb', line 54

def unbind(source, binding_key: "", arguments: {})
  source = source.name unless source.is_a?(String)
  @client.exchange_unbind(source:, destination: @name, binding_key:, arguments:)
  self
end