jsonwso2wso2-das

WSO2 DAS - Sending multiple events using JSON


I am trying to send multiple events at once, using JSON, sending the following:

{
    "event": {
        "metaData": {
            "meta_timestamp": 4.504343
        },
        "payloadData": {
            "value": 20.44345
        }
    },
    "event": {
        "metaData": {
            "meta_timestamp": 3.57724
        },
        "payloadData": {
            "value": 9.30211
        }
    },
    "event": {
        "metaData": {
            "meta_timestamp": 8.94134
        },
        "payloadData": {
            "value": 35.41315
        }
    }
}

Am I using the correct JSON format?

Currently, the event receiver is ready to receive something like this:

{
    "event": {
        "metaData": {
            "meta_timestamp": 4.504343
        },
        "payloadData": {
            "value": 20.44345
        }
    }
}

I have been reading the documentation, something about "JSON input mapping" but I don't know how to use it (see the image).

Any ideas?


Solution

  • You JSON input mapping for this purpose. If input JSON is an array, each element will treat as an seperate event. Consider following custom JSON file.

    [
        {
           "sensorData": {
    
                   "timestamp": 19900813115534,
                   "powerSaved": false,
                   "id": 501,
                   "name": temperature,
                   "long": 90.34344,
                   "lat": 20.44345,
                   "humidity": 2.3,
                   "temp": 20.44345
               }
           }
        },
        {
           "sensorData": {
                   "timestamp": 19900813115534,
                   "powerSaved": false,
                   "id": 502,
                   "name": temperature,
                   "long": 90.34344,
                   "lat": 20.44345,
                   "humidity": 2.3,
                   "temp": 20.44345
               }
           }
        }
    ]
    

    Assume in the stream you have an meta attribute called "isPowerSaverEnabled" to store "powerSaved" attribute of the above JSON. Then in the JSON path should be $.sensorData.powerSaved and in the "Mapped to" field it should be meta_isPowerSaverEnabled.

    For more information refer the documentation [1]. The sample of the this mapping is available with WSO2CEP pack, you can refer that one as well [2]

    [1] https://docs.wso2.com/display/DAS310/Input+Mapping+Types#InputMappingTypes-JSONinputmappingJSONInputMapping

    [2] https://docs.wso2.com/display/CEP410/Sample+0002+-+Receiving+Custom+JSON+Events+via+HTTP+Transport