Message Scripts
Message Handlers allow you to write a script that will run in the scope they are located in, but they can be invoked by making a call from other projects or even other Gateways. They can be called using three different scripting functions: system.util.sendMessage, system.util.sendRequest, and system.util.sendRequestAsync.

Under the list of handlers, three small buttons allow you to add, remove and manage your handlers.
Add Message Handler - Will add a message handler.
Remove Message Handler - Will delete the highlighted message handler.
Modify Message Handler - Will modify the settings for the highlighted message handler.
Gateway Message Handler Settings
When adding or modifying a message handler, a Message Handler settings window will popup.

The following settings are available:
- Name - The name of the message handler. Each message handler must have a unique name per project.
- Threading - Determines the threading for the message handler. Contains the following options:
- Shared - The default way of running a message handler. Will execute the handler on a shared pool of threads in the order that they are invoked. If too many message handlers are called all at once and they take long periods of time to execute, there may be delays before each message handler gets to execute.
- Dedicated - The message handler will run on its own dedicated thread. This is useful when a message handler will take a long time to execute, so that it does not hinder the execution of other message handlers. Threads have a bit of overhead, so this option uses more of the Gateway's resources, but is desirable if you want the message handler to not be impeded by the execution of other message handlers.
- Security - Allows you to specify security zone and role combinations that are allow to request this message handler.
The Payload
Inside the message handler is your script. The script will have a single object available to it, the payload. The payload is a dictionary containing the objects that were passed into it. In essence, the payload is the mechanism that allows you to pass the message handler values.
The payload is simply a python dictionary, so extracting values involves specifying the key:
Code Block |
---|
language | py |
---|
title | Pseudocode - Payload Values |
---|
|
value1 = payload["MyFirstValue"] # "MyFirstValue" is the key that is associated with a value. We are taking the value associated with MyFirstValue, and assigning it to value1.
value2 = payload["MySecondValue"] # Similarly, we are taking the value associated with MySecondValue and assigning it to value2. |
Calling Message Handlers
Once you have your message handlers created, you can then call them from a script using one of three scripting functions: system.util.sendMessage, system.util.sendRequest, and system.util.sendRequestAsync. These functions allow you to call a message handler in any project, even if the project that the message handler resides on is different from the one you are calling it from. The message handler will then execute in the scope in which it was created, and will use any parameters that you pass in through the payload.
Code Block |
---|
language | py |
---|
title | Pseudocode - Calling a Message Handler |
---|
|
project="test"
messageHandler="My Message Handler"
myDict = {'MyFirstValue': "Hello", 'MySecondValue': "World"}
results=system.util.sendMessage(project, messageHandler, myDict) |