How to Invoke a Service from Script

This is an example of a script showing how to invoke a service using the Messenger Service. See the full docs for the Messenger Service in the script documentation. From Scripting API Documentation for the Akana API Platform and Policy Manager, choose the correct version.

Note: you can set outbound identities using the Manage Outbound Activies action on the virtual service. Alternatively you can set principals within the script, but this is more complex.

// Grab the message variable for input
var msg = processContext.getVariable("message");

// Set up the new messenger service and instance instances
messenger = msgrService.getMessenger();
exchangeFactory = msgrService.createExchangeFactory();
exchange = exchangeFactory.createInOut();

// Tell the messenger service exchange which service, interface, and operation to invoke

// Tell the messenger service exchange which message variable to use as it's input

// Send the message

// Read the response and override the input msg variable with the response
msg = exchange.getOutMessage();

// Replace the message variable in the process with the result of the invoke

That's it. Nice and simple.