Quick Start with WSO2 Micro Integrator
Let's get started with WSO2 Micro Integrator by running a simple use case on your local environment. In this example, we use a REST API to simulate a simple HTTP service (HelloWorld service) deployed in an instance of WSO2 Micro Integrator. You can deploy this HelloWorld service on a Docker container or on Kubernetes. When invoked, the HelloWorld service will return the following response: {"Hello":"World"}
Follow the topics given below.
Set up the workspace
- Install Docker (version 17.09.0-ce or higher).
- Install Curl.
- To set up the integration workspace for this quick guide, we will use an integration project that was built using WSO2 Integration Studio:
- Download the project file for this guide, and extract it to a known location. Let's call this
<MI_QSG_HOME>
. Go to the
<MI_GS_HOME>
directory. The following project files, and Docker/Kubernetes configuration files are available.hello-world-config-project This is the ESB Config Project folder with the integration artifacts (synapse artifacts) for the HelloWorld service. This service consists of the following REST API:
HelloWorld.xml<api context="/hello-world" name="HelloWorld" xmlns="http://ws.apache.org/ns/synapse"> <resource methods="GET"> <inSequence> <payloadFactory media-type="json"> <format>{"Hello":"World"}</format> <args/> </payloadFactory> <respond/> </inSequence> <outSequence/> <faultSequence/> </resource> </api>
hello-world-config-projectCompositeApplication This is the Composite Application Project folder, which contains the packaged CAR file of the HelloWorld service.
Dockerfile This Docker configuration file is configured to build a Docker image for WSO2 Micro Integrator with the HelloWorld service.Note that this file is configured to use the community version of the WSO2 Micro Integrator base Docker image (from DockerHub). If you want to use the Micro Integrator that includes the latest product updates, you can update the image name in this Docker file as explained here.
k8s-deployment.yaml This is sample Kubernetes configuration file that is configured to deploy WSO2 Micro Integrator in a Kubernetes cluster.
- Download the project file for this guide, and extract it to a known location. Let's call this
Run on Docker
Once you have set up your workspace, you can run the HelloWorld service on Docker:
Build a Docker image
Open a terminal, navigate to the <MI_QSG_HOME>
directory (which stores the Dockerfile), and execute the following command to build a Docker image with WSO2 Micro Integrator and the integration artifacts.
docker build -t hello_world_docker_image .
This command executes the following tasks:
- The base Docker image of WSO2 Micro Integrator is downloaded from DockerHub and a custom, deployable Docker image of the Micro Integrator is created in a Docker container.
- The CAR file with the integration artifacts that define the HelloWorld service is deployed.
Run Docker container
From the <MI_QSG_HOME>
directory, execute the following command to start a Docker container for the Micro Integrator.
docker run -d -p 8290:8290 hello_world_docker_image
The Docker container with the Micro Integrator is started.
Invoke the Micro Integrator (on Docker)
Open a terminal, and execute the following command to invoke the HelloWorld service:
curl http://localhost:8290/hello-world
Upon invocation, you should be able to observe the following response:
{"Hello":"World"}
Run on Kubernetes
Once you have set up your workspace, you can run the HelloWorld service on Kubernetes:
Install Minikube
Let's use Minikube to run a Kubernetes cluster for this example.
- Install Minikube. Once you have completed this step, you should have kubectl configured to use Minikube from your terminal.
Start Minikube from your terminal:
minikube start
Execute the command given below to start using Minikube's built-in Docker daemon. You need this Docker daemon to be able to create Docker images for the Minikube environment.
eval $(minikube docker-env)
Now you can build a Docker image for your HelloWorld service in Minikube as explained below.
Build a Docker image
Open a terminal, navigate to the <MI_QSG_HOME>
directory (which stores the Dockerfile), and execute the following command to build a Docker image (with WSO2 Micro Integrator and the integration artifacts) in the Minikube environment.
docker build -t wso2-mi-hello-world .
Run container (on Minikube)
Follow the steps given below to start a Docker container for Docker image on Minikube.
Navigate to the
<MI_QSG_HOME>
directory (which stores thek8s-deployment.yaml
file), and execute the following command:kubectl create -f k8s-deployment.yaml
Check whether all the Kubernetes artifacts are deployed successfully by executing the following command:
kubectl get all
You will get a result similar to the following. Be sure that the deployment is in 'Running' state.
NAME READY STATUS RESTARTS AGE pod/mi-helloworld-deployment-56f58c9676-djbwh 1/1 Running 0 14m pod/mi-helloworld-deployment-56f58c9676-xj4fq 1/1 Running 0 14m NAME TYPE CLUSTER-IP EXTERNAL-IP PORT(S) AGE service/kubernetes ClusterIP 10.96.0.1 <none> 443/TCP 25m service/mi-helloworld-service NodePort 10.110.50.146 <none> 8290:32100/TCP 14m NAME READY UP-TO-DATE AVAILABLE AGE deployment.apps/mi-helloworld-deployment 2/2 2 2 14m NAME DESIRED CURRENT READY AGE replicaset.apps/mi-helloworld-deployment-56f58c9676 2 2 2 14m
Invoke the Micro Integrator (on Minikube)
Open a terminal, and execute the command given below to invoke the HelloWorld service. Be sure to replace MINIKUBE_IP with the IP of your Minikube installation.
curl http://MINIKUBE_IP:32100/hello-world
Upon invocation, you should be able to observe the following response:
{"Hello":"World"}
- Use WSO2 Micro Integrator's CLI Tool to check the integration artifacts deployed in the Micro Integrator instance.
- Use Prometheus and other tools to monitor your Micro Integrator instance.