|Topic||XmlBlaster has a plugin interface which allows to control the distribution of published messages to subscribers|
It is possible to let a plugin handle the distribution of published messages. The normal behavior is that all client-sessions subscribing to a certain topic are getting all updates of that topic. This covers a wide range of use cases but sometimes it is just too limiting.
Suppose you want to guarantee that a published message is consumed once and only once. That could be acheeved by sending a PtP message to a client (by specifying his session to avoid double dispatching) and setting the message as volatile. This is great but it implies that the publisher knows the address of the client. What shall we do if the destination has to be anonymous, i.e. if everybody is allowed to consume that message without the producer knowing about it, as it is for example the case of queues in JMS ?
Suppose a load balancer is required where messages of the same topic have to be distributed intelligently among clients (for example by giving the current message to the client currently having the lowest cpu consumption)
The mentioned cases are just a few of a whole spectra of potential -an many times specific- wishes users can have. A good approach to this problem is to avoid to hard-code such specific cases and provide a plugin instead.
The plugin controls the distribution of a published message to the subscribing clients, in other words it contains the logics which decide who/how a certain subscriber is getting a certain message or message update.
There is a maximum of one plugin instance per TopicHandler instance. The Topic is the owner of the plugin. This implies that you define distribution control on a pro-topic base. Practically this is defined in the PublishQos.
How to write my own plugin
As a plugin coder, you have to implement two interfaces
This is simple and straightforward (see requirement msgDistributor.plugin.ConsumableQueuePlugin).
Note that this is only an example of what you can do. The status message and priority configuration of the above example is specific for exactly this plugin. If you implement your own plugin, you can do whatever you like.
For the mentioned example of only once delivery an implementation exists which you can use/change and modify according to your needs. It is the ConsumableQueuePlugin (see link below).
The first step to do when configuring this plugin is to register it by assigning a name to it.
This is normally put into the xmlBlaster.properties file which is read by the server.
The name has the structure
When publishing a topic for the first time (or when doing an administrative publish), you can specify which plugin to use for the distribution of the message. In java you would do it like this:
... PublishQos pubQos = new PublishQos(global); TopicProperty topicProp = new TopicProperty(global); topicProp.setMsgDistributor("ConsumableQueue,1.0"); pubQos.setTopicProperty(topicProp); MsgUnit msgUnit = new MsgUnit(new PublishKey(global, someOid), someContent, pubQos); global.getXmlBlasterAccess().publish(msgUnit); ...
NOTE: Configuration parameters are specified on command line (-someValue 17) or in the
xmlBlaster.properties file (someValue=17). See requirement "util.property" for details.
This page is generated from the requirement XML file xmlBlaster/doc/requirements/msgDistributor.plugin.xml
Back to overview