0% found this document useful (0 votes)
63 views

Node Red

Node Red is an open source programming tool that allows users to visually create flows using nodes with different functionalities. It provides an easy way to integrate APIs and perform tasks like data transformation without writing code. Some key benefits are that it is easy to learn and use, supports visual flow-based programming, and makes debugging simple. Common nodes used include Inject, Debug, Function, Switch, Change, SQLResult, and HTTP nodes. APIs can be created using HTTP In and Response nodes. Node Red runs on port 8000 and is accessed via the localhost URL. Sample flows are provided to demonstrate polling data from a database and calling an external API via RabbitMQ and HTTP triggers.

Uploaded by

ramesh333nadar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
63 views

Node Red

Node Red is an open source programming tool that allows users to visually create flows using nodes with different functionalities. It provides an easy way to integrate APIs and perform tasks like data transformation without writing code. Some key benefits are that it is easy to learn and use, supports visual flow-based programming, and makes debugging simple. Common nodes used include Inject, Debug, Function, Switch, Change, SQLResult, and HTTP nodes. APIs can be created using HTTP In and Response nodes. Node Red runs on port 8000 and is accessed via the localhost URL. Sample flows are provided to demonstrate polling data from a database and calling an external API via RabbitMQ and HTTP triggers.

Uploaded by

ramesh333nadar
Copyright
© © All Rights Reserved
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 14

NODE RED

Document Version: 1.0


06th April,2021
Created By : Sonam Gaur
Table of Contents
Node Red....................................................................................................................... 3
Why to Use Node Red?................................................................................................. 3
Basic Information......................................................................................................... 3
Get Started.....................................................................................................................5
Commonly used Nodes.................................................................................................5
Create API in Node Red..............................................................................................10
How to call Node Red created API............................................................................ 10
References...................................................................................................................12
Node Red

Node is Event driven flow based application. It is programming tool designed to


create flows with various nodes having different functionalities and helps to
integrate API easily into the application.

Why to Use Node Red?

1. Easy to Learn and Use


Node Red allows to use Java script programming language, which is easy to
understand and learn.

2. Flow Based Programming


Who wants to write long code files, when the same functionality can be
performed in Node red by just creating flows and wiring the nodes.

3. Debugging is easy
We can check what action is performed at each node and catch the error message
is easily captured in front end as well as in Log files.

Basic Information

Some basic information that should be known before using Node Red in
Funds/Wealth System.

1) Data Base and RabbitMQ details are added in config.json file

We can add multiple database and rabbitmq details under config.json file. A tag is
given to each database detail, using the tags we can connect to a DB and perform
SQL queries.
Below Example include only on DB and rabbitmq detail:

2) Command to start Node Red service.

Traverse to Node red folder and run “npm start” command.


3) Node red runs on port 8000

4) Access Node Red using below URL

URL: localhost:8000/red

In place of localhost, the URL of application can be passed.


Node Red can also be accessed from inside the application by logging into the
application.

Get Started

Once we access Node Red, we can see the below screen with different panels.

- Flow is created in center screen


- Nodes are picked from left panel (drag and drop in the center screen)
- Information,Help and Debug panel is in right side
- Save, Login, Import/Export is in top right corner of the screen

Commonly used Nodes

1) Inject
Used to Inject Message or Timestamp or Trigger start of any flow. It can be
automatically triggered at interval of times.

2) Debug
Used to see what message is displayed in selected node in Debug panel(right
side).
By default message is displayed under msg.payload( msg.payload is default
message object property in Node Red, we can define our own properties under
message object like msg.topic,msg.resultset, msg,msgid etc )

3) Function
Used to write a Javascript function in Node red. We can do calculation, write
conditional statements, declare variables or message properties inside Function
Node.

4) Switch
Used to route messaged based on any condition defined upon message value.

5) Change
Used to set(copy one message to another), change(replace any string or
message), delete(delete any message property), move(move message from one
property to another) message properties.

Example:

Msg Properties are defined below:


In above picture, “Hi” is replaced with “Bye” in msg.topic (change rule) and
msg.topic is copied to msg.payload(set rule always copies value from 2nd to 1st
object)

In above picture, msg.topic is deleted (delete rule) and msg.payload is moved to


msg.data(move rule always moves value from 1st to 2nd object)
6) SQLResult
Used to execute SQL queries. In this node we define pool name as the tag given to
the database details inside config.json file. Output is displayed in the mentioned
message property.

Example to pass message property values in SQL query.

Below, we have defined msg.payload.data as “Welcome”

The same msg.payload.data value is passed in Select Query using the templating
‘<%=data%>’ (Here we directly call the property “data” which is inside
msg.payload) and the output is shown inside msg.resultset
7) MQin
Used to fetch the data passed to Rabbit MQ. Below are the parameter that we
need to define in MQin node.

