Reputation: 28289
I'm tring to implement a custom processor which read message from RocketMQ.
Basiclly I need
@onScheduled and @onTrigger, which one should I use and how to achieve it?
Upvotes: 1
Views: 2165
Reputation: 14194
You can create the MessageConsumer
in the method with @OnScheduled
, store it as a field in the processor class, and then invoke it inside the #onTrigger()
method.
The @OnScheduled
method will be called whenever the processor is scheduled to be run (i.e. a user clicks/invokes the API to "start" the processor). The #onTrigger()
method runs every time the processor actually performs some unit of work (i.e. when one or more flowfiles are pulled from the incoming queue and operated on, or when the timer fires if this is the first processor in a flow segment). The Apache NiFi Developer Guide has more information on this as well as a common scenarios and patterns section which may be helpful.
I would also look at the source code for ConsumeJMS and AbstractJMSProcessor as it is a similar pattern.
Upvotes: 3