Class: AMQP::Client::Exchange

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

Overview

High level representation of an exchange

Instance Method Summary collapse

Instance Method Details

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

Bind to another exchange

Parameters:

  • exchange (String)

    Name of the exchange to bind to

  • binding_key (String)

    Binding key on which messages that match might be routed (depending on exchange type)

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

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

Returns:



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

def bind(exchange, binding_key, arguments: {})
  @client.exchange_bind(@name, exchange, binding_key, arguments: arguments)
  self
end

#deletenil

Delete the exchange

Returns:

  • (nil)


60
61
62
63
# File 'lib/amqp/client/exchange.rb', line 60

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)

    The routing key of the message, the exchange may use this when routing the message to bound queues

  • 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:



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

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

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

Unbind from another exchange

Parameters:

  • exchange (String)

    Name of the exchange to unbind from

  • binding_key (String)

    Binding key which the queue is bound to the exchange with

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

    Arguments matching the binding that’s being removed

Returns:



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

def unbind(exchange, binding_key, arguments: {})
  @client.exchange_unbind(@name, exchange, binding_key, arguments: arguments)
  self
end