Spring Boot集成EventBus(Guava方式)
依赖
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
配置
@Configuration
public class AsyncEventBusConfig {
@Bean
@Scope("singleton")
public AsyncEventBus asyncEventBus() {
final ThreadPoolTaskExecutor executor = executor();
return new AsyncEventBus("Merchant-AsyncEventBus", executor);
}
@Bean
public ThreadPoolTaskExecutor executor() {
ThreadPoolTaskExecutor executor = new ThreadPoolTaskExecutor();
executor.setCorePoolSize(2);
executor.setMaxPoolSize(10);
executor.setQueueCapacity(20);
return executor;
}
}
生产者
@Autowired
private AsyncEventBus asyncEventBus;
public void myFunc(MyEvent event) {
...
asyncEventBus.post(MyEvent.builder().id(1).name("Joe.Ye").build());
}
消费者
@Autowired
private AsyncEventBus asyncEventBus;
@Subscribe
public void listenMyEvent(MyEvent event) {
}
@PostConstruct
public void init() {
asyncEventBus.register(this);
}
版权声明:
作者:Joe.Ye
链接:https://www.appblog.cn/index.php/2023/03/27/spring-boot-integrate-eventbus-guava/
来源:APP全栈技术分享
文章版权归作者所有,未经允许请勿转载。
THE END
0
二维码
打赏
海报
Spring Boot集成EventBus(Guava方式)
依赖
<dependency>
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>
配置……
文章目录
关闭
共有 0 条评论