Queue: Queue name which you want to define on your own


Exchange: jobcenter (by default)
Routing Key: Event name which is passed to Rabbit MQ

Example: On creation of client the below Event object is passed from application
to RabbitMQ.

{"eventname": "client.create", "workflow": "client",


"data":{"client_id":"208"},"uid":"" ,"userObj":{"user_id":""} }

In below picture, we have defined our own queue name as “corporateClient”,


exchange by default as jobcenter and routing key is the eventname taken from
above event object which is “client.create”

Using this Node we can fetch the client id which is created on client.create event.
Similarly, there will be other events which will be generated on
creation,modification,authorization,unauthorization,deletion of any records.

8) Http Request
Used to Send http Request to any third party URL and receive response in string,
JSON or binary buffer format. If any certificate is not attached then we have to
define msg.rejectUnauthorized = false; otherwise Certificate error will be shown.
Create API in Node Red

First thing that is required to create a API in Node red is the request and
response nodes.
We have to use “http in” node to create a endpoint which will be called for
listening request of API and “http response” to send response back to requests
received from an HTTP Input node.

Example:
By looking at below API flow, we can identify that, when the API will be called, a
request is received at Http In node->Some data is fetched in msg.payload ->
Some SQL query is executed inside SQLResult node -> Response is sent back
using Http Response node.

How to call Node Red created API

We have defined a name to endpoint created inside “Http In” node. In below
picture the endpoint URL is defined as “/payment”.
When the above API will called the final endpoint URL will be as below:

“https://localhost/jcnr/api/payment”

In Place of localhost we can specify the application URL.

Lets call the above API from Postman Application

In the request we have specified the endpoint to call and inside body we are
passing a data in JSON format.

Inside Node red, we have fetched the Body request in first debug node and after
running the SQL query we received an array and that same value is passed back
as response.

Same Array of object is the Response received in Postman.


References

Import below sample flow with Inject Message trigger

[{"id":"83140006.acc1f","type":"tab","label":"EQ-CASHIN-
POLL","disabled":false,"info":""},{"id":"d55f6f15.06f05","type":"inject","z":"83140006.acc1f","na
me":"","props":[{"p":"payload"},{"p":"topic","vt":"str"}],"repeat":"1200","crontab":"","once":false,
"onceDelay":0.1,"topic":"","payload":"","payloadType":"date","x":350,"y":180,"wires":[["6984e48
0.35bc0c"]]},{"id":"6984e480.35bc0c","type":"SQLresult","z":"83140006.acc1f","name":"fetch
PND data","output":"resultset","pool":"ideal","SQL":"select SERIALNO from impleqcashin where
status='PND' and
rownum=1","x":630,"y":220,"wires":[["c8a57b75.60e9c8"]]},{"id":"2135c93c.bb0276","type":"ch
ange","z":"83140006.acc1f","name":"REFID
payload","rules":[{"t":"set","p":"payload","pt":"msg","to":"{}","tot":"json"},{"t":"move","p":"results
et[0].SERIALNO","pt":"msg","to":"payload.SERIALNO","tot":"msg"},{"t":"set","p":"rejectUnauthori
zed","pt":"msg","to":"false","tot":"bool"},{"t":"set","p":"SERIALNO","pt":"msg","to":"payload.SERI
ALNO","tot":"msg"}],"action":"","property":"","from":"","to":"","reg":false,"x":880,"y":260,"wires":
[["ed5f494b.ef2168","68264c58.3fd124"]]},{"id":"ed5f494b.ef2168","type":"debug","z":"831400
06.acc1f","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"pay
load","targetType":"msg","statusVal":"","statusType":"auto","x":1070,"y":180,"wires":[]},{"id":"9f
6ecca6.68e6e","type":"debug","z":"83140006.acc1f","name":"","active":true,"tosidebar":true,"con
sole":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":1270,"y":300,
"wires":[]},{"id":"c8a57b75.60e9c8","type":"switch","z":"83140006.acc1f","name":"check
query","property":"resultset","propertyType":"msg","rules":[{"t":"nempty"},{"t":"empty"}],"check
all":"true","repair":false,"outputs":2,"x":710,"y":300,"wires":[["2135c93c.bb0276"],["86354917.1
ba238"]]},{"id":"c5c0df24.50c56","type":"debug","z":"83140006.acc1f","name":"","active":true,"t
osidebar":true,"console":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"aut
o","x":1150,"y":380,"wires":[]},{"id":"86354917.1ba238","type":"change","z":"83140006.acc1f","
name":"","rules":[{"t":"set","p":"payload","pt":"msg","to":"No data
found","tot":"str"}],"action":"","property":"","from":"","to":"","reg":false,"x":900,"y":380,"wires":[[
"c5c0df24.50c56"]]},{"id":"68264c58.3fd124","type":"http
request","z":"83140006.acc1f","name":"","method":"POST","ret":"txt","paytoqs":"ignore","url":"ht
tps://3.7.239.74/jcnr/api/cashinout","tls":"","persist":false,"proxy":"","authType":"","x":1070,"y"
:280,"wires":[["9f6ecca6.68e6e"]]}]

