Class: Qpid::Management::Broker

Inherits:
BrokerObject show all
Defined in:
lib/qpid_management/broker.rb

Overview

Representation of the broker. Properties include:

  • abandoned

  • abandonedViaAlt

  • acquires

  • byteDepth

  • byteFtdDepth

  • byteFtdDequeues

  • byteFtdEnqueues

  • bytePersistDequeues

  • bytePersistEnqueues

  • byteTotalDequeues

  • byteTotalEnqueues

  • byteTxnDequeues

  • byteTxnEnqueues

  • connBacklog

  • dataDir

  • discardsLvq

  • discardsNoRoute

  • discardsOverflow

  • discardsPurge

  • discardsRing

  • discardsSubscriber

  • discardsTtl

  • maxConns

  • mgmtPubInterval

  • mgmtPublish

  • msgDepth

  • msgFtdDepth

  • msgFtdDequeues

  • msgFtdEnqueues

  • msgPersistDequeues

  • msgPersistEnqueues

  • msgTotalDequeues

  • msgTotalEnqueues

  • msgTxnDequeues

  • msgTxnEnqueues

  • name

  • port

  • queueCount

  • releases

  • reroutes

  • stagingThreshold

  • systemRef

  • uptime

  • version

  • workerThreads

Instance Attribute Summary

Attributes inherited from BrokerObject

#content

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BrokerObject

#[], #created_at, #deleted_at, #id, #initialize, #invoke_method, #method_missing, qmf_class, #refresh!, #short_id, #to_s, #updated_at

Constructor Details

This class inherits a constructor from Qpid::Management::BrokerObject

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class Qpid::Management::BrokerObject

Class Method Details

.has_many(*collections) ⇒ Object

Adds methods for the specified collections to be able to access all instances of a given collection, as well as a single instance by oid.

Example

has_many :queues which will add:

  • #queues to retrieve all queues

  • #queue(oid) to retrieve a queue by oid (note, this is the short form of the object id, e.g. “myqueue” for a queue instead of “org.apache.qpid.broker:queue:myqueue”

Parameters:

  • collections

    one or more symbols for the collections of objects a broker manages



78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/qpid_management/broker.rb', line 78

def self.has_many(*collections)
  [*collections].each do |collection|
    singular_form = collection.to_s[0..-2]
    capitalized_type = singular_form.gsub(/^\w/) { $&.upcase }

    define_method(collection) do
      @agent.find_all_by_class(Qpid::Management::const_get(capitalized_type))
    end

    define_method(singular_form) do |oid|
      @agent.find_by_object_id(Qpid::Management::const_get(capitalized_type), "org.apache.qpid.broker:#{singular_form}:#{oid}")
    end
  end
end

.has_one(*types) ⇒ Object

Adds method for the specified types to be able to access the singular instance of a given type.

Example

has_one :acl which will add:

  • #acl to retrieve the Acl data for the Broker

Parameters:

  • types

    one or more symbols for the singular objects a broker manages



101
102
103
104
105
106
107
108
109
# File 'lib/qpid_management/broker.rb', line 101

def self.has_one(*types)
  [*types].each do |type|
    capitalized_type = type.to_s.gsub(/^\w/) { $&.upcase }

    define_method("#{type}") do
      @agent.find_first_by_class(Qpid::Management::const_get(capitalized_type))
    end
  end
end

Instance Method Details

#add_binding(exchange, queue, key = "", options = {}) ⇒ Object

Adds a binding from an exchange to a queue

Parameters:

  • exchange (String)

    exchange name

  • queue (String)

    queue name

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

    binding key

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

    binding creation options



146
147
148
# File 'lib/qpid_management/broker.rb', line 146

def add_binding(exchange, queue, key="", options={})
  create_broker_object('binding', "#{exchange}/#{queue}/#{key}", options)
end

#add_dynamic_route(name, options = {}) ⇒ Object

Adds a dynamic route

Parameters:

  • name (String)

    the name of the bridge to create

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

    options for the dynamic route

Options Hash (options):

  • :link (String)

    the name of the link to use (required)

  • :exchange (String)

    the name of the exchange to use (required)

  • :sync (Fixnum)

    the number of messages to send before issuing an explicit session sync (required)

  • :bridge_queue (String)

    name of the queue to use as a bridge queue (optional)



239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
# File 'lib/qpid_management/broker.rb', line 239

def add_dynamic_route(name, options={})
  validate_options(options, [:link, :exchange, :sync])

  properties = {
    'link' => options[:link],
    'src' => options[:exchange],
    'dest' => options[:exchange],
    'dynamic' => true,
    'sync' => options[:sync]
  }

  properties['queue'] = options[:bridge_queue] if options.has_key?(:bridge_queue)

  create_broker_object('bridge', name, properties)
end

#add_exchange(type, name, options = {}) ⇒ Object

Adds an exchange to the broker

