Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Asynchronous API operation occurs when the console application supplies a Console object to the session manager. The Console object (which overrides the qmf.console.Console class) handles all asynchronously arriving data. The Console class has the following methods. Any number of these methods may be overridden by the console application. Any method that is not overridden defaults to a null handler which takes no action when invoked.

Method

Arguments

Invoked when...

brokerConnected

broker

a connection to a broker is established

brokerDisconnected

broker

a connection to a broker is lost

newPackage

name

a new package is seen on the QMF bus

newClass

kind, classKey

a new class (event or object) is seen on the QMF bus

newAgent

agent

a new agent appears on the QMF bus

delAgent

agent

an agent disconnects from the QMF bus

objectProps

broker, object

the properties of an object are published

objectStats

broker, object

the statistics of an object are published

event

broker, event

an event is published

heartbeat

agent, timestamp

a heartbeat is published by an agent

brokerInfo

broker

information about a connected broker is available to be queried

Supplied with the API is a class called DebugConsole. This is a test Console instance that overrides all of the methods such that arriving asynchronous data is printed to the screen. This can be used to see all of the arriving asynchronous data.

Receiving Events

We'll start the example from the beginning to illustrate the reception and handling of events. In this example, we will create a Console class that handles broker-connect, broker-disconnect, and event messages. We will also allow the session manager to manage the broker connection for us.

Begin by importing the necessary classes:

No Format

>>> from qmf.console import Session, Console

Now, create a subclass of Console that handles the three message types:

No Format

>>> class EventConsole(Console):
...   def brokerConnected(self, broker):
...     print "brokerConnected:", broker
...   def brokerDisconnected(self, broker):
...     print "brokerDisconnected:", broker
...   def event(self, broker, event):
...     print "event:", event
...
>>>

Make an instance of the new class:

No Format

>>> myConsole = EventConsole()

Create a Session class using the console instance. In addition, we shall request that the session manager do the connection management for us. Notice also that we are requesting that the session manager not receive objects or heartbeats. Since this example is concerned only with events, we can optimize the use of the messaging bus by telling the session manager not to subscribe for object updates or heartbeats.

No Format

>>> sess = Session(myConsole, manageConnections=True, rcvObjects=False, rcvHeartbeats=False)
>>> broker = sess.addBroker()
>>>

Once the broker is added, we will begin to receive asynchronous events (assuming there is a functioning broker available to connect to).

No Format

brokerConnected: Broker connected at: localhost:5672
event: Thu Jan 29 19:53:19 2009 INFO  org.apache.qpid.broker:bind broker=localhost:5672 ...

Discovering what Kinds of Objects are Available