Import below sample flow with RabbitMQ trigger

[{"id":"a15e7174.d1577","type":"tab","label":"IR0 risk profile


tag","disabled":false,"info":""},{"id":"2ccd280e.8061a8","type":"mqin","z":"a15e7174.d1577","na
me":"Read MQ
msg","mq":"","queue":"riskupdate","exchange":"jobcenter","routingkey":"client.update","x":180,"
y":60,"wires":[["d64e1564.2d0888"]]},{"id":"7124d9f9.fe67a8","type":"debug","z":"a15e7174.d1
577","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","ta
rgetType":"full","statusVal":"","statusType":"auto","x":450,"y":200,"wires":[]},{"id":"d64e1564.2d
0888","type":"change","z":"a15e7174.d1577","name":"","rules":[{"t":"set","p":"payload.client_id",
"pt":"msg","to":"payload.data.client_id","tot":"msg"}],"action":"","property":"","from":"","to":"","re
g":false,"x":350,"y":120,"wires":[["7124d9f9.fe67a8","baced0ef.7ed9e"]]},{"id":"baced0ef.7ed9e",
"type":"SQLresult","z":"a15e7174.d1577","name":"","output":"payload","pool":"ideal","SQL":"upd
ate wm_client_master set cl_risk_profile='Execution' where client_id like '<%=client_id%>' and
advisory='N'","x":450,"y":280,"wires":[["ab102f8f.76a8a"]]},{"id":"ab102f8f.76a8a","type":"debu
g","z":"a15e7174.d1577","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"
complete":"false","statusVal":"","statusType":"auto","x":660,"y":320,"wires":[]}]
Import below sample flow for creating API in Node Red

