In addition to be able to manage JBM2 using JMX, it must be possible to manage a JBM
server by sending "management" messages using its core API .
I've some working code to do that in my local box.
The idea is that the user creates a temporary queue that he will use to send management
messages.
| SimpleString mngmntQueue = new SimpleString("admin.MyOwnAdminQueue");
| clientSession.addDestination(mngmntQueue, false, true);
| clientSession.createQueue(mngmntQueue, mngmntQueue, null, false, true);
|
He then create such management messages using the ClientSession:
| ClientMessage msg = clientSession.createManagementAttributesMessage(
| ManagementServiceImpl.getQueueObjectName(queue, queue),
| "MessageCount", "Durable");
|
The semantics are the same than JMX: the message above means "retrieve attributes
MessageCount and Durable on the Queue identified by the ObjectName".
He then sends the message:
| producer.send(msg);
|
After that, he consumes a message on the *same* temporary queue:
| ClientMessage m = consumer.receive(5000);
|
The message he received then contains the value of the attributes:
| ManagementHelper helper = new ManagementHelper(m.getBody());
| System.out.println("MessageCount=" +
helper.getProperty("MessageCount"));
| System.out.println("Durable=" + helper.getProperty("Durable"));
|
It works almost the same to invoke a management operation:
| message = clientSession.createManagementOperationMessage(
| ManagementServiceImpl.getQueueObjectName(queue, queue),
| "listAllMessages");
| producer.send(msg);
| ...
| m = consumer.receive(5000);
| ...
| helper = new ManagementHelper(m.getBody());
| System.out.println("operation succeeded? " +
mngmntHelper.hasOperationSucceeded());
| if (!helper.hasOperationSucceeded())
| {
| System.out.println("exception: " +
helper.getOperationExceptionMessage());
| }
| else
| {
| TabularData msgs = (TabularData)
helper.getTabularDataProperty("listAllMessages");
| MessageInfo[] infos = MessageInfo.from(msgs);
| for (MessageInfo info : infos)
| {
| System.out.println(info);
| }
| }
|
The result of an operation is available has a property identified by the name of the
operation "listAllMessages" above.
Additionally, we must check if the operation has succeeded and if not, we have a exception
message to report to the user.
The implementation is straightforward: the "so-called" management messages are
simple ClientMessages using well known headers
to identify management attributes and operations (+ 1 header to flag the message as a
management message).
When the message is routed by the PostOffice on the server, we check if it is flagged as a
management message.
If that's the case, we pass it to the ManagementService.
This service will invoke management operations and fetch attributes and put the values in
the message.
Then the message continues to be routed as any other message.
To sum up:
- management operations over JBM 2 core API uses JMX semantics
- on the server, they're intercepted and processed by the management service, then
routed normally
- the user workflow is to create a temp queue, create management messages, send them,
consume them and process the results
The advantage of this implementation is that it is simple and not intrusive.
The disadvantage is that the management code will be brittle since a lot is done by
reflection: you've to double-check
the ObjectNames you use, the attributes spelling, the types required by the management
operation.
Besides to know what can be done on the management side, you have to look at our MBeans to
check the available attributes and operations.
I still need to add support for notifications but i'll save that for another post on
the dev forum
View the original post :
http://www.jboss.com/index.html?module=bb&op=viewtopic&p=4172578#...
Reply to the post :
http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&a...