Node Red
Node Red
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.
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:
URL: localhost:8000/red
Get Started
Once we access Node Red, we can see the below screen with different panels.
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:
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.
Example: On creation of client the below Event object is passed from application
to RabbitMQ.
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.
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 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.
[{"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"]]}]
[{"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