Notice: 函数 WP_Scripts::localize 的调用方法不正确$l10n 参数必须是一个数组。若要将任意数据传递给脚本,请改用 wp_add_inline_script() 函数。 请查阅调试 WordPress来获取更多信息。 (这个消息是在 5.7.0 版本添加的。) in /data/www/appblog/wp-includes/functions.php on line 6131

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);
}
上一篇 Spring Cloud Gray 微服务灰度中间件
下一篇 Spring Cloud Gray 部署