Dynamic StartStop - atleon/atleon GitHub Wiki
AloStream
implementations can be configured to dynamically start and stop using the StarterStopperConfig interface. The process for this is:
- Update your
AloStreamConfig
to implementStarterStopperConfig
- Implement the config method to return an implementation of
StarterStopper
- The implementation of
StarterStopper
will be used to build a stream (Flux
) of boolean signals indicating when the stream should start (true
) and stop (false
)
Dynamic start-stop can be useful for implementing message prioritization, circuit breaking, etc. For example, if a stream detects that some known downstream process is degraded, it can shut itself off in order to avoid exacerbating whatever that degradation is, until it is alleviated. As another example, if it is detected that there is some downstream back-up of high(er) priority messages, a stream can shut off its processing of lower priority message processing.
The following example shows how to add Kafka lag-based dynamic start-stop behavior to an AloStream
:
public class MyStreamConfig implements AloStreamConfig, StarterStopperConfig {
@Override
public StarterStopper buildStarterStopper() {
return KafkaLagThresholdStarterStopper.create(configSource, "group-id")
.withThresholds(10000, 1000); // Stop when lag is above 10000, start when at-or-below 1000
}
}