On 11/20/2013 01:33 PM, Kerry Bonin wrote:
Thanks!  I'm absolutely fine w/ using the messaging APIs, and thanks for
the example, its clear enough.  Is there any data available from the
console APIs (I used them a long time ago - 0.8? - weren't very stable)
that I can't get using the message APIs?

No, all the data that the tools offer can be obtained through direct use of the underlying QMFv2 protocol.

 And where can I look for the best
documentation that does exist?

https://cwiki.apache.org/confluence/display/qpid/QMF+Map+Message+Protocol is the basic description of the protocol, /home/gordon/projects/qpid-svn-trunk/cpp/src/qpid/broker/management-schema.xml is the schema definition that describes the stats and properties available for different classes of object.

Though it doesn't really help on the list side, I've attached some rough notes I wrote up on creating and deleting objects. It may (or may not) be useful for some of the general patterns with QMF.

Feel free to ask questions here as well.

The broker (qpidd) is managed via specially formatted messages sent
to- and received from- special addresses. This approach can be used to
list, create and delete queues and exchanges and to bind them
together.

This approach is described as part of the Qpid Management Framework
(version 2). 

Command messages are simply map messages that are sent to address
qmf.default.direct/broker (i.e. to the exchange named
'qmf.default.direct', with a routing key or subject of 'broker'). The
message should contain a reply-to address from which the sender can
receiver responses.

The map used as the content for commands follows a particular
pattern.

There must always be an entry with key _object_id whose value
is a nested map identifying the target of the command. For the
commands considered here the target is always the broker itself. Thus
the _object_id map contains a single value with key _object_name and
value org.apache.qpid.broker:broker:amqp-broker.

There are two further top-level entries in the map. One has
_method_name as the key and the name of the command as its value. The
second, with key _arguments, contains a nested map in which the named
arguments for the command are contained.

In addition to correctly formatted content, there are two message
properties that must also be set. These are 'x-amqp-0-10.app-id',
which should always have the value 'qmf2' and 'qmf.opcode' which for
commands should always have the value '_method_request'.

After we have correctly constructed a command message and sent it to
the correct address, we can wait for the response to arrive from the
reply-to address we specified.

Wehn it arrives it should also have the 'x-amqp-0-10.app-id' property
set to 'qmf2' and the 'qmf.opcode' should be '_method_response' if all
went well or '_exception' if an error was encountered. In both cases
the content is again a map. In the case of a valid response, any
return values (or 'out parameters') will be present as a nested map
against the key '_arguments'. In the case of an exception, the details
of the exception will be given in a nested map against the key
'_values'.

Given the basic mechanism described, the commands used to create and
delete queues and exchanges are named 'create' and 'delete'
respectively. The create command takes four arguments: 

(1) type specifies the type of object to create and can be queue,
exchange or binding

(2) name specifies the name of the object to create

(3) properties is a nested map in which specific properties for the
object to be created can be requested

(4) the strict argument takes a boolean value which at present is
ignored, but which is intended to indicate whether the command should
fail if any unrecognised properties have been specified

The delete method takes three arguments:

(1) as for create the type specifies the type of object to be delete -
valid values are again queue, exchange or binding - and is needed here
to handle the different namespaces that each object inhabits

(2) the name identifies the object to delete

(3) the final argument is a nested map with key options that at
present is unused

The naming of queues and exchanges is simple - a queue named my-queue
would set the name argument to a string of that value. The naming of
bindings uses the pattern <exchange>/<queue>/<key>
(e.g. amq.topic/my-queue/my-key identifies a binding between my-queue
and the exchange amq.topic with the binding key my-key)

The following python code shows by example the creation of a queue
named 'my-queue' that is set to be auto-deleted after 10 seconds.

conn = Connection(opts.broker)
try:
  conn.open()
  ssn = conn.session()
  snd = ssn.sender("qmf.default.direct/broker")
  reply_to = "#; {create:always, node:{x-declare:{auto-delete:true}}}"
  rcv = ssn.receiver(reply_to)

  content = {
             "_object_id": {"_object_name": 
"org.apache.qpid.broker:broker:amqp-broker"},
             "_method_name": "create",
             "_arguments": {"type":"queue", "name":"my-queue", 
properties:{"auto-delete":True, "qpid.auto_delete_timeout":10}}
            } 
  request = Message(reply_to=reply_to, content=content)
  request.properties["x-amqp-0-10.app-id"] = "qmf2"
  request.properties["qmf.opcode"] = "_method_request"
  snd.send(request)

  try:
    response = rcv.fetch(timeout=opts.timeout)
    if response.properties['x-amqp-0-10.app-id'] == 'qmf2':
      if response.properties['qmf.opcode'] == '_method_response':
        return response.content['_arguments']
      elif response.properties['qmf.opcode'] == '_exception':
        raise Exception("Error: %s" % response.content['_values'])
      else: raise Exception("Invalid response received, unexpected opcode: %s" 
% m)
    else: raise Exception("Invalid response received, not a qmfv2 method: %s" % 
m)
  except Empty:
    print "No response received!"
  except Exception, e:
    print e
except ReceiverError, e:
  print e
except KeyboardInterrupt:
  pass

conn.close()



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to