Snaplex configuration for Snaps
- Configuring HTTP proxies for Script Snaps
- Managing outbound WebSocket connections for child pipelines
- Optimizing the node's performance for handling various Snap execution scenarios
Snaplex configuration for Snaps includes the following two configurations:
- Configuring the Script Snap to Use an HTTP Proxy
- Snaplex Outbound Connections for Child Pipelines
Configuring the Script Snap to use an HTTP Proxy
Script Snaps enable you to execute custom scripts within your SnapLogic pipelines. When these scripts need to access external services, configuring an HTTP proxy ensures secure and proper routing of these connections.
- Setting Up the HTTP Proxy: Script Snaps and other HTTP-compatible Snap Packs can use an HTTP proxy configured in the Snaplex configuration tab within SnapLogic Manager. For Script Snaps, you need to configure the proxy directly using the
curl --proxy
argument or by setting thehttp_proxy
and/orhttps_proxy
environment variables. - Configuring Environment Variables: Declare the environment variables in the
/etc/sysconfig/jcc
file for Linux or in the appropriate configuration file for Windows. If the directory or file does not exist, create them using the following command:sudo mkdir -p /etc/sysconfig; sudo sh -c "echo 'export http_proxy=username:password@proxy-ip-address:port' >> /etc/sysconfig/jcc"
- Restarting the Snaplex: After configuring the proxy, restart the Snaplex application to apply the changes:
/opt/snaplogic/bin/jcc.sh restart
For example, the following Script Snap uses the subprocess
library to execute curl
and adds the response body to the output document:
# Import the interface required by the Script snap.
from com.snaplogic.scripting.language import ScriptHook
import subprocess
class TransformScript(ScriptHook):
def __init__(self, input, output, error, log):
self.input = input
self.output = output
self.error = error
self.log = log
# The "execute()" method is called once when the pipeline is started
# and allowed to process its inputs or just send data to its outputs.
def execute(self):
self.log.info("Executing Transform script")
while self.input.hasNext():
try:
# Read the next input document, store it in a new dictionary, and write this as an output document.
inDoc = self.input.next()
proc = subprocess.Popen(['curl','https://www.snaplogic.com'], stdout=subprocess.PIPE)
(out, err) = proc.communicate()
outDoc = {
'original' : out
}
self.output.write(inDoc, outDoc)
except Exception as e:
errDoc = {
'error' : str(e)
}
self.log.error("Error in python script")
self.error.write(errDoc)
self.log.info("Script executed")
# The "cleanup()" method is called after the snap has exited the execute() method
def cleanup(self):
self.log.info("Cleaning up")
# The Script Snap will look for a ScriptHook object in the "hook" variable. The snap will then call the hook's "execute" method.
hook = TransformScript(input, output, error, log)
Snaplex outbound connections for child pipelines
Snaplex nodes establish outbound WebSocket connections to the SnapLogic cloud to process incoming requests. Proper management of these connections is crucial for ensuring that your pipelines run smoothly, especially when dealing with nested or concurrent pipelines.
- Managing Outbound Connections: By default, Snaplex creates 20 outbound WebSocket connections. This can be increased to a maximum of 60 if higher concurrency is required. However, setting this too high can cause network overhead. It is recommended to add more Snaplex nodes if higher concurrency is consistently needed.
- Updating Connection Limits: To increase the connection limit, modify the
jcc.websocket_connection_count
property in theetc/global properties
file:jcc.websocket_connection_count = 30
. Apply this change in the Snaplex Manager by updating the node properties.