Obaid
Obaid

Reputation: 237

WSO2 CEP - Custom Receiver Adapter: Event Formats

I am trying to build a custom receiver adaptor. Which will read from CSV file and push events to a stream. As far a I understand, we have to follow any of the WSO2 standard format(TEXT, XML or JSON) to push data to a stream.

Problem is, CSV files doesn't match with any of the standard format stated above. We have to convert csv values to any of the supported format within the custom adapter. As per my observation, WSO2 TEXT format doesn't support comma(,) within a string value. So, I have decided to convert CSV JSON.

My questions are below:

  1. How to generate WSO2 TEXT events if values ave comma ?
  2. (if point 1 is not possible) In my custom adapter MessageType, if I add either only TEXT or all 3 (TEXT, XML, JSON) it works fine. But if I add only JSON I get below error. My target is to add only JSON and convert all the CSV to JSON to avoid confusion.

    [2016-09-19 15:38:02,406] ERROR {org.wso2.carbon.event.receiver.core.EventReceiverDeployer} - Error, Event Receiver not deployed and in inactive state, Text Mapping is not supported by event adapter type file

Upvotes: 1

Views: 151

Answers (2)

Obaid
Obaid

Reputation: 237

I have just made it. Not an elegant way. However it worked fine for me.

As I have mentioned, JSON format is the most flexible one to me. I am reading from file and converting each line/event to WSO2 JSON format.

Issue with this option was, I want to limit message format only to JSON from management console ("Message Format" menu while creating new receiver). If I add only JSON [supportInputMessageTypes.add(MessageType.JSON)] it shows error as I mentioned in question#2 above.

The solution is, instead of putting static variable from MessageType class, use corresponding string directly. So now, my method "getSupportedMessageFormats()" in EventAdapterFactory class is as below:

@Override public List<String> getSupportedMessageFormats() { List<String> supportInputMessageTypes = new ArrayList<String>(); // just converting the type to string value // to avoid error "Text Mapping is not supported by event adapter type file" String jsonType = MessageType.JSON; supportInputMessageTypes.add(jsonType); //supportInputMessageTypes.add(MessageType.JSON); //supportInputMessageTypes.add(MessageType.XML); //supportInputMessageTypes.add(MessageType.TEXT); return supportInputMessageTypes; }

My request to WSO2 team, please allow JSON format event adapter type file.

Thanks, Obaid

Upvotes: 0

Dilini
Dilini

Reputation: 787

To read from CSV file and push events to a stream, you could use the file-tail adapter. Refer the sample 'Receiving Custom RegEx Text Events via File Tail'. This sample contains the regex patterns which you could use to map your CSV input.

In addition to this, as Charini has suggested in a comment, you could also check out the event simulator. However, the event simulator is not an event receiver - meaning, it will not receive events in realtime, rather it will "play" a previously defined set of events (in the CSV file, in this case) to simulate a flow of events. It will not continuously monitor the file for new events. If you want to monitor the file for new events, then consider using the file-tail adapter.

Upvotes: 0

Related Questions