Operation on Routing Rule

It has four services for performing operation on MR rule:

1) Start the rule

2) Stop the rule

3) Update the rule

4) Delete the rule

Start the Routing Channel

It starts the send receive channel against the particular rule ID. This web service has the following functionalities:

  • POST http://<domain name>/MessageRouting/v2.0/routingChannel/{ruleid}/start

here ruleid is the ID of created MR rule which needs to be started.

Following mediums can be used to start MR rule:

By MR API swagger

  • Provide the rule ID of MR rule in the given text box and click on Try it out! button of swagger, MR rule will be started and response from API is received as mentioned in the image below:

../../_images/MR_start.jpg

By MR portal

  • Provide the rule ID of MR rule in the given text box beside search button and rule description will be displayed. Click on Start button under action drop down list, here MR rule ID 33 will be started and response from portal is received as mentioned in the image below:

../../_images/MR_start_portal1.jpg
  • Once you click the start button success message will be displayed for a while and the list will be reset to load latest status:

../../_images/MR_start_portal2.jpg

Stop the Routing Channel

It stops the send receive channel against the particular rule ID. This web service has the following functionalities:

  • POST http://<domain name>/MessageRouting/v2.0/routingChannel/{ruleid}/stop

here ruleid is the ID of created MR rule which needs to be stopped.

Following mediums can be used to stop MR rule:

By MR API swagger

  • Provide the rule ID of MR rule in the given text box and click on Try it out! button of swagger, MR rule will be stopped and response from API is received as mentioned in the image below:

../../_images/MR_stop.jpg

By MR portal

  • Provide the rule ID of MR rule in the given text box beside search button and rule description will be displayed. Click on Stop button under action drop down list, here MR rule ID 33 will be stopped and response from portal is received as mentioned in the images below:

../../_images/MR_stop_portal1.jpg
  • Once you click the Stop button success message will be displayed for a while and the list will be reset to load latest status:

../../_images/MR_stop_portal2.jpg

Update Routing Rule

This service is used to update a particular routing rule with its rule ID created by a tenant. Rule can only be updated by the creator of the rule. Rule can be updated by the following two mediums:

  • Using MR API swagger

  • Using MR portal

Using MR API swagger

Following is the URL for describing a routing rule by ID in MR:

  • PUT http://<domain name>/MessageRouting/v2.0/routingRules/71

Template for update rule remains the same as of create rule. Following is the sample MR rule to be updated with the given template:

{
  "Status": "Created",
  "RuleID": 254,
  "RuleName": "Demo rule",
  "RuleDescription": "Demo rule for user guide",
  "parallelismFactor": 1,
  "input": {
    "type": "",
    "DirectExchange": "Direct.Exchange",
    "RoutingKey": "e325f4fe-a0e3-4252-82af-4c24deb8c0cf",
    "MQName": ""
  },
  "params": [
    {
      "name": "feature",
      "value": "room1"
    },
    {
      "name": "sensorID",
      "value": ""
    },
    {
      "name": "time",
      "value": {
        "starttime": "",
        "endtime": ""
      }
    },
    {
      "name": "expression",
      "value": {
        "if": "",
        "then": "",
        "else": ""
      }
    },
    {
      "name": "ObservedProperties",
      "value": []
    }
  ],
  "output": {
    "TopicExchange": "DemoExchange",
    "Topic": "demo1"
  }
}

Following is the update rule JSON for updating the above rule:

{
           "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": "NEXUS1"
                   },
                   {
                           "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"
           }
   }

Here in update rule JSON sensor ID has been updated which in earlier rule was missing. After the update is performed the sensor ID as NEXUS1 is updated. The image below shows the steps:

../../_images/routingrule_Update1.jpg
  • Below is the updated rule ID 254:

{
        "Status": "Created",
        "RuleID": 254,
        "RuleName": "Demo rule",
        "RuleDescription": "Demo rule for user guide",
        "parallelismFactor": 1,
        "input": {
                "type": "",
                "DirectExchange": "Direct.Exchange",
                "RoutingKey": "e325f4fe-a0e3-4252-82af-4c24deb8c0cf",
                "MQName": ""
        },
        "params": [{
                        "name": "feature",
                        "value": "room1"
                },
                {
                        "name": "sensorID",
                        "value": "NEXUS1"
                },
                {
                        "name": "time",
                        "value": {
                                "starttime": "",
                                "endtime": ""
                        }
                },
                {
                        "name": "expression",
                        "value": {
                                "if": "",
                                "then": "",
                                "else": ""
                        }
                },
                {
                        "name": "ObservedProperties",
                        "value": []
                }
        ],
        "output": {
                "TopicExchange": "DemoExchange",
                "Topic": "demo1"
        }
}

Note

If the rule is in started condition, then it first stops the rule, updates and starts it automatically. But in case the rule is in created or stopped condition, it will just update the rule. If you keep any non mandatory field as blank then during rule update that particular field will not be updated. So while keeping topic exchange as blank it will not be updated however, if you keep topic name as blank then it will be created automatically as the following convention:

  • If both feature and sensor is specified in the JSON - <tennant_id>+”.”+<featureId>+”.”+<sensorid>+”.*” .

  • If sensor is not specified in the JSON - <tennant_id>+”.”+<featureId>+”.*” .

  • If feature is not specified in the JSON - <tennant_id>+”.*”+”.”+<sensorid> .

  • If feature & sensor is not specified in the JSON - <tennant_id>+”.*” .

Note

“parallelismFactor” is an optional field if not defined it takes default value as 1. It accepts in between 1 to 10. It helps to increase the throughput of the rule if it takes a long time.

Using MR portal

Usin MR portal the update of MR rule can be performed easily as shown in the image below:

../../_images/routingrule9.jpg

After the rule is searched and expanded to update, provide the required details to be updated as below:

../../_images/routingrule10.jpg

After providing all the details click on update button to update the rule as below:

../../_images/routingrule11.jpg

Delete a Routing Rule

This service is used to delete a particular routing rule with its rule ID created by a tenant. Rule can be deleted by the creator of the rule only. Rule can be deleted by the following two mediums:

  • Using MR API swagger

  • Using MR portal

Using MR API swagger

The following is the URL for describing a routing rule by ID in MR:

  • DELETE http://<domain name>/MessageRouting/v2.0/routingRules/1160

Below image shows the steps to delete a routing rule in MR:

../../_images/routingrule4.jpg

Using MR portal

MR rule can be deleted from MR portal as well, after the rule is searched click on delete button to delete the rule as shown below:

../../_images/routingrule12.jpg