REQUIREMENT interface.subscribe |
Type | NEW |
Priority | HIGH |
Status | CLOSED |
Topic | Messages are asynchronous accessed with the subscribe() method | |||||||||||||||||||||||||||
Des cription |
The subscribe() method allows to subscribe for messages in xmlBlaster. You can subscribe with exactly one message by passing its oid, or by a selection of message by passing a XPATH query. Subscribed messages are sent to the callback servers update() method. Clients have to establish a callback server instance to allow asynchronous callbacks. Method detail (CORBA IDL notation): typedef string XmlType; typedef sequence<string> StringArr; XmlType subscribe(in XmlType xmlKey, in XmlType qos) raises(XmlBlasterException);
Here is an overview of all available subscribe QoS: <qos> <!-- Force a subscription ID from client side --> <subscribe id='__subId:client/subscriber/session/1-exact:MyHelloTopic'/> <!-- Recoverable subscription after server crash / restart --> <persistent/> <!-- Don't send me the xmlKey meta data on updates (default: true) --> <meta>false</meta> <!-- Don't send me the content data on updates (notify only) (default: true) --> <content>false</content> <!-- false: Ignore a second subscribe on same oid or XPATH (default: true) --> <multiSubscribe>false</multiSubscribe> <!-- Inhibit the delivery of messages to myself if i have published it (default: true) --> <local>false</local> <!-- don't send an initial message after subscribe (default: true) --> <initialUpdate>false</initialUpdate> <!-- send callbacks messages for this subscription with the better performing --> <!-- updateOneway() instead of the more reliable update() (default: false) --> <!-- Note: The SOCKET protocol plugin supports additionally the faster UDP transfer --> <updateOneway>true</updateOneway> <!-- Suppress erase event to subscribers (default: true) --> <notify>false</notify> <!-- Filters messages i have subscribed as implemented in your plugin --> <!-- Here we use the RegEx filter and only want content starting with 'H' --> <filter type='GnuRegexFilter' version='1.0'>^H.*$</filter> <!-- http://www.xmlblaster.org/xmlBlaster/doc/requirements/engine.qos.queryspec.html --> <querySpec type='QueueQuery' version='1.0'> <![CDATA[maxEntries=3;maxSize=-1;consumable=false;waitingDelay=0]]> </querySpec> <!-- Default is to deliver the current entry (numEntries='1'), '-1' deliver all (default: 1) --> <!-- newestFirst let you change the delivery order, it defaults to true --> <!-- The higher priority messages are always delivered first. --> <!-- In one priority the newest message is delivered first with 'true', setting 'false' --> <!-- reverts the delivery sequence in this priority. --> <history numEntries='20' newestFirst='true'/> </qos> Detailed description
A special note how to subscribe in cluster environments:If you subscribe to a cluster slave node, the subscription is only forwarded to a master node if the subscription key matches the configured master selection. The return string of subscribe()
On successful call the subscribe() method returns detailed informations:
The state = "OK" means everything was successful.
Note: Example of a reproducable subscriptionID in a queued return qos (e.g. after client restart): <qos> <state id='OK' info='QUEUED'/> <subscribe id='__subId:client/subscriber/session/1-exact:PublishToSlave.RUGBY_NEWS'/> </qos> 2. For none fail save clients any unique Id will do Example of a queued return qos: <qos> <state id='OK' info='QUEUED'/> <subscribe id='__subId:client/joe/session/1-1166021247822779000'/> </qos> |
|||||||||||||||||||||||||||
Example XML |
Here is an example of an exact query:
The topic MyMessage is queried and no initial update of existing history messages is delivered. And a return value:
|
|||||||||||||||||||||||||||
Example XML |
Here is an example of an XPATH query:
All topics which oid starts with radar. is queried. And the returned value:
|
|||||||||||||||||||||||||||
Example XML |
A subscription in a cluster environment belonging to domain RUGBY_NEWS
And a return value:
|
|||||||||||||||||||||||||||
Example XmlRpc |
This is the XmlRpc server interface variant: public String subscribe(String sessionId, String xmlKey_literal, String qos_literal) throws XmlBlasterException |
|||||||||||||||||||||||||||
Example Java |
A typical Java client code for an EXACT subscription: import org.xmlBlaster.client.key.SubscribeKey; import org.xmlBlaster.client.qos.SubscribeQos; import org.xmlBlaster.client.qos.SubscribeReturnQos; ... SubscribeKey sk = new SubscribeKey(glob, "MyOid"); SubscribeQos sq = new SubscribeQos(glob); SubscribeReturnQos sr = con.subscribe(sk.toXml(), sq.toXml()); System.out.println("Success, subscriptionId=" + sr.getSubscriptionId()); See xmlBlaster/demo/HelloWorld*.java for more examples. |
|||||||||||||||||||||||||||
Example Java |
A typical Java client code for an XPATH subscription: import org.xmlBlaster.client.key.SubscribeKey; import org.xmlBlaster.client.qos.SubscribeQos; import org.xmlBlaster.client.qos.SubscribeReturnQos; import org.xmlBlaster.util.def.Constants; ... SubscribeKey sk = new SubscribeKey(glob, "/xmlBlaster/key[@oid='radar.track']", Constants.XPATH); SubscribeQos sq = new SubscribeQos(glob); SubscribeReturnQos sr = con.subscribe(sk.toXml(), sq.toXml()); System.out.println("Success, subscriptionId=" + sr.getSubscriptionId()); |
|||||||||||||||||||||||||||
Example Java |
A typical Java client code for a subscriptions in a cluster environment which uses selection of master nodes with message domains: import org.xmlBlaster.client.key.SubscribeKey; import org.xmlBlaster.client.qos.SubscribeQos; import org.xmlBlaster.client.qos.SubscribeReturnQos; ... SubscribeKey sk = new SubscribeKey(glob, "MyMessageOid"); sk.setDomain("RUGBY_NEWS"); // Subscription is forwarded from slaves to master // without setting the domain the subscribe would just be handled by the slave connected to SubscribeReturnQos sr = con.subscribe(sk.toXml(), null); System.out.println("Success, subscriptionId=" + sr.getSubscriptionId()); |
|||||||||||||||||||||||||||
Configure |
NOTE: Configuration parameters are specified on command line (-someValue 17) or in the
xmlBlaster.properties file (someValue=17). See requirement "util.property" for details. |
|||||||||||||||||||||||||||
See REQ | interface | |||||||||||||||||||||||||||
See REQ | engine.qos.subscribe.id | |||||||||||||||||||||||||||
See REQ | engine.qos.subscribe.duplicate | |||||||||||||||||||||||||||
See REQ | engine.qos.subscribe.multiSubscribe | |||||||||||||||||||||||||||
See REQ | client.subscribe.dispatch | |||||||||||||||||||||||||||
See REQ | mime.plugin.accessfilter | |||||||||||||||||||||||||||
See | ../../demo/javaclients/HelloWorldSubscribe.java.html | |||||||||||||||||||||||||||
See API | org.xmlBlaster.engine.xml2java.XmlKey | |||||||||||||||||||||||||||
See API | org.xmlBlaster.client.qos.SubscribeQos | |||||||||||||||||||||||||||
See API | org.xmlBlaster.client.qos.SubscribeReturnQos | |||||||||||||||||||||||||||
See API | org.xmlBlaster.client.I_XmlBlasterAccess | |||||||||||||||||||||||||||
See API | org.xmlBlaster.protocol.xmlrpc.XmlBlasterImpl | |||||||||||||||||||||||||||
See TEST | org.xmlBlaster.test.qos.TestSub | |||||||||||||||||||||||||||
See TEST | org.xmlBlaster.test.qos.TestSubExact | |||||||||||||||||||||||||||
See TEST | org.xmlBlaster.test.qos.TestSubXPath | |||||||||||||||||||||||||||
See TEST | org.xmlBlaster.test.qos.TestSubManyClients | |||||||||||||||||||||||||||
See TEST | org.xmlBlaster.test.qos.TestSubNoDup | |||||||||||||||||||||||||||
See TEST | org.xmlBlaster.test.qos.TestSubNotify | |||||||||||||||||||||||||||
See TEST | org.xmlBlaster.test.qos.TestSubNoLocal | |||||||||||||||||||||||||||
See TEST | org.xmlBlaster.test.qos.TestSubXPathMany | |||||||||||||||||||||||||||
See TEST | org.xmlBlaster.test.qos.TestSubDispatch | |||||||||||||||||||||||||||
See TEST | org.xmlBlaster.test.qos.TestSubLostClient | |||||||||||||||||||||||||||
See TEST | org.xmlBlaster.test.qos.TestSubMulti | |||||||||||||||||||||||||||
See TEST | org.xmlBlaster.test.qos.TestSubMultiSubscribe | |||||||||||||||||||||||||||
See TEST | org.xmlBlaster.test.classtest.qos.StatusQosFactoryTest | |||||||||||||||||||||||||||
See TEST | org.xmlBlaster.test.cluster.SubscribeTest | |||||||||||||||||||||||||||
See TEST | org.xmlBlaster.test.cluster.SubscribeXPathTest |
This page is generated from the requirement XML file xmlBlaster/doc/requirements/interface.subscribe.xml