Serverless integration with Solace PubSub+ cloud using Kumologica
Publish subscribe model is a very common exchange pattern followed in any message oriented middleware. In this article we are going to demonstrate on how to publish a message to Solace PubSub+ cloud platform from AWS lambda using Kumologica.
For those who are new to Kumologica I would recommend to go through our articles and youtube videos to get an insight.
Training & Certification
For a limited time, Kumologica offers free online certification for developers on https://training.kumologica.com/
Use case
In this use case a plant supervisor is sending the asset information to an asset management application as well as to data lake for reporting purpose. The supervisor is using a mobile client App which is invoking an serverless integration (Kumologica) application that runs on AWS lambda. The integration application will then publish the message into a broker topic (Solace PubSub+) which will be subscribed by the Asset management application and data lake.
Prerequisite
- Solace PubSub+ account— For configuring the Topic and getting the credentials for connecting the topic.
- Kumologica Designer — Download the designer for building the flow.
- AWS account — For running the Kumologica flow as lambda.
Solace node will not be part of the palette by default. You need to click on "Add more nodes" to install the solace node.
Implementation
We will be creating PublisherService flow in Kumologica designer. This flow will expose the endpoint on the resource path /publish.
PublisherService flow
Steps
- Open Kumologica Designer, click the Home button and choose Create New Kumologica Project.
- Enter name (for example PublishService), select directory for project.
- press Create Button.
4. Drag and drop EventListener node to the canvas the provide the following configuration.
Display Name : POST /publish
Provider : AWS
Event Source : Amazon API gateway
Verb : POST
URL : /publish
5. Add a Logger node and wire with the EventListener node. Provide the following message. Wire the logger node to Eventlistener node.
'Request received - ' & msg.payload
6. Add the JSON node to convert JSON string (msg.payload) to Object. Wire the JSON node to the logger.
7. Drag and drop the datamapper node and provide the following configuration. Wire the datamapper to JSON node.
Mapping:{
"asset_name": msg.payload.assetname,
"asset_type":msg.payload.assettype,
"assetid": msg.payload.assetid,
"plantid":msg.payload.plantid,
"floorid":msg.payload.floorid,
"description":msg.payload.description,
"assignedby":msg.payload.assignedby
}
8. Add the Solace node to the canvas and provide the following configurations.
DisplayName: PublishToSolace
Hostname: <<your solace hostname>>
Port: 9443 (default)
Username: <<you solace REST endpoint username>>
Password: <<you solace REST endpoint password>>
Operation: Topic
ContentType: Text
Topic Name: <<Name of the topic endpoint>>
Payload: msg.payload
You can refer the following link to understand how to get the username , password and hostname details of your topic. https://tutorials.solace.dev/rest-messaging/publish-subscribe/
8. Add EventListener End node and wire with the SQS node. Provide the following configuration.
Display Name : Success
Status Code : 200
Content-Type : application/json
Payload : {"status": "published"}
Testing locally
Invoke the endpoint from your postman using the following url: http://localhost:1880/publish
You will be getting the following as response on successful delivery of message to the Solace topic.
{ "status": "published"}
On the Solace portal you could the message transaction queued.
Deployment
- Select AWS icon on the right hand side vertical tab of Kumologica designer, select your AWS Profile.
Note: If you haven’t mapped the your local AWS profile with the designer then you may follow the below video to configure it.
Mapping the AWS profile to Kumologica designer
- Click Connect. If successfully connected will show the rest of the configuration options.
- Set the Memory to 512mb and Timeout as 20 seconds.
- Go to “Trigger” section under cloud tab and select the Amazon API Gateway trigger.
Conclusion
This article has shown how easy to publish an event to Solace PubSub Cloud+ from a serverless provider (AWS) using Kumologica.
Remember Kumologica is totally free to download and use. Go ahead and give it a try, we would love to hear your feedback.