...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
...
Introduction
...
The SOAJS controller is the main gateway for the SOAJS cloud services. It is designed toSome of the SOAJS Gateway features are:
- handle the awareness among the micro-services
- monitor the health of all the registered services
- redirecting the requests into the appropriate services
- decrypt cookies from logged in members requests
In the previous examples, a request to a particular service must be sent to the port that that service is listening to.
However, the controller alleviates this issue. Instead of worrying about ensuring the correctness of the service port number,
it is sufficient to direct the request to the controller's port number, while specifying the name of the service and the API being called.
Service Exploration
...
To turn on the gateway in a development environment you just need to start the environment as follow
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
#sudo go to soajs directoryservices cd /opt/soajs/node_modules/ # install soajs.controller npm install soajs.controller # go to controller directory cd soajs.controller # export necessary environment variables export SOAJS_PROFILE=/opt/soajs/node_modules/soajs.utilities/data/getStarted/profile.js export SOAJS_ENV=test export SOAJS_SRVIP=127.0.0.1 # start the service node . |
...
start --env=example |
The gateway for environment example runs and listens on port 400020000. Its maintenance port is 500021000.
The controller can gateway can be accessed, from the local machine, using the following URL http://127.0.0.1:400020000.
Perform a heartbeat check on the controller to gateway to monitor its status:
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
curl -X GET "http://127.0.0.1:500021000/heartbeat" |
The following response indicates a healthy functioning of the controllergateway.
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
{"result":true,"ts":1425054123486,"service": {"service":"CONTROLLER","type":"rest","route":"/heartbeat"}} |
Using the
...
Gateway
Previously, when calling a service API, a request should contain the port of the service, followed by the API's name.
A problem might arise when the number of services increases.
The controller alleviates gateway alleviates this problem by aggregating all the calls targeting the services registered, and then redirecting each call to the destined service.
Consider an example where a call is made to the testGet API of the example01 service. The service listens on port 40104021.
The following code snippet lists two requests. The first requests directly calls the service using its port.
...
Code Block | ||||||
---|---|---|---|---|---|---|
| ||||||
# Direct request to the example01 service CURL -X GET "http://127.0.0.1:40104021/testGet?firstName=John&lastName=Doe" # Indirect request to the example01 service through the controller CURL -X GET "http://127.0.0.1:400020000/example01/testGet?firstName=John&lastName=Doe" |
Both commands invoke the same API of the same service. However, the controller alleviates the problem of memorizing the port number of each service.
Evidently, the controller has much more important and delicate tasks than solely redirecting calls to their appropriate services.
For further information, the Controller Gateway section provides detailed explanation about this service and its tasks.