DZone
Thanks for visiting DZone today,
Edit Profile
  • Manage Email Subscriptions
  • How to Post to DZone
  • Article Submission Guidelines
Sign Out View Profile
  • Post an Article
  • Manage My Drafts
Over 2 million developers have joined DZone.
Log In / Join
Please enter at least three characters to search
Refcards Trend Reports
Events Video Library
Refcards
Trend Reports

Events

View Events Video Library

Zones

Culture and Methodologies Agile Career Development Methodologies Team Management
Data Engineering AI/ML Big Data Data Databases IoT
Software Design and Architecture Cloud Architecture Containers Integration Microservices Performance Security
Coding Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks
Culture and Methodologies
Agile Career Development Methodologies Team Management
Data Engineering
AI/ML Big Data Data Databases IoT
Software Design and Architecture
Cloud Architecture Containers Integration Microservices Performance Security
Coding
Frameworks Java JavaScript Languages Tools
Testing, Deployment, and Maintenance
Deployment DevOps and CI/CD Maintenance Monitoring and Observability Testing, Tools, and Frameworks

The software you build is only as secure as the code that powers it. Learn how malicious code creeps into your software supply chain.

Apache Cassandra combines the benefits of major NoSQL databases to support data management needs not covered by traditional RDBMS vendors.

Generative AI has transformed nearly every industry. How can you leverage GenAI to improve your productivity and efficiency?

Modernize your data layer. Learn how to design cloud-native database architectures to meet the evolving demands of AI and GenAI workloads.

Related

  • Shallow and Deep Copies in JavaScript: What’s the Difference?
  • Ultimate Guide to FaceIO
  • What Is Ant, Really?
  • HTTP Deep-Dive With Ballerina: Client Communication

Trending

  • The Full-Stack Developer's Blind Spot: Why Data Cleansing Shouldn't Be an Afterthought
  • Metrics at a Glance for Production Clusters
  • Manual Sharding in PostgreSQL: A Step-by-Step Implementation Guide
  • Endpoint Security Controls: Designing a Secure Endpoint Architecture, Part 2
  1. DZone
  2. Coding
  3. Languages
  4. Accessing Payload, Variables and Environment Properties in Kumologica

Accessing Payload, Variables and Environment Properties in Kumologica

This article will demonstrate how to access or manipulate message payload, variables, and environment variables inside Kumologica flow.

By 
Rohini Arun kumar user avatar
Rohini Arun kumar
·
Oct. 22, 20 · Tutorial
Likes (3)
Comment
Save
Tweet
Share
8.1K Views

Join the DZone community and get the full member experience.

Join For Free

A Kumologica API or service integration can be represented as a connected network of nodes, each node is responsible to take a message (request) and produce zero or many outputs, which in turn becomes the input to the next node. A Kumologica flow uses only 3 elements for the propagation and manipulation of data when moving from one node to the other. 

1. Message — msg

2. Variables — vars

3. Environment — env

flow execution

Message

Message (msg) object is a piece of information that node use to communicate with each other. Nodes work on the object their predefined logic and modify the object. The basic structure of the message object is as follows.

_msgrid

  • _msgid: Unique execution identifier created for each execution. 
  • error: This property will hold the error being caught by the Error Node. 
  • header: This property is an object hold metadata added by a node. Information contained in this object should not be modified by other nodes.
  • payload: This property is an object hold information added by the node. Unlike the header property, this property is meant to be mutable, and it has a special meaning for some nodes. 

How to Access Message Object?

Message object can be accessed in all the nodes with the expression msg. You may access the payload inside the message using the expression msg.payload. Based on the object type of within the payload the content can be further traversed down. Eg: Let's assume that a payload is a JSON object with the following structure.

JSON
 




x





1
{
2
  "details" : {
3
    "name" : "kumo",
4
    "location" : "Kerala"
5
  },
6
  "Country" : "India" 
7
}



In the above JSON payload, the location field can be accessed in any nodes using the following expression.

msg.payload.details.location

Now to set a value to the location filed in the same JSON payload can be done using different ways like using Set-Property node, Datamapper node, or a Function node. Inside the function node, you can set the value to the above-shown JSON payload as given below.

msg.payload.details.location = 'Delhi' 

Or if you want to introduce a new field in the existing payload you can do as follows.

msg.payload.direction = "South"

This will result in the below-given payload output.

JSON
 




xxxxxxxxxx
1


 
1
{
2
  "details" : {
3
    "name" : "kumo",
4
    "location" : "Kerala"
5
  },
6
  "Country" : "India" ,
7
  "Direction" : "South"
8
}



Similarly, you can introduce a new field directly on the msg object structure as well.

msg.mydata = "testdata"

Variables

Variables are temporary storage which can be used when you want to preserve certain content like payload which can be further used at any point in the flow. Variables like message object can be accessed using the expression vars. You can set a variable either using a Set-Property node or a Function node.

How to Access Variable Object?

Inside the Set-Property node, you need to select $vars from the drop-down to create and initialize a variable.

rules

Then provide the variable name. On the to section provide the value you want to set on the variable. For example, in the below Set-Property, I am setting payload inside the variable with the name "mytemp".

rules

You can access the variable to retrieve the content similar to the message object. Eg. Assume that the JSON payload mentioned in the earlier example in the message section is stored in the variable mytemp using the Set-Property node as shown above. We can access the location field in the JSON structure using the below-given expression.

vars.details.location

Environment

Environment variable unlike the regular variable is set from outside the context of Kumologica flow. These are variables injected as part of the environment properties of your lambda application.

How to Access Environment Object?

Environment variables can be accessed using the expression env. The property can be accessed in any node using the following expression. Eg. I have a database hostname that is set as part of the environment and I need to access it inside the flow. 

env.db.hostname

Summary

Know the above 3 elements of Kumologica flow you can manipulate data whichever way you like to build your cool application. All the expressions covered in this article are fundamentally JSONata expressions which means that you can apply the principles of JSONata for the manipulation of your data.

Payload (computing) Property (programming) Object (computer science)

Opinions expressed by DZone contributors are their own.

Related

  • Shallow and Deep Copies in JavaScript: What’s the Difference?
  • Ultimate Guide to FaceIO
  • What Is Ant, Really?
  • HTTP Deep-Dive With Ballerina: Client Communication

Partner Resources

×

Comments
Oops! Something Went Wrong

The likes didn't load as expected. Please refresh the page and try again.

ABOUT US

  • About DZone
  • Support and feedback
  • Community research
  • Sitemap

ADVERTISE

  • Advertise with DZone

CONTRIBUTE ON DZONE

  • Article Submission Guidelines
  • Become a Contributor
  • Core Program
  • Visit the Writers' Zone

LEGAL

  • Terms of Service
  • Privacy Policy

CONTACT US

  • 3343 Perimeter Hill Drive
  • Suite 100
  • Nashville, TN 37211
  • support@dzone.com

Let's be friends:

Likes
There are no likes...yet! 👀
Be the first to like this post!
It looks like you're not logged in.
Sign in to see who liked this post!