In the following use-case, a typical bank that has partnered with an insurance provider through Open Finance concepts, exposes a managed WebSocket API using WSO2 API Manager. The subscribers of this API can receive approved loan requests that require mortgage insurance, with bundled mortgage insurance quotes specific to each borrower. This would allow the bank employees to streamline the loan approval process and present the borrowers with seamless housing loans plus insurance policies.
-
Download WSO2 API Manager 4.0(Zip archive) from https://wso2.com/api-manager/#
-
Download WSO2 Streaming Integrator 4.0 listed under 'Other components' of https://wso2.com/api-manager/#
-
Dowloand the Streaming Integrator tooling from https://wso2.com/integration/streaming-integrator/
-
Follow the prerequisites of https://apim.docs.wso2.com/en/latest/use-cases/streaming-tutorials/expose-a-kafka-topic-as-a-managed-websocket-api/#prerequisites to download and install Kafka, setting port offsets in API Manager, enabling service catalog in Streaming Integrator and finally starting up all the servers.
-
Extract the Streaming Integrator Tooling pack to a preferred location. Hereafter, the extracted location is referred to as <SI_TOOLING_HOME>.
Navigate to the <SI_TOOLING_HOME>/bin directory and issue the appropriate command depending on your operating system to start the Streaming Integration tooling.
For Windows: tooling.bat
For Linux/MacOS: ./tooling.sh
Access the Streaming Integration Tooling via the http://<HOST_NAME>:<TOOLING_PORT>/editor URL. 6. Open the deployment.toml file of WSO2 API Manager and update the port(s) of the websocket server endpoints with below port numbers. This is assuming that the port offset for API Manager was set to '5' as listed in step 4.
ws_endpoint = "ws://localhost:9104"
wss_endpoint = "wss://localhost:8104"
- Run the sample Insurance backendservice(InsuranceService.bal) in Ballerina . (https://ballerina.io/1.0/learn/how-to-deploy-and-run-ballerina-programs/#running-standalone-source-code)
- Open Streaming Integrator tooling and import (or create new with following content) 'HomeLoanRequestApp.siddhi' and 'PMIQuoteProviderApp.siddhi'.
- Go to 'Deploy' -> 'Deploy to Server'.
- Add a new server representing your Streaming Integrator server (Following are the default vaules such as Host:localhost,HTTPS Port:9443,User Name/Password)
- Deploy above siddhi apps to the created server. When service catalog feature is enabled through Prerequisites step 4, the deployed Siddhi App with Async API specification will be automatically made available in WSO2 API Manager.
- Log into WSO2 API Manager publisher portal and go to 'Services' tab and you should be able to view your developed service listed. Click on the + icon to create a managed Websocket API out of it like below.
-
Log in to API Developer portal and subscribe to the published API by creating an application and generating a token under production.
-
Install wscat client. (npm install -g wscat)
-
Connect to the Websocket API similar to below. Make sure that the context you list is the API context that was provided when creating the API.
wscat -c ws://localhost:9104/quote/insurance/1.0.0 -H "Authorization: Bearer [accesstoken]"
4.To run the Kafka command line client, issue the following command from the <KAFKA_HOME> directory.
bin/kafka-console-producer.sh --broker-list localhost:9092 --topic loan_request_topic
-
In the same terminal, publish events similar to below format. (Please note that PMI quotes will be provided only to loan requests with less than 20% down payment from the house value ). Make sure the backend service (InsuranceService.bal) has the necessary values as credit scores/insurance rates are hardcoded.
{"event":{ "loanAppID":"1111", "customerID":"81454", "houseValue":10000, "downPayment":50}}
-
Once events are published to first Kafka topic you can view following output through the subscribed Websocket API.