Oracle Mediator, the-always-give-response-pattern by using the Echo-reply

In my usecase i subscribed to an eventbus solution (rabbitmq with some custom code to be able to publish to consumers based on the soap protocol).

The backend system which generated the notications can generate the next type of events :

— employeename got changed

<nce:notification xmlns:nce="http://my.notifications" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<nce:entity>EMPLOYEE</nce:entity>
	<nce:subentity>EMPLOYEE</nce:subentity>
</nce:notification>

— employee contactaddress got changed

<nce:notification xmlns:nce="http://my.notifications" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
	<nce:entity>EMPLOYEE</nce:entity>
	<nce:subentity>ADDRESS</nce:subentity>
</nce:notification>

The current subscription mechanism only allows me to subscribe based on the value of entity.
Since i’m not interested in all EMPLOYEE related events i need to do the filtering myself.

When i register myself as consumer on the event i need to configure a soap endpoint at which the event bus will deliver the soap envelope.
The definition of this soap interface defines a http sync operation. (http 200)

This means, when the event bus tries to deliver an event and it receives back a soap response with http200, the message will be removed from the queue (i have 1 queue dedicated for my consumer application).
When the event bus tries to deliver an event and it receives back a empty response with http202, the publish on the event bus will fail since it checks on a valid soap body response.

So..this is a bit of background information.

The event bus publishes the event to our Oracle SOA Suite 12c platform. We store the events and have polling interfaces which process the events based on entity values.
To process events as soon as possible i was playing a bit with the meditor for filtering the messages. This all works ok.
Problem : when i was sending an event which wouldn’t pass the filter of the first (and only) routing rule, i would receive a http202.

Since the event bus won’t remove the event (since it’s received http202), the event will end up in a retry-sitution, this is not wanted.
I want to reply back a http200 in both situations (events i’m interested in and events i’m not interested in).

Let’s copy/paste some code from my mediator

<Mediator name="eventHandler" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" wsdlTargetNamespace="http://ibridge.nl/generic/services/eventhandler/1" xmlns="http://xmlns.oracle.com/sca/1.0/mediator"
          xmlns:nce="http://ibridge.nl/gm/model/notificatie/1">
   <operation name="receiveNotification" deliveryPolicy="AllOrNothing" priority="4" validateSchema="false">
      <switch>
         <case executionType="sequential" name="storeNotification.client.receiveNotification">
            <condition language="xpath">
               <expression>
               (
                 ($in.notification/nce:notification/nce:entity = 'EMPLOYEE' and $in.notification/nce:notification/nce:subentity = 'EMPLOYEE')
               )
               </expression>
            </condition>
            <action>
               <invoke reference="storeNotification.client" operation="receiveNotification">
                  <onReply>
                     <reply/>
                  </onReply>
               </invoke>
            </action>
         </case>
      </switch>
   </operation>
</Mediator>

When i send a event EMPLOYEE/EMPLOYEE combination this will pass the filter restriction and it will be stored (http200 will be send back to the client).
When i send a event EMPLOYEE/ADDRESS combination this will not pass the filter restriction (http202 will be send back to the client).

Now let’s make use of the “Echo Reply” routing rule type.

<Mediator name="eventHandler" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" wsdlTargetNamespace="http://ibridge.nl/generic/services/eventhandler/1" xmlns="http://xmlns.oracle.com/sca/1.0/mediator"
          xmlns:nce="http://ibridge.nl/gm/model/notificatie/1">
   <operation name="receiveNotification" deliveryPolicy="AllOrNothing" priority="4" validateSchema="false">
      <switch>
         <case executionType="sequential" name="storeNotification.client.receiveNotification">
            <condition language="xpath">
               <expression>
               (
                 ($in.notification/nce:notification/nce:entity = 'EMPLOYEE' and $in.notification/nce:notification/nce:subentity = 'EMPLOYEE')
               )
               </expression>
            </condition>
            <action>
               <invoke reference="storeNotification.client" operation="receiveNotification">
                  <onReply>
                     <reply/>
                  </onReply>
               </invoke>
            </action>
         </case>
         <case executionType="sequential" name="echo.receiveNotification">
            <action>
               <transform>
                  <part name="$out.payload"
                        function="xslt(../Transformations/generateOkResponse.xsl, $in.notificatie)"/>
               </transform>
               <echo/>
            </action>
         </case>
      </switch>
   </operation>
</Mediator>

I’m using the “Sequential routing rule” option to force the mediator to evaluate the routing rules in the order they’re added to the mediator.

If an event matches the first case filter, it will pass on the event and it will pass on the response from the backend system.
If an event doesn’t match all the filters of all the cases it will end up at the “otherwise” (last routing rule) case. Since this one just sends back and echo with the ok response from and xslt, the event bus will receive the http200.
Now both wanted and unwanted events will be removed from the event bus.

I could have added extra routing rules to define the opposite of for example the =’EMPLOYEE’ (!=EMPLOYEE) expression but then you will arrive at the problem of defining the opposite of (=’EMPLOYEE’ AND =’ADDRESS’)
which means i need to list all the possible event types and exclude them (mathematical negation ?).

A lot of non Oracle Mediator related information, sorry ;). Just wanted to share my first ever use of the mighty “Echo reply” routing rule đŸ˜‰

Share this Post:
Digg Google Bookmarks reddit Mixx StumbleUpon Technorati Yahoo! Buzz DesignFloat Delicious BlinkList Furl

Comments are closed.