Tuesday, May 24, 2016

OEP - Hello World

This blog will walk you thru building a very basic OEP application. components. So this application reads a csv file. The csv file contains list of transactions and contains data like TransactionID, CustomerID, TrasactionValue. In this blog, we will be reading the CSV file and output it to the console.

1. Create new OEP Jdeveloper Project

2. Create supporting java classes

i. Right click on the OEP Project and select "Create New Java Class"



ii. Create a Class named "Transaction" & create private members within it (trasactionID:int, customerId:int, transactionValue:float). Create the setters/getters with it.

package demoprj;

public class Transaction {
    
    int transactionId;
    
    float transactionValue;
    
    int customerId;
    
    public Transaction() {
        super();
    }

    public void setTransactionId(int transactionId) {
        this.transactionId = transactionId;
    }

    public int getTransactionId() {
        return transactionId;
    }

    public void setTransactionValue(float transactionValue) {
        this.transactionValue = transactionValue;
    }

    public float getTransactionValue() {
        return transactionValue;
    }

    public void setCustomerId(int customerId) {
        this.customerId = customerId;
    }


    @Override
    public String toString() {
        // TODO Implement this method
        return new Integer(transactionId).toString();

    }

    public int getCustomerId() {
        return customerId;
    }
}

iii. Create another class named "TransactionListener". This class implements com.bea.wlevs.ede.api.StreamSink. 

package demoprj;

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

public class TransactionListener implements StreamSink {
    public TransactionListner() {
        super();
    }

    @Override
    public void onInsertEvent(Object object) throws EventRejectedException {
        if (object instanceof Transaction) {
        Transaction transactionEvent = (Transaction) object;
        System.out.println("Event: " + transactionEvent);
        }
    }
}


2. Create supporting Event Types

i. Click on the EPN Diagram from the left navigation and click on Event Type Tab & Click on the + icon to create new event Type




ii. Create a new event type named "Transaction" and associated the recently created Transaction java class. Save the project.



3. Drag CSVInbound from the advanced adapter to the EPN Diagram







i. This opens up the CSVInbound configuration screen. Leave the default as its .i.e. Adapter ID: csv-inbound-adapter and configuration location as: processes.xml & Click Next



ii. Select the event type as "Transaction", Source URL as "file:///demo/transaction.csv (this would change depending upon your environment), Event Interval as 1 & Initial Delay as 2 & Click Finish


iii. You should see the csv-inbound-adapter in your EPN diagram as shown in the diagram.


4. Configure: Channels is away by which you can transfer events from one stage to another in the EPN. 



i. Drag Channel from EPN components to EPN Page

ii. Select eventType as Transaction and leave default values to channelID


iii. Re Do the above to steps and name the channel ID as output channel & event type to Transaction.

5. Configure Beans: Beans are listener events, that receive events from the channel and works on those events. In my blog ,I am going to print the information to the console.

i. Drag Bean to EPN diagram




ii. Select bean class to "demoprj.TransactionListner" & leave the bean ID to default



6. The final step is to add a Processor. The process would be added between the channel & output channel. The Oracle CQL code queries the events sent to the processor from Channel. In a real-world scenario, this component typically executes additional and possibly much more processing of the events from the stream, such as selecting a subset of events based on a property value, grouping events, and so on using Oracle CQL.

i. Drag Processor component on the EPN Diagram.




ii. Without changing the default values click Ok (Processor ID: processor & FileName: Processor.xml)



iii. Right click on the dropped component and click on "Go to Configuration Source"


iv. Make sure channel name is correct. The correct query should be

<rules>
      <query id="ExampleQuery"><![CDATA[ 
 select * from channel [now] ]]></query>
    </rules>

7. Connect CSV Inbound adapter to channel,channel to processor, processor to outputchannel and output channel to bean.,  & refresh it. The EPN diagram should look like the below


8. Right-click the OEP project and select Deploy > New Deployment Profile.

Monitor the Server Console, you should be able to see the output as shown below





Sample Content of CSV file being used in this blog

transactionId,transactionValue,customerId
1,10.5,5001
2,10.5,5001
3,10.5,5001
4,10.5,5002
5,10.5,5004

No comments: