Search code examples
wso2custom-adapterwso2-cep

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


Solution

  • 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