[{"id":"976ff8f0.4a5d38","type":"tab","label":"AML_Payment","disabled":false,"info":""},{"id":"71
6deea0.cc87d","type":"debug","z":"976ff8f0.4a5d38","name":"","active":true,"tosidebar":true,"co
nsole":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":530,"y":240,
"wires":[]},{"id":"cef75052.1b72b","type":"SQLresult","z":"976ff8f0.4a5d38","name":"","output":"
payload","pool":"ideal","SQL":"select wcm.global_client_id as CIF_ID,wcm.client_name as
ACCT_NAME,wt.trans_date as trandate,wt.trans_no as tran_id ,wt.amount as tran_amt,'SYSTEM'
as TRAN_SUB_TYPE,wt.value_date,wt.trans_rate as FX_RATE ,wt.amount as FX_AMOUNT,CASE
WHEN TRANS_TYPE_CODE='MF-BUY' THEN 'DEBIT' WHEN TRANS_TYPE_CODE='MF-SELL'
THEN 'CREDIT' ELSE '' END PART_TRAN_TYPE ,wt.TRANS_TYPE_CODE as
TRAN_PARTICULAR,wt.trans_entry_by as ENTRY_USER_ID,iwm.user_name as
ENTRY_USER_NAME ,wt.authorised_by as VERIFY_USER_ID,iwm.user_name as
VERIFY_USER_NAME,wt.trans_entry_on as ENTRY_DATE,wt.auth_entry_on as
VERIFY_DATE ,wt.currency as TRANSACTION_CURRENCY,wt.AC_NO as foracid,SYSDATE as
DWEntrydate ,'' SourceBankName,wcb.bankacid as SourceBankAcountID,''
SourceBankAccountName,wt.net_amt as TotalAmountAmount ,'' SourceTransferdate,''
SourceTransferCurrency,'' DestinationBankName,'' DestinationBankAcountID,''
DestinationAccountName ,wt.amount as lcy_amount,wt.amount as Prinicipal,wt.trans_charges as
Charges ,CASE WHEN wt.SETTLEMENT_DATE is null THEN 'NOTSETTLED' ELSE 'SETTLED' END
Issettled from wm_transaction wt, wm_client_ac_master wcam,wm_client_master
wcm,iwz_user_master iwm,WM_CLIENT_AC_BANKAC wcb where
wt.customer_code=wcam.pms_acno and wcam.client_id=wcm.client_id and
iwm.user_id(+)=wt.trans_entry_by and wcb.pms_acno(+)=wcam.pms_acno and wt.trans_date=
'<%=TDATE%>'","x":320,"y":240,"wires":[["c7fcf84d.0dc2f8","716deea0.cc87d"]]},{"id":"2f6107
22.c86b48","type":"http in","z":"976ff8f0.4a5d38","name":"Web API
","url":"/payment","method":"post","upload":false,"swaggerDoc":"","x":200,"y":160,"wires":[["4f3
36950.0e9148"]]},{"id":"c7fcf84d.0dc2f8","type":"http
response","z":"976ff8f0.4a5d38","name":"Response","statusCode":"200","headers":{"content-
type":"application/json"},"x":460,"y":320,"wires":[]},{"id":"4f336950.0e9148","type":"change","z
":"976ff8f0.4a5d38","name":"fetch data
payload","rules":[{"t":"set","p":"TDATE","pt":"msg","to":"payload.TDATE","tot":"msg"}],"action":"
","property":"","from":"","to":"","reg":false,"x":430,"y":180,"wires":[["cef75052.1b72b","828d181
5.030da8"]]},{"id":"828d1815.030da8","type":"debug","z":"976ff8f0.4a5d38","name":"","active":t
rue,"tosidebar":true,"console":false,"tostatus":false,"complete":"payload","targetType":"msg","sta
tusVal":"","statusType":"auto","x":710,"y":180,"wires":[]}]
Import below sample flow for triggering notification at particular interval of time

[{"id":"9b3da695.393838","type":"tab","label":"NOTIFICATION","disabled":false,"info":""},{"id":"841f
68f0.1da8f8","type":"debug","z":"9b3da695.393838","name":"","active":true,"tosidebar":true,"conso
le":false,"tostatus":false,"complete":"false","statusVal":"","statusType":"auto","x":650,"y":160,"wires
":[]},{"id":"1400034a.90d26d","type":"change","z":"9b3da695.393838","name":"","rules":[{"t":"set","
p":"payload.userid","pt":"msg","to":"admin","tot":"str"},{"t":"set","p":"payload.sessionid","pt":"msg"
,"to":"wealthonline","tot":"str"},{"t":"set","p":"payload.data","pt":"msg","to":"{}","tot":"json"},{"t":"s
et","p":"payload.bcc","pt":"msg","to":"Daniel,sysadmin,user1","tot":"str"},{"t":"set","p":"rejectUnaut
horized","pt":"msg","to":"false","tot":"bool"}],"action":"","property":"","from":"","to":"","reg":false,"
x":340,"y":160,"wires":[["841f68f0.1da8f8","bf07609c.b04b"]]},{"id":"667a05ed.63d27c","type":"deb
ug","z":"9b3da695.393838","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,
"complete":"false","statusVal":"","statusType":"auto","x":590,"y":220,"wires":[]},{"id":"6e7c5038.9e6
32","type":"http
request","z":"9b3da695.393838","name":"","method":"POST","ret":"txt","paytoqs":"ignore","url":"ht
tps://3.7.239.74/ncenter/user/msg/notify/create","tls":"","persist":false,"proxy":"","authType":"","x"
:530,"y":420,"wires":[["9f4ce12e.f614e"]]},{"id":"9f4ce12e.f614e","type":"debug","z":"9b3da695.393
838","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"false","sta
tusVal":"","statusType":"auto","x":650,"y":300,"wires":[]},{"id":"bf07609c.b04b","type":"function","z"
:"9b3da695.393838","name":"","func":"msg.payload.data.msg='Hi user
\"'+msg.payload.client_id+'\"';\nmsg.payload.client_id;\nreturn
msg;","outputs":1,"noerr":0,"initialize":"","finalize":"","x":380,"y":260,"wires":[["667a05ed.63d27c","
6e7c5038.9e632"]]},{"id":"b85232ab.69652","type":"debug","z":"9b3da695.393838","name":"","activ
e":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","status
Val":"","statusType":"auto","x":610,"y":260,"wires":[]},{"id":"ac1eafb4.b1f92","type":"debug","z":"9b
3da695.393838","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":
"true","targetType":"full","statusVal":"","statusType":"auto","x":670,"y":340,"wires":[]},{"id":"d97085
33.d0c298","type":"inject","z":"9b3da695.393838","name":"","props":[{"p":"payload"},{"p":"payload.
client_id","v":"326","vt":"str"}],"repeat":"60","crontab":"","once":false,"onceDelay":0.1,"topic":"","p
ayload":"{}","payloadType":"json","x":140,"y":160,"wires":[["1400034a.90d26d"]]}]

Below link can be referred to go through the flow videos created by Product team.

https://drive.google.com/file/d/1Pf-
60qMWPF180cr8nLUDPWJYY9fiJAzz/view?usp=sharing

You might also like