Use the inbound REST adapter of StreamExplorer to consume events from HTTP POST requests

1

StreamExplorer is a fairly recent product from Oracle – a business user friendly layer around Oracle Event Processor. In various previous articles, I have discussed StreamExplorer. I have demonstrated how SX can consume events from JMS, EDN and from CSV files. This article shows how a stream in StreamExplorer can expose a REST service to which events can be pushed.

image

In this case, we will look at a movie theater. More specifically, we will monitor the visitors entering and leaving the various rooms in the theater so we keep track of the number of people currently present in each room. When rooms are almost full, we may have to stop selling tickets or perhaps open up an additional room showing the same movie. When a room is [almost] empty, perhaps we should cancel the show altogether. When people keep coming and going, there may be a problem we should attend to.

In this case, the events are received by Stream Explorer in the form of JSON messages posted to a REST service. We use a SoapUI test case with requests to send in these events. The test request called aprtyOf3InRoom1, isshown in the figure:

image

The request is configured to be sent to the endpoint http://localhost:9002. That is the endpoint for Stream Explorer (and OEP and more specifically the Jetty server running the OEP domain on top of which Stream Explorer was applied). The (REST) Resource is specified as /cinema. Together this means that this request is sent as a POST request to the end point http://localhost:9002/cinema. So that is where our StreamExplorer application will have to consume the message.

The message itself has a JSON payload with two simple properties: room (to identify a room in the movie theater) and partySize (to stipulate the number of people involved in an observation). Note: the number of people is positive when a party enters the room and negative when it leaves the room.

The TestSuite TestSuiteCinema contains a single test case with a number of steps that simulate events on a slow night in the movie theater.

Create a Stream and a First Exploration for Handling Cinema Events

Create a new Stream. The name is not crucial. The Source Type should be REST.

image

 

Specify the Context Path as /cinema.

image

Define the REST Shape. Set the name to CinemaEntryOrExitEvent. Define two properties: room – of type String – and partySize – of type Integer.

image

Click on Create to create the Stream.

The Exploration wizard opens next. Set a name for the exploration – for example RoomOccupancy. You may provide a description as well.

image

Click on Create.

Configure the Exploration for example like this:

image

The events are aggregated grouped by room. The aggregation to be calculated is a sum over the partySize. This should produce the total number of people in every room. In this case, I have also chosen to have the summary calculated once every 5 seconds and to include in the results only the events from the last 8 hours (which is quite arbitrary).

At this point I create a test case in SoapUI for the REST service – and run it:

image

The exploration starts reporting its findings:

image

 

Because publishing data to a REST service in JSON format is so easy – and is supported from many tools such as SoapUI and technologies including PL/SQL and Java, it is a very convenient way of sending events to a StreamExplorer application, both for development and testing purposes as well as for a production implementation.

Using the PL/SQL procedure described in this article  we can easily send events from inside the Oracle Database to the StreamExplorer stream:

image

– and verify the effects in Stream Explorer. Note that the movie showing in room 2 must be quite awful;-)

image

 

Resources

Getting Started with the REST Adapter in OEP 12c – A-Team Blog

Make HTTP Post call from PL/SQL

Make HTTP Post call from Java

About Author

Lucas Jellema, active in IT (and with Oracle) since 1994. Oracle ACE Director and Oracle Developer Champion. Solution architect and developer on diverse areas including SQL, JavaScript, Kubernetes & Docker, Machine Learning, Java, SOA and microservices, events in various shapes and forms and many other things. Author of the Oracle Press book Oracle SOA Suite 12c Handbook. Frequent presenter on user groups and community events and conferences such as JavaOne, Oracle Code, CodeOne, NLJUG JFall and Oracle OpenWorld.

1 Comment

  1. Hi,

    I have configured the REST adapter at service end which is capable of accepting and replying in JSON format.

    In the response the rest adapter is giving response in below format for the xml i have mapped to.
    {
    “data1” : “value1”,
    “data2” : “value2”,
    “data3” : “value3”
    }

    value1
    value2
    value3

    The issue which i was facing is : when one of the xml element is null the JSON is showing null, but this suppose to show the value like this “”

    below is the transformed ouput.

    Actual:

    value1
    value2

    {
    “data1” : “value1”,
    “data2” : “value2”,
    “data3” : null
    }

    desired:

    {
    “data1” : “value1”,
    “data2” : “value2”,
    “data3” : “”
    }

    Please suggest me the on what basis is the rest adapter is converting into JSON format.