[jboss-dev-forums] [Design of JBoss ESB] - Re: Design of a Content Based Routing Service

kurt.stam@jboss.com do-not-reply at jboss.com
Fri Nov 3 14:32:19 EST 2006


I have been working on the CBR configuration, and this is what we have so far:

The CBR can be started as a service by putting a fragment like this in your deployment-configuration.xml (taken from the qa/junit/src/org/jboss/soa/esb/listeners/message/ContentBasedRouting.xml):

  | <ContentBasedRouter
  |     service-category="MessageRouting"
  | 	service-name="ContentBasedRoutingService"
  | 	service-description="This CBR routs messages to different service destination based whether the messageType is XML or Serializable"
  |    	listenerClass="org.jboss.soa.esb.listeners.message.CbrJmsQueueListener"
  | 	connection-factory="ConnectionFactory"
  | 	destination-type="queue"
  |    	destination-name="queue/A"
  | 	jndi-type="jboss"
  |     jndi-URL="localhost"
  |     message-selector="service='ContentBasedRouting-SerializableOrXml'"
  |    >
  | 	   <cbr ruleSet="JBossESBRules.drl" />
  |    </ContentBasedRouter>
  | 

This will bring up a CBR with serviceName ContentBasedRoutingService, and it is of type CbrJmsQueueListener (which extends JmsQueueListener).

The message-selector is set to 'ContentBasedRouting-SerializableOrXml' and the  section you can see the ruleset it will use is 'JBossESBRules.drl'. So if you send your message to this destination it will route this message based on that ruleSet. 

Now, the outcoming of the routing is one or more destinations. Based on the setting of the flag 'MessageRouter.DELIVER_MESSAGE' in the message
the Router itself will take care of the delivery (if set to true, which is the default behavior) or if set to false it will simply return the Collection of destinationServices. This part becomes interesting when the CBR is called from an action. Let's say you have the following section in your deployment-config.xml:


  | <CreditAgencyJMSOutput
  |    	listenerClass="org.jboss.soa.esb.listeners.JmsQueueListener"
  | 
  |    	actions="CreditCheckResponse-To-BankQuote, CBR-To-Banks,
  | BankQuote-Transform,CBR-Deliver"
  | 
  |    	maxThreads="1"
  |    	queueConnFactoryClass="ConnectionFactory"
  |    	listenJndiType="jboss"
  |    	listenJndiURL="localhost"
  |    	listenQueue="queue/A"
  |    	listenMsgSelector="sample_loanbroker_servicecode='creditResponse'"
  | > 
  |   
  | </CreditAgencyJMSOutput>
  | 
  | <Action name="CBR-To-Banks" processor="addDestinationListToMessage" />
  | <Action name="CBR-Deliver" processor="deliverToDestinations" />
  | 

The idea here is the Credit-Agency response is send to the CBR, which obtains the list of destinationServices. Which gets set on the message. Now before delivering them you may want to execute another action before sending it out for delivery. The action I m ade up here is the 'BankQuote-Transform'. The the next action 'CBR-Deliver', sends the message on it's merry way.

Note that if you have multiple ruleSets, you can define a Listener for each and you can then chain these routers, for example sort out the XML-based messages first (and route those with XPATH). It seems a nice way to break the ruleSets up manageable sets. The JRulesBasedRouter keeps a static HashMap of each of these ruleSets.

Well so far the update, I'm opening the floor for suggestions :).

--Kurt

View the original post : http://www.jboss.com/index.html?module=bb&op=viewtopic&p=3983079#3983079

Reply to the post : http://www.jboss.com/index.html?module=bb&op=posting&mode=reply&p=3983079



More information about the jboss-dev-forums mailing list