Parameters:

  • type (String)

    exchange type (fanout, direct, topic, headers, xml)

  • name (String)

    exchange name

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

    exchange creation options



118
119
120
# File 'lib/qpid_management/broker.rb', line 118

def add_exchange(type, name, options={})
  create_broker_object('exchange', name, options.merge!({'exchange-type' => type}))
end

#add_exchange_route(name, options = {}) ⇒ Object

Adds an exchange route

Parameters:

  • name (String)

    the name of the bridge to create

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

    options for the exchange route

Options Hash (options):

  • :link (String)

    the name of the link to use (required)

  • :exchange (String)

    the name of the exchange to use (required)

  • :key (String)

    routing key to federate (required)

  • :sync (Fixnum)

    the number of messages to send before issuing an explicit session sync (required)

  • :bridge_queue (String)

    name of the queue to use as a bridge queue (optional)



216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
# File 'lib/qpid_management/broker.rb', line 216

def add_exchange_route(name, options={})
  validate_options(options, [:link, :exchange, :key, :sync])

  properties = {
    'link' => options[:link],
    'src' => options[:exchange],
    'dest' => options[:exchange],
    'key' => options[:key],
    'sync' => options[:sync]
  }

  properties['queue'] = options[:bridge_queue] if options.has_key?(:bridge_queue)

  create_broker_object('bridge', name, properties)
end

Adds a link to a remote broker

Parameters:

  • name (String)

    link name

  • host (String)

    remote broker host name or IP address

  • port (Fixnum)

    remote broker port

  • transport (String) (defaults to: 'tcp')

    transport mechanism used to connect to the remote broker

  • durable (Boolean) (defaults to: false)

    should this link be persistent

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

    authentication mechanism to use

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

    user name to authenticate with the remote broker

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

    password for the user name



167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/qpid_management/broker.rb', line 167

def add_link(name, host, port, transport='tcp', durable=false, auth_mechanism="", username="", password="")
  options = {
    'host' => host,
    'port' => port,
    'transport' => transport,
    'durable' => durable,
    'authMechanism' => auth_mechanism,
    'username' => username,
    'password' => password
  }

  create_broker_object('link', name, options)
end

#add_queue(name, options = {}) ⇒ Object

Adds a queue to the broker

Parameters:

  • name (String)

    queue name

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

    queue creation options



131
132
133
# File 'lib/qpid_management/broker.rb', line 131

def add_queue(name, options={})
  create_broker_object('queue', name, options)
end

#add_queue_route(name, options = {}) ⇒ Object

Adds a queue route

Parameters:

  • name (String)

    the name of the bridge to create

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

    options for the queue route

Options Hash (options):

  • :link (String)

    the name of the link to use (required)

  • :queue (String)

    the name of the source queue from which messages are pulled (required)

  • :exchange (String)

    the name of the destination exchange to which messages are sent (required)

  • :sync (Fixnum)

    the number of messages to send before issuing an explicit session sync (required)



194
195
196
197
198
199
200
201
202
203
204
205
206
# File 'lib/qpid_management/broker.rb', line 194

def add_queue_route(name, options={})
  validate_options(options, [:link, :queue, :exchange, :sync])

  properties = {
    'link' => options[:link],
    'src' => options[:queue],
    'dest' => options[:exchange],
    'srcIsQueue' => true,
    'sync' => options[:sync]
  }

  create_broker_object('bridge', name, properties)
end

#delete_binding(exchange, queue, key = "") ⇒ Object

Deletes a binding from an exchange to a queue

Parameters:

  • exchange (String)

    exchange name

  • queue (String)

    queue name

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

    binding key



154
155
156
# File 'lib/qpid_management/broker.rb', line 154

def delete_binding(exchange, queue, key="")
  invoke_method('delete', {'type' => 'binding', 'name' => "#{exchange}/#{queue}/#{key}"})
end

#delete_bridge(name) ⇒ Object

Deletes a bridge (route)

Parameters:

  • name (String)

    bridge name



257
258
259
# File 'lib/qpid_management/broker.rb', line 257

def delete_bridge(name)
  invoke_method('delete', {'type' => 'bridge', 'name' => name})
end

#delete_exchange(name) ⇒ Object

Deletes an exchange from the broekr

Parameters:

  • name (String)

    exchange name



124
125
126
# File 'lib/qpid_management/broker.rb', line 124

def delete_exchange(name)
  invoke_method('delete', {'type' => 'exchange', 'name' => name})
end

Deletes a link to a remote broker

Parameters:

  • name (String)

    link name



183
184
185
# File 'lib/qpid_management/broker.rb', line 183

def delete_link(name)
  invoke_method('delete', {'type' => 'link', 'name' => name})
end

#delete_queue(name) ⇒ Object

Deletes a queue from the broker

Parameters:

  • name (String)

    queue name



137
138
139
# File 'lib/qpid_management/broker.rb', line 137

def delete_queue(name)
  invoke_method('delete', {'type' => 'queue', 'name' => name})
end