Interface Function
A component is executed with a ExecutionParameters
which provides
the component with a Message
, configuration and a snapshot.
The given Message
represents component's input. Besides other things
it contains a payload to be consumed by a component.
A configuration is an instance JsonObject
containing
required information, such as API key or username/password combination, that
components needs to collect from user to function properly.
A snapshot is an instance of JsonObject
that represents
component's state. For example, a Twitter timeline component might store the id
of the last retrieved tweet for the next execution in order to ask Twitter for
tweets whose ids are greater than the one in the snapshot.
EventEmitter
.
The following example demonstrates a simple component which echos the incoming message.
public class EchoComponent implements Function {
@Override
public void execute(ExecutionParameters parameters) {
final JsonObject snapshot = Json.createObjectBuilder()
.add("echo", parameters.getSnapshot())
.build();
parameters.getEventEmitter()
.emitSnapshot(snapshot)
.emitData(echoMessage(parameters));
}
private Message echoMessage(ExecutionParameters parameters) {
final Message msg = parameters.getMessage();
final JsonObject body = Json.createObjectBuilder()
.add("echo", msg.getBody())
.add("config", parameters.getConfiguration())
.build();
return new Message.Builder()
.body(body)
.attachments(msg.getAttachments())
.build();
}
}
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionvoid
execute
(ExecutionParameters parameters) Executes this component with the givenExecutionParameters
.default void
init
(InitParameters parameters) Used to initialize a component before message processing.default void
shutdown
(ShutdownParameters parameters) Used to shutdown a component gracefully before its process is killed.default jakarta.json.JsonObject
startup
(StartupParameters parameters) Used to initialize the component on flow start.
-
Method Details
-
execute
Executes this component with the givenExecutionParameters
.- Parameters:
parameters
- parameters to execute component with
-
startup
Used to initialize the component on flow start. For example, a webhook trigger can subscribe a webhook url to receive events from a target API inside this method. The subscription data, such as ID, can be returned from this method as JSON object for persistence in the platform. The persisted JSON will be passed toshutdown(ShutdownParameters)
method where the subscription can be canceled on flow stop.- Parameters:
parameters
- parameters to startup the module with- Returns:
- state to be persisted
- Since:
- 2.0.0
-
init
Used to initialize a component before message processing. For polling flows this method is called once per scheduled execution. For real-time flows this method is called once on first execution.- Parameters:
parameters
- to init the module with- Since:
- 2.0.0
-
shutdown
Used to shutdown a component gracefully before its process is killed. This method is invoked when the flow the component is used in is inactivated. It is considered as the counterpart ofstartup(StartupParameters)
. For example, this method may be used to cancel a webhook subscription on flow stop.- Parameters:
parameters
- parameters to shutdown the module with- Since:
- 2.2.0
-