public interface Module
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 Module {
@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();
}
}
ExecutionParameters,
Message,
EventEmitter| Modifier and Type | Method and Description |
|---|---|
void |
execute(ExecutionParameters parameters)
Executes this component with the given
ExecutionParameters. |
default void |
init(javax.json.JsonObject configuration)
Used to initialize a component before message processing.
|
default javax.json.JsonObject |
startup(javax.json.JsonObject configuration)
Used to initialize the component on flow start.
|
void execute(ExecutionParameters parameters)
ExecutionParameters.parameters - parameters to execute component withdefault javax.json.JsonObject startup(javax.json.JsonObject configuration)
configuration - component's configurationdefault void init(javax.json.JsonObject configuration)
configuration - component's configuration