Feature Based

Feature based MR rule is created when filtering is based on feature of the input JSON data. Here the feature name is provided in MR rule which is supposed to filter the provided feature only and discard other features.

  • Below is the create rule JSON based on feature only:

{
  "RuleName": "Demo rule",
  "RuleDescription": "Demo rule for user guide",
  "input": {
     "DirectExchange": "Direct.Exchange",
     "RoutingKey": "e325f4fe-a0e3-4252-82af-4c24deb8c0cf"
  },
  "params": [
     {
         "name": "feature",
         "value": "room1"
     },
     {
         "name": "sensorID",
         "value": ""
     },
     {
         "name": "time",
         "value": {
             "starttime": "",
             "endtime": ""
         }
     },
     {
         "name": "expression",
         "value": {
             "if": "",
             "then": "",
             "else": ""
         }
     },
     {
         "name": "",
         "type": "rectangle/circles/polygon",
         "geoFencing": "YES/NO",
         "value": {
             "points": [
                 {
                     "x": "",
                     "y": ""
                 },
                 {
                     "x": "",
                     "y": ""
                 }
             ]
         }
     },
     {
         "name": "ObservedProperties",
         "value": [
             {
                 "name": "",
                 "type": "Text/quantity/count",
                 "value": "",
                 "operator": ""
             }
         ]
     }
   ],
   "output": {
      "TopicExchange": "DemoExchange",
      "Topic": "demo1"
   }
  }

As we can see in the above JSON feature, value provided is room1 which acts as a filtering condition for input data and routes the input data with feature as room1 only. In case input data has feature value other than room1, it will discard the data. Topic exchange name is DemoExchange which we have already created in the topic exchange section.

Now we will create the above rule in the following 2 ways:

  • Using MR API swagger

  • Using MR portal

Using MR API swagger

  • Click on POST /routingRules API in swagger, use the above JSON template and hit Try it out! button, it will create a new MR rule with feature as shown in the image below:

../../../_images/featurerule1.jpg

As we can see in the above image MR rule created with rule ID - 1111 will be used to start this rule. We can refer Start the Routing Channel to start the rule.

Using MR portal

  • Click on Create Rule button in MR rule, fill in all the details as mentioned in the image below and click Create Rule button, it will create a new MR rule with feature as shown in the image below:

../../../_images/featurerule2.jpg
  • After clicking Create Rule button the below message will be dispalyed at the upper right corner with rule ID. Here in our case the rule ID is 1113.

../../../_images/featurerule3.jpg

As we can see in the above image MR rule created with rule ID - 1113 will be used to start this rule. We can refer to Start the Routing Channel to start the rule.

Send Request operation

After the rule is created it needs to be started as mentioned above and then the input JSON can be posted to MR rule using send request API. For this we have to configure and start SSE viewer page and send the observation matching to the MR rule.

  • Below is the matching input SOS observation JSON

{
  "version": "1.0.1",
  "observations": [
    {
         "sensor": "NEXUS1",
         "feature": "room1",
         "record": [
             {
                 "starttime": "1-JAN-2014 15:30:03 IST",
                 "output": [
                     {
                         "name": "OutsideSensorTemp",
                         "value": "46.0",
                         "type": "decimal"
                     },
                     {
                         "name": "temp",
                         "value": "99",
                         "type": "quantity"
                     }
                 ]
             }
         ],
         "meta-data": []
      }
    ]
 }

Here in input JSON we can see that feature name is room1 which is same as MR rule feature. We can now use send request API to verify this rule. Please refer to Execute and View Result section to send the request and view the output in SSE viewer.