9 min read

In this article by Sergey Popov, author of the book Applied SOA Patterns on the Oracle Platform, we will learn some complex SOA patterns, realized on very interesting Oracle products: Coherence and Oracle Event Processing.

(For more resources related to this topic, see here.)

We have to admit that for SOA Suite developers and architects (especially from the old BPEL school), the Oracle Event Processing platform could be a bit outlandish. This could be the reason why some people oppose service-oriented and event-driven architecture, or see them as different architectural approaches. The situation is aggravated by the abundance of the acronyms flying around such as EDA EPN, EDN, CEP, and so on. Even here, we use EPN and EDN interchangeably, as Oracle calls it event processing, and generically, it is used in an event delivery network.

 

The main argument used for distinguishing SOA and EDN is that SOA relies on the application of a standardized contract principle, whereas EDN has to deal with all types of events. This is true, and we have mentioned this fact before. We also mentioned that we have to declare all the event parameters in the form of key-value pairs with their types in <event-type-repository>. We also mentioned that the reference to the event type from the event type repository is not mandatory for a standard EPN adapter, but it’s essential when you are implementing a custom inbound adapter in the EPN framework, which is an extremely powerful Java-based feature. As long as it’s Java, you can do practically everything! Just follow the programming flow explained in the Oracle documentation; see the EP Input Adapter Implementation section:

 

import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import com.bea.wlevs.ede.api.EventProperty;

import com.bea.wlevs.ede.api.EventRejectedException; import com.bea.wlevs.ede.api.EventType;

 

import com.bea.wlevs.ede.api.EventTypeRepository; import com.bea.wlevs.ede.api.RunnableBean;

 

import com.bea.wlevs.ede.api.StreamSender; import com.bea.wlevs.ede.api.StreamSink; import com.bea.wlevs.ede.api.StreamSource; import com.bea.wlevs.util.Service;

 

import java.lang.RuntimeException;

 

public class cargoBookingAdapter implements RunnableBean, StreamSource, StreamSink

 

{

 

static final Log v_logger = LogFactory. getLog(“cargoBookingAdapter”);

 

private String v_eventTypeName; private EventType v_eventType;

       private StreamSender v_eventSender;

 

private EventTypeRepository v_EvtRep = null; public cargoBookingAdapter(){

 

super();

 

}

 

/**

 

*  Called by the server to pass in the name of the event

 

*  v_EvTypee to which event data should be bound.

 

*/

 

public void setEventType(String v_EvType){ v_eventTypeName = v_EvType;

}

 

/**

 

*  Called by the server to set an event v_EvTypee

 

*  repository instance that knows about event

 

*  v_EvTypees configured for this application

 

*

 

*  This repository instance will be used to retrieve an

 

*  event v_EvTypee instance that will be populated

 

*  with event data retrieved from the event data file

 

*  @param etr The event repository.

 

*/

 

@Service(filter = EventTypeRepository.SERVICE_FILTER)

 

public void setEventTypeRepository(EventTypeRepository etr){ v_EvtRep = etr;

 

}

 

/**

 

*  Executes to retrieve raw event data and

 

*  create event v_EvTypee instances from it, then

 

*  sends the events to the next stage in the

 

*  EPN.

 

*  This method, implemented from the RunnableBean

 

*  interface, executes when this adapter instance

 

*  is active.

 

*/

 

public void run()

 

{

 

if (v_EvtRep == null){

 

throw new RuntimeException(“EventTypeRepository is

 

not set”);

 

}

 

//  Get the event v_EvTypee from the repository by using

 

//  the event v_EvTypee name specified as a property of

 

//  this adapter in the EPN assembly file.

 

v_eventType = v_EvtRep.getEventType(v_eventTypeName); if (v_eventType == null){

throw new RuntimeException(“EventType(” + v_eventType + “) is not found.”);

 

 

}

 

/**

 

*   Actual Adapters implementation:

 

*          

 

*  1. Create an object and assign to it

 

*      an event v_EvTypee instance generated

 

*      from event data retrieved by the

 

*      reader

 

*

 

*  2. Send the newly created event v_EvTypee instance

 

*      to a downstream stage that is

 

*      listening to this adapter.

 

*/

 

}

 

}

 

}

 

The presented code snippet demonstrates the injection of a dependency into the Adapter class using the setEventTypeRepository method, implanting the event type definition that is specified in the adapter’s configuration.

 

So, it appears that we, in fact, have the data format and model declarations in an XML form for the event, and we put some effort into adapting the inbound flows to our underlying component. Thus, the Adapter Framework is essential in EDN, and dependency injection can be seen here as a form of dynamic Data Model/Format Transformation of the object’s data. Going further, just following the SOA reusabilityprinciple, a single adapter can be used in multiple event-processing networks and for that, we can employ the Adapter Factory pattern discussed earlier (although it’s not an official SOA pattern, remember?) For that, we will need the Adapter Factory class and the registration of this factory in the EPN assembly file with a dedicated provider name, which we will use further in applications, employing the instance of this adapter. You must follow the OSGi service registry rules if you want to specify additional service properties in the <osgi:service interface=”com.bea.wlevs.ede.api.AdapterFactory”> section and register it only once as an OSGi service.

 

