nl.grons.sentries.examples.SentryExampleApp
Here we use the load balancer.
Here we use the load balancer.
Note that the code block will be executed in the context of the resource's sentry. Note that the code might be invoked multiple times when a NotAvailableException is caught in the load balancer.
You can also use this fact to your advantage; if inside the code block it becomes clear that another resource should be called, explicitly throw a NotAvailableException and the load balancer will invoke the next resource.
LoadBalancer is abstract and requires us to implement 'resources'.
Returns a new sentry builder with the current class as owner.
Returns a new sentry builder with the current class as owner.
Returns the default SentriesRegistry.
Returns the default SentriesRegistry. Override to use another.
Load balancer example.
In this example we'll show the load balancer support. The default load balancer requires you to implement 'resources' that returns all available resources. When this is not dynamic, simply implement 'resources' as a val (as done in this example).
Upon invoking the load balancer it randomly picks one of the given resources and tries to use it. When a NotAvailable exception is caught, the next resource is attempted.
If the resource throws any other error, the error is simply rethrown and not further attempt to invoke another resource is done.