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

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:



45
46
47
48
49
# File 'lib/amqp/client/exchange.rb', line 45

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

#deletenil

Delete the exchange

Returns:

  • (nil)


64
65
66
67
# File 'lib/amqp/client/exchange.rb', line 64

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

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

Publish to the exchange

Parameters:

  • body (String)

    The message body

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

    The routing key of the message, the exchange may use this when routing the message to bound queues (defaults to empty string)

  • properties (Properties)

Options Hash (**properties):

  • 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 (Integer)

    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:



35
36
37
38
# File 'lib/amqp/client/exchange.rb', line 35

def publish(body, routing_key = "", **properties)
  @client.publish(body, @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:



56
57
58
59
60
# File 'lib/amqp/client/exchange.rb', line 56

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