Class DefaultTracker
- All Implemented Interfaces:
Registration
,Runnable
A tracker is always running in a single thread. To balance the processing load over multiple threads create multiple trackers with the same name but different tracker id.
Trackers with different names will receive the same messages. Trackers with the same name will not. (Flux Capacitor will load balance between trackers with the same name).
Tracking stops if the provided message consumer throws an exception while handling messages (i.e. the tracker will need to be manually restarted in that case). However, if the tracker encounters an exception while fetching messages it will retry fetching indefinitely until this succeeds.
Trackers can choose a desired maximum batch size for consuming. By default this batch size will be the same as the batch size the tracker uses to fetch messages from Flux Capacitor. Each time the consumer has finished consuming a batch the tracker will update its position with Flux Capacitor.
Trackers can be configured to use batch interceptors. A batch interceptor manages the invocation of the message consumer. It is therefore typically used to manage a database transaction around the invocation of the consumer. Note that if the interceptor gives rise to an exception the tracker will be stopped.
-
Method Summary
Modifier and TypeMethodDescriptionvoid
cancel()
Cancels the resource or subscription associated with this registration.protected void
protected MessageBatch
protected void
protected void
process
(MessageBatch batch) void
run()
static Registration
start
(Consumer<List<SerializedMessage>> consumer, MessageType messageType, ConsumerConfiguration config, Client client) Starts one or more trackers.static Registration
start
(Consumer<List<SerializedMessage>> consumer, MessageType messageType, ConsumerConfiguration config, FluxCapacitor fluxCapacitor) Starts one or more trackers.static Registration
start
(Consumer<List<SerializedMessage>> consumer, MessageType messageType, String topic, ConsumerConfiguration config, Client client) Starts one or more trackers.static Registration
start
(Consumer<List<SerializedMessage>> consumer, MessageType messageType, String topic, ConsumerConfiguration config, FluxCapacitor fluxCapacitor) Starts one or more trackers.static Registration
start
(Consumer<List<SerializedMessage>> consumer, ConsumerConfiguration config, TrackingClient trackingClient) Starts one or more trackers that consume messages using the provided trackingClient and process them using the provided consumer.Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface io.fluxcapacitor.common.Registration
merge
-
Method Details
-
start
public static Registration start(Consumer<List<SerializedMessage>> consumer, MessageType messageType, ConsumerConfiguration config, FluxCapacitor fluxCapacitor) Starts one or more trackers. Messages will be passed to the given consumer. Once the consumer is done the position of the tracker is automatically updated.FluxCapacitorInterceptor
will be added to the list of batch interceptors in the given configuration. This ensures that a thread localFluxCapacitor
instance will always be available during tracking.Each tracker started is using a single thread. To track in parallel configure the number of trackers using
ConsumerConfiguration
. -
start
public static Registration start(Consumer<List<SerializedMessage>> consumer, MessageType messageType, String topic, ConsumerConfiguration config, FluxCapacitor fluxCapacitor) Starts one or more trackers. Messages will be passed to the given consumer. Once the consumer is done the position of the tracker is automatically updated.FluxCapacitorInterceptor
will be added to the list of batch interceptors in the given configuration. This ensures that a thread localFluxCapacitor
instance will always be available during tracking.Each tracker started is using a single thread. To track in parallel configure the number of trackers using
ConsumerConfiguration
. -
start
public static Registration start(Consumer<List<SerializedMessage>> consumer, MessageType messageType, ConsumerConfiguration config, Client client) Starts one or more trackers. Messages will be passed to the given consumer. Once the consumer is done the position of the tracker is automatically updated.Each tracker started is using a single thread. To track in parallel configure the number of trackers using
ConsumerConfiguration
. -
start
public static Registration start(Consumer<List<SerializedMessage>> consumer, MessageType messageType, @Nullable String topic, ConsumerConfiguration config, Client client) Starts one or more trackers. Messages will be passed to the given consumer. Once the consumer is done the position of the tracker is automatically updated.Each tracker started is using a single thread. To track in parallel configure the number of trackers using
ConsumerConfiguration
. -
start
public static Registration start(Consumer<List<SerializedMessage>> consumer, ConsumerConfiguration config, TrackingClient trackingClient) Starts one or more trackers that consume messages using the provided trackingClient and process them using the provided consumer. Each tracker operates in its own thread, and their positions are managed automatically upon processing the messages. -
run
public void run() -
pauseFetchIfNeeded
protected void pauseFetchIfNeeded() -
fetch
-
process
-
cancelAndDisconnect
protected void cancelAndDisconnect() -
cancel
public void cancel()Description copied from interface:Registration
Cancels the resource or subscription associated with this registration.Calling this method should be idempotent and safe to invoke multiple times.
- Specified by:
cancel
in interfaceRegistration
-