Notifications over JBM core connections
jmesnil Sep 17, 2008 10:10 AMAs part of the management task, I'm implementing receiving management notifications over JBM core connections.
The idea is that a Core client can subscribe to notifications by asking the server to send a message to a given destination every time a notification is triggered on the server (e.g. a queue is full, a queue is added to the server)
- the client creates a "management message", a Core message with well-known properties:
* the ObjectName it wants to observe
* the destination where the notification messages must be sent (specified by the client, can be any kind of destination, more likely either a topic or a temp queue)
- it sends the message to the server
- the server handles the message
* the PostOffice detects it is a management message and pass it to the management service
* the management service creates a NotificationListener for the given ObjectName
- Later on, when a notification is received by the listener (e.g. a queue is full)
* the listener creates a Core message and fills it with the notifications information (who, when, what, etc.)
* this core message is then routed by the PostOffice according to the destination set by the client
- the client will receive the Core message and process the notification information
So, the big idea is that a Core message is created on the /server-side/ as the result of a notification (internal to the server) and not as the result of receiving a message from a client.
I'm not sure about the best way to create a Core message on the server.
The ManagementService code looks like:
// when handling a "management message" final SimpleString replyTo = (SimpleString)message.getProperty(ManagementMessageImpl.HDR_JMX_REPLYTO); boolean subscribe = (Boolean)message.getProperty(ManagementMessageImpl.HDR_JMX_SUBSCRIBE_TO_NOTIFICATIONS); if (subscribe) { broadcaster.addNotificationListener(new NotificationListener() { public void handleNotification(Notification notification, Object handback) { ServerMessage notificationMessage = new ServerMessageImpl(0); notificationMessage.setDestination(replyTo); // FIXME no hard-coded value notificationMessage.setBody(new ByteBufferWrapper(ByteBuffer.allocate(1024))); notificationMessage.putBooleanProperty(ManagementMessageImpl.HDR_JMX_NOTIFICATION, true); notificationMessage.putStringProperty(new SimpleString("notif"), new SimpleString(notification.getMessage())); try { postOffice.route(notificationMessage); } catch (Exception e) { log.warn("problem while routing a notification message", e); // TODO unregister the listener for the broadcaster } } }, null, null); } ...
The code to create the notificationMessage is not correct.
I need to use a proper message ID but, on the server-side, it is the storage manager which owns the ID sequence.
I could inject the storageManager into the managementService to get access to its generateID() but it smells like a bad idea.
I could create a new POJO, a ID generator, injected in both the storageManager and the managementService.
What do you think?
Does this make sense?