Dynamic Service
Setting up Dynamic Service
Setting up a dynamic service allows you to integrate your own micro-services with Connectivity. Through service registration and configuration, your dynamic service can access other Connectivity services. In addition, the dynamic service also supports customized event trigger, giving you an option to integrate Connectivity scripts into your micro-services.
This page assumes you have a Connectivity account & blank solution. In addition, you should have an dynamic service deployed on the same K8s cluster with murano-bundle.
Create dynamic service
If you're building micro-services with nodejs with express and express-openapi, you can use Demo as an example. For other languages or frameworks, using the same logic and payload will get the same result.
On micro-services startup (app.js), register for the service by sending a http post request to pegasus dispatcher's public endpoint (pegasus-dispatcher-public/api/v1/register/).
Cross namespace dynamic service
This is optional. If your micro-service and Connectivity are deployed on different namespaces on K8s within the same cluster. You'll need cross namespace registration. Please update update these environment variables in the demo code
process.env['PLATFORM_NAMESPACE'] = {platform_k8s_namespace};
process.env['LOCAL_NAMESPACE'] = {service_k8s_namespace};
// This will update the host property in the swagger.yaml:
// #host: {service.name}.{service_k8s_namespace}:{port}
Add dynamic service to the solution
On successful registration response, you should see the service under Marketplace
Click on the added dynamic service. In the Element Details Page, click on ADD TO SOLUTION BUTTON, check the Terms of Service and add the external service to your solution.
For testing purpose, you have to add another service, add Keystore service to your solution.
Create endpoint
Navigate to the Endpoints
tab and create a new Http Endpoint. Select the GET
method and give it a path (Eg. /dynamic-service
).
Endpoints are managed by the Webservice Micro-Service and triggered by the request event when an incoming Http request arrives to the public API. A routing layer is done for you to link the event to the different endpoints.
Select your new endpoint. You will see the script editor. Type the following Lua script to return the requests content.
Keystore.set({key="my-key", value="my-key-value-updated"})
return Demoexternalservice.callService({service="Keystore", operation="get", args="my-key"})
request is here provided by the endpoint routing. Learn more here.
Click Save or use CTRL + s keyboard key.
Test with the API documentation page
On the Endpoint page of the solution you will see a document link:
Click on it, and it will get to the automatically generated documentation page for your API with your first endpoint.
Notice the TRY button, click on it to call your first endpoint.
You will get a 200 response with the complete request content.
Interact with dynamic service event trigger
All micro-services enabled in the Solution are available from scripting using the capitalized service alias. A few Core Services
are always available. However, you might need to Add the service to your solution to get it available.
Read more about service calls on the scripting reference.
Dynamic service also supports event trigger. For security, dynamic service can only call its own script.
Let's use now the native Config Service 'listservices' operation to list all services already enabled.
endpoint script
Try your endpoint again to get the result.Deployment on K8s
For K8s deployment, the following steps are required. You should have access to K8s and know how to create helm-charts. You can refer to Demo-K8s-settings
-
Install Linkerd or have Linkerd available in your K8s cluster. You should see linkerd-proxy container within your Connectivity pod.
-
Allow your dynamic service repository to create docker image on AzureDevops, for example, the pipeline.js file in Demo
-
Create helm-chart for the dynamic service and add the helmchart to IoT_infra repository
-
In the helm-chart, configure service and service account name, the service name and service account name must be the same, and it should match regex pattern [a-z0-9] to allow Connectivity to connect to dynamic service for service validation.
-
add linkerd.io/inject: enabled to dynamic service's helm-chart
-
In the azure_pipelines, add dynamic service to both paths and jobs
-
On deployment, add the following variable to values.yaml.
- On deployment, include dynamic service in the helm file.