NodeJS component can be used to launch NodeJS scripts. This component provides two modes of operations, server and client, facilitating to run scripts written in both these modes. Communication between java and NodeJS is done using Sockets. A socket server is hosted in the NodeJS part which communicates with the socket client in java.
Configuration
Component Configuration panel in the CPS (Configuration Property Sheet) allows customization in the component.
Figure 1: NodeJS Configuration properties
Attributes
Error handling configuration
Please refer to the Error Handling section in the Common Configurations page for documentation.
Is Script from File?
Select this property if the script is provided by the file path.
Script Path
Provide the path of the file which contains the Node JS Script.
Script
Available when 'Is Script from File? property is disabled. Provide the contents of the Node JS Script. Template for NodeJS script in Server and Client mode has been preloaded.
To easily download npm-modules have node JS installed with NPM. This link provides instructions to install it.
https://nodejs.org/en/download/package-manager/
Operation Mode
- Server : This mode can be used to host a nodeJS server. Only the output port is available in this configuration to receive responses generated by the server.
- Client: This mode can be used to host a nodeJS client. Both input and output ports are available in this configuration to make a request and receive a response.
Socket IP
The IP address of the socket server given in Node JS script.
Socket Port
The port of the socket server given in Node JS script.
Script Startup Time(milliseconds)
This option is available only in server mode. The script needs some time to start the socket server to which a socket connection should be made, so a timeout is needed. However, this timeout should have a threshold. Thus the component waits for a maximum of this time for the Socket Server to start before stopping.
Socket Response Time-Out(milliseconds)
This option is available only in client mode. When a request is sent to the socket a response should be received within this time. Timeout value '0' means to wait indefinitely.
Expert Properties
Enable the View Expert Properties option to configure these properties.
Figure 2: NodeJS Configuration advanced properties
Pre Processing XSL Configuration
Pre Processing XSL configuration can be used to transform the request message before processing it. Click the ellipses button against the property to configure the properties.
Refer to the Pre/Post Processing XSL Configuration section under the Common Configurations page for details regarding Pre Processing XSL configuration and Post Processing XSL configuration (below).
Post Processing XSL Configuration
Post Processing XSL configuration can be used to transform the response message before sending it to the output port.
Process Message Based on Property
The property helps components to skip certain messages from processing.
Refer to the Process Message Based On a Property section under the Common Configurations page.
Threadpool Configuration
This property is used when there is a need to process messages in parallel within the component, still maintaining the sequence from the external perspective.
Refer to the Threadpool Configuration section under the Common Configurations page.
Functional Demonstration
Scenario
Configure two Node JS components, one as Server and another as Client each in two separate EPs.
The flow and scripts for client and server mode are provided below. An HTTP POST request is made to the server from the client via input port. The socket connection in the client is used to send a request and the response is obtained from the server. The output from the server is given out in the output port. This response is propagated to the client which is sent out through its output port.
Figure 3: Server mode event process
Figure 4: Client mode event process