Contents

Creating a FioranoMQ CBR subscriber is similar to creating a JMS subscriber. Set the value of InitialContext environment variable UseFioranoCbr to true. The subscribers (durable and non-durable) can then be created in a manner similar to PubSub. The message can be any valid XML message passed as the contents of FioranoXMLMessages.

CreateDurableSubscriber

The following API creates a Durable Subscriber which receives messages only if they conform to the specified Xpath Message Selector string:
/**

  • Fiorano's proprietary API to create XPath Durable Subscriber.
    *
  • This API creates an XPath Durable Subscriber.
    *
  • @param topic - the non temporary topic to subscribed to.
  • @param subscriptionID - ID used to identify subscription.
  • @param messageSelector - string containing the XPth message selector or normal JMS Message selector.
  • @param NoLocal - if set, inhibits delivery of messages published over its own connection.
  • @exception JMSException if operation fails
    *
    */
    public TopicSubscriber createDurableSubscriber (
    Topic topic,
    String subscriberID,
    String messageSelector,
    boolean noLocal)
    throws JMSException ;

    CreateSubscriber

    The following API creates a Non-Durable Subscriber, which only receives messages if they pass the specified Xpath Message Selector string:
    /**
  • Fiorano's proprietary API to create XPath Subscriber
    *
  • Create XPath Durable Subscriber
    *
  • @param topic - the non temporary topic to subscribe to.
  • @param messageSelector - string containing the XPth message selector or normal JMS Message selector.
  • @param NoLocal - if set, inhibits delivery of messages published by its own connection.
  • @exception JMSException if operation fails
    */
    public TopicSubscriber createSubscriber (
    Topic topic,
    String messageSelector,
    boolean noLocal)
    throws JMSException ;
    To create a FioranoMQ CBR subscriber, you can follow the example code snippet given below, which sets up an XPath Subscriber, onMessage and onException listeners.
    /*
  • Copyright (c) 2001, Fiorano Software, Inc.
  • All Rights Reserved
    *
  • FileName : XPathSubscriber.java
    *
  • [No Text. Check please]
  • Implements an asynchronous listener to listen
  • for messages published on the topic - "primaryTopic"
  • only receiving message which match the selector parameter
    *
  • Questions/comments/suggestions?
  • Please visit: http://www.fiorano.com
  • Or e-mail: support@fiorano.com
    *
  • @since FioranoMQ 6.0, August 2002
    */
    import javax.jms.*;
    import javax.naming.*;
    import java.io.*;
    import java.util.*;
    import fiorano.jms.services.msg.def.*;
    import fiorano.jms.rtl.*;
    import fiorano.jms.runtime.naming.FioranoJNDIContext;
    import java.net.*;
    class Subscriber implements MessageListener,ExceptionListener
    {
    public static void main (String args[])
    {
    Subscriber subscriber = new Subscriber ();
    try
    {
    // 1. Create the InitialContext Object used for looking up
    // JMS administered objects on the Fiorano/EMS
    // located on the default host.
    //
    Hashtable env = new Hashtable ();
    env.put (Context.SECURITY_PRINCIPAL, "anonymous");
    env.put (Context.SECURITY_CREDENTIALS, "anonymous");
    env.put (Context.PROVIDER_URL,
    "http://localhost:1856");
    env.put (Context.INITIAL_CONTEXT_FACTORY,
    "fiorano.jms.runtime.naming.FioranoInitialContextFactory");
    InitialContext ic = new InitialContext (env);
    System.out.println ("Created InitialContext :: " + ic);
    // 1.1 Lookup Connection Factory and Topic names
    //
    TopicConnectionFactory tcf =
    (TopicConnectionFactory) ic.lookup ("primaryTCF");
    Topic topic = (Topic)ic.lookup("primaryTopic");

    // 2. create and start a topic connection
    System.out.println("Creating topic connection");
    TopicConnection topicConnection = tcf.createTopicConnection();
    // Register an Exception Listner
    topicConnection.setExceptionListener (subscriber);
    topicConnection.start ();
    // 3. create topic session on the connection just created
    System.out.println("Creating topic session: not transacted, auto ack");
    TopicSession topicSession = topicConnection.createTopicSession(false,1);
    // 4. create XpathSubscriber
    System.out.println("Creating topic, subscriber");
    String selector = "/quote/symbol = 'IBM' and /quote/askprice > 40";
    TopicSubscriber topicSubscriber =
    topicSession.createSubscriber(topic,selector,false);
    // 5. install an asynchronous listener/callback on the subscriber object
    // just created
    System.out.println ("Ready to subscribe for messages :");
    topicSubscriber.setMessageListener (new Subscriber ());
    }
    catch (Exception e)
    {
    e.printStackTrace ();
    }
    }
    /**
  • Message listener which receives messages aysynchronously
  • For the bound subscriber.
    */
    public void onMessage( Message m )
    {
    if( !(m instanceof FioranoXMLMessage) )
    {
    return;
    }
    String s = "";
    try
    {
    s = ((FioranoXMLMessage)m).getText();
    }
    catch( Exception e )
    {
    System.out.println("Exception in getText() :" + e );
    }
    System.out.println ("Received the message :: "+s);
    }
    /**
  • If a JMS provider detects a serious problem with a
  • Connection this method is invoked passing it a JMSException
  • describing the problem.
  • @param JMSException e
    */
    public void onException (JMSException e)
    {
    //Report the Error and take necessary Error handling measures
    String error = e.getErrorCode ();
    System.out.println (error);
    ((fiorano.jms.common.FioranoException)e).printCompleteStackTrace();
    }
    }
    More samples of using FioranoXCR content-based routing are available in the samples directory of the FioranoMQ installation under pubsub/ContentBasedRouting.

    Handling Massive Number of Subscribers

    In an environment where millions of subscribers are required, it is possible to cascade FioranoMQ Servers a form that allows data source publishers to multiple FioranoMQ servers simultaneously. This enables each source to publish and/or send messages to several FioranoMQ Servers. Each of these in turn sends the information to another set of FioranoMQ Servers or sends information directly to the system that ultimately transfers information to subscribers. For best results it is recommended not to run more than 500 subscribers on each FioranoMQ connection.
    Below are the key concepts that enable the handling of a large number of subscribers:
  • Keep XML messages small (do not mix domain data, such as weather and sports. Do not add information on more than one item within a domain at a time, such as stock quotes for more than 1 company).
  • Use fewer connections and more subscribers per connection.
  • Use suitably powered systems that run subscribers so that they do not decelerate the movement of messages. Most slowdowns occur due to subscribers that are unable to process the messages at speed.
  • Segregate domain data on different topics (for example, use a topic for weather and a different topic for sports).

Following figure illustrates an environment where incoming XML messages are distributed to several FioranoMQ boxes. These FioranoMQ boxes in turn feed the distribution systems that eventually send message to devices such as cell phones and wireless PDAs. This example illustrates how multiple subscribers can be used to distribute data on several different topics.

Adaptavist ThemeBuilder EngineAtlassian Confluence