We also use Asynchronous Queuing and persistence storage to provide reliable delivery of events aggregation to event subscribers, as we demonstrated in the previous paragraph. Talking about aggregation on our CQL processors, we have practically unlimited possibilities to merge and correlate various event sources, such as streams:

 

<query id=”cargoQ1″><![CDATA[

 

select * from CragoBookingStream, VoyPortCallStream

 

where CragoBookingStream.POL_CODE = VoyPortCallStream.PORT_CODE and VoyPortCallStream.PORT_CALL_PURPOSE =”LOAD”

]]></query>

Here, we employ Intermediate Routing (content-based routing) to scale and balance our event processors and also to achieve a desirable level of high availability. Combined together, all these basic SOA patterns are represented in the Event-Driven Network that has Event-Driven Messaging as one of its forms.

 

Simply put, the entire EDN has one main purpose: effective decoupling of event (message) providers and consumers (Loose Coupling principle) with reliable event identification and delivering capabilities. So, what is it really? It is a subset of the Enterprise Service Bus compound SOA pattern, and yes, it is a form of an extended Publish-Subscribe pattern.

 

Some may say that CQL processors (or bean processors) are not completely aligned with the classic ESB pattern. Well, you will not find OSB XQuery in the Canonical ESB patterns catalog either; it’s just a tool that supports ESB VETRO operations in this matter. In ESB, we can also call Java Beans when it’s necessary for message processing; for instance, doing complex sorts inJava Collections is far easier than in XML/XSLT, and it is worth the serialization/ deserialization efforts. In a similar way, EDN extends the classic ESB by providing the following functionalities:

 

        Continuous Query Language

 

        It operates on multiple streams of disparate data

 

        It joins the incoming data with persisted data

 

        It has the ability to plug in to any type of adapter

 

        It has the ability to plug to any type of adapters

 

Combined together, all these features can cover almost any range of practical challenges, and the logistics example we used here in this article is probably too insignificant for such a powerful event-driven platform; however, for a more insightful look at Oracle CEP, refer to Getting Started with Oracle Event Processing 11g, Alexandre Alves, Robin J. Smith, Lloyd Williams, Packt Publishing. Using exactly the same principles and patterns, you can employ the already existing tools in your arsenal. The world is apparentlybigger, and this tool can demonstrate all its strength in the following use cases:

 

      As already mentioned, Cablecom Enterprise strives to improve the overall customer experience (not only for VOD). It does so by gathering and aggregating information about user preferences through the purchasing history, watch lists, channel switching, activity in social networks, search history and used meta tags in search, other user experiences from the same target group, upcoming related public events (shows, performances, or premieres), and even the duration of the cursor’s position over certain elements of corporate web portals. The task is complex and comprises many activities, including meta tag updates in metadata storage that depend on new findings for predicting trends and so on; however, here we can tolerate (to some extent) the events that aren’t processed or are not received.

 

  •    For bank transaction monitoring, we do not have such a luxury. All online events must be accounted and processed with the maximum speed possible. If the last transaction with your credit card was at Bond Street in London, (ATM cash withdrawal) and 5 minutes later, the same card is used to purchase expensive jewellery online with a peculiar delivery address, then someone should flag the card with a possible fraud case and contact the card holder. This is the simplest example that we can provide. When it comes to money laundering tracking cases in our borderless world—the decision-parsing tree from the very first figure in this article—based on all possible correlated events will require all the pages of this book, and you will need a strong magnifying glass to read it; the stratagem of the web nodes and links would drive even the most worldly wise spider crazy.

 

For these mentioned use cases, Oracle EPN is simply compulsory with some spice, like Coherence for cache management and adequate hardware. It would be prudent to avoid implementing homebrewed solutions (without dozens of years of relevant experience), and following the SOA design patterns is essential.

 

Let’s now assemble all that we discussed in the preceding paragraphs in one final figure. Installation routines will not give you any trouble; just install OEPE 3.5, download it, install CEP components for Eclipse, and you are done with the client/ dev environment. The installation of the server should not pose many difficulties either (http://docs.oracle.com/cd/E28280_01/doc.1111/e14476/install.htm#CEPGS472). When the server is up and running, you can register it in Eclipse(1). The graphical interface will support you in assembling event-handling applications from adapters, processor channels, and event beans; however, knowledge of the internal organization of an XML config and application assembly files (as demonstrated in the earlier code snippets) is always beneficial.

In addition to the Eclipse development environment, you have the CEP server web console (visualizer) with almost identical functionalities, which gives you a quick hand with practically all CQL constructs (2).

Applied SOA Patterns on the Oracle Platform

Parallel Complex Events Processing

LEAVE A REPLY

Please enter your comment!
Please enter your name here