com.netflix.eventbus.spi
Annotation Type Subscribe


@Retention(value=RUNTIME)
@Target(value=METHOD)
public @interface Subscribe

Consumers for EventBus must annotate their consumer methods with this annotation.
A consumer is asynchronous, however it can choose to batch events consumed at a time using a batching strategy.
A consumer can indicate if it favors synchronous event consumption, provided, it is allowed in the current environment, by setting the property SyncSubscribersGatekeeper.ALLOW_SYNC_SUBSCRIBERS to true.
A consumer is always assumed to be thread-safe.
Any method annotated with this must have one and only one argument which is the event object that it is supposed to handle.


Optional Element Summary
 int batchAge
          The threshold for the age of the batch in milliseconds since the first entry was added.
 Subscribe.BatchingStrategy batchingStrategy
          Returns the batching strategy for this subscriber.
 int batchSize
          The threshold for the size of the batch.
 java.lang.String name
          A name for this subscriber, this is only required if you want to have a dynamic configuration via SubscriberConfigProvider AND each subscriber method in the class has a different configuration.
 int queueSize
          The queue size for the consumer.
 boolean syncIfAllowed
          A backdoor in the eventbus to allow synchronous events consumption.
 

name

public abstract java.lang.String name
A name for this subscriber, this is only required if you want to have a dynamic configuration via SubscriberConfigProvider AND each subscriber method in the class has a different configuration.

Returns:
A name, unique in a single subscriber class. This name does not need to be unique amongst all subscriber classes.
Default:
"none"

batchingStrategy

public abstract Subscribe.BatchingStrategy batchingStrategy
Returns the batching strategy for this subscriber. If a subscriber chooses a batching strategy other than Subscribe.BatchingStrategy.None, the argument to the subscriber method must be an Iterable. Event batches does not support removal.

Returns:
The batching strategy for this subscriber.
Default:
com.netflix.eventbus.spi.Subscribe.BatchingStrategy.None

batchAge

public abstract int batchAge
The threshold for the age of the batch in milliseconds since the first entry was added. Only considered if the batching strategy is Subscribe.BatchingStrategy.Age or Subscribe.BatchingStrategy.SizeOrAge

Returns:
The age of the batch in milliseconds.
Default:
0

batchSize

public abstract int batchSize
The threshold for the size of the batch. Only considered if the batching strategy is Subscribe.BatchingStrategy.SizeOrAge

Returns:
The threshold for the size of the batch.
Default:
1

queueSize

public abstract int queueSize
The queue size for the consumer. In case, the consumer receives batches of events, this will be the number of batches and not individual events.

Returns:
The queue size for the consumer.
Default:
-1

syncIfAllowed

public abstract boolean syncIfAllowed
A backdoor in the eventbus to allow synchronous events consumption. This mode is controlled by the property SyncSubscribersGatekeeper.ALLOW_SYNC_SUBSCRIBERS, which when set to true, allows registration of synchronous consumers.
Setting this property to true, does NOT guarantee synchronous event consumption. It is only available when the property SyncSubscribersGatekeeper.ALLOW_SYNC_SUBSCRIBERS is set to true at the time of event publishing. If the property is set to false the events will be sent to the consumer asynchronously.

Returns:
true if this subscriber favors synchronous consumption of events. false by default.
Default:
false