A sample command-processor which adds a timestamp in response.
A Command represents an asynchronous unit of work.
A command document is a json document with type field value as command & ~status filed. Command document format is similar to an HTTP request, with a request and response section contained in the same document.
Any HTTP enabled micro-service.
Micro-Service tasked with routing pending command documents to configured Command Processors.
The Command Router manages the state of a given command from the time the document arrives on the server, until the router writes the result from an invoked Command Processor to the response section of the document. The Command Router will translate a command document into an equivalent HTTP request to a Command Processor. The HTTP response from the Command Processor will be serialized and placed in the response section of the originating command document.
Registering Command Processor
PM CLI tool needs following two parameters to register a Command Processor:
command route and a Command-Processor-endpoint-url.
ex. pm add-route '/cmdp_test/' 'my-command-processor.run.aws-usw02-pr.ice.predix.io' Note: (you can use --debug option to see what it is doing behind the scene)
command-document example:
`
{
"type": "command", //should be of type command
"~userid": usera_ge_com, // replace . & @ with _ from username (if email address is used)
"channels": ["entity_" + usera_ge_com],
"~status": "pending",
// command router reads this and hit command processor based on parameters
"request": {
"uri": "/cmdp_test/",
"method": "PUT",
"headers": {},
"body": { //whatever goes inside body will be passed to command processor
"abc" : 1,
"some key" : "some value"
}
}
}`
It is assumed that you already have a running instances of Predix Mobile cloud services and have installed the Predix Mobile command line tool.
When running on a development system environment the configuration found in config/default.json will be used to configure whereas manifest.yml will be used when pushed to CF.
Logging level can be changed in js/bunyanLogger.js file. Default is trace and src is true.
Checkout this repository, open the folder in a terminal window, and execute:
npm install
Checkout this repository, open the folder in a terminal window, and execute:
cf push
A common workflow is outlined below:
- push this command-processor to cf.
- Get command-processor url (urls field of
cf apps). - run
pm add-route <command-route> <processor-url> - Push Sample WebApp to Mobile backend
pm publish