Annotation Interface EventSubscribe


@Documented @Retention(RUNTIME) @Target(METHOD) public @interface EventSubscribe
Subscriber annotation, marks a method as an event subscriber (receives events, processes events), configurable with thread executor strategy and execution priority. It is thread-safe by default.
The subscriber must have one and only one parameter, used to receive the event source.
It is thread-safe by default, using the user thread executor.
for example
public class YourEventBusSubscriber implements EventBusSubscriber {
    // Specify the thread executor to execute the subscriber's logic
    @EventSubscribe(ExecutorSelector.userExecutor)
    public void userLogin(YourEventMessage message) {
        log.info("event - User [{}] logged in", message.getUserId());
    }
}

@Data
public class YourEventMessage {
    final long userId;
    public YourEventMessage(long userId) {
        this.userId = userId;
    }
}

Since:
21
Author:
渔民小镇
date:
2023-12-24
  • Optional Element Summary

    Optional Elements
    Modifier and Type
    Optional Element
    Description
    int
    The execution order (priority) of the subscriber.
    Executor strategy selection
  • Element Details

    • value

      Executor strategy selection
      Default:
      userExecutor
    • order

      int order
      The execution order (priority) of the subscriber. A higher value means higher execution priority.
      To ensure sequential execution, subscribers need to use the same thread executor.
      For example, it can be used with strategies like userExecutor, simpleExecutor, etc.
      These strategies determine the thread executor used via EventBusMessage.threadIndex.
      
      Returns:
      Execution order
      See Also:
      Default:
      0