@Configuration public class GuavaAutoConfiguration extends Object
| Constructor and Description |
|---|
GuavaAutoConfiguration() |
| Modifier and Type | Method and Description |
|---|---|
com.google.common.eventbus.EventBus |
asyncEventBus()
注入一个guava异步消息总线
|
void |
checkConfig()
配置检查
|
@Bean @ConditionalOnMissingBean(value=com.google.common.eventbus.EventBus.class) public com.google.common.eventbus.EventBus asyncEventBus()
注入一个guava异步消息总线
使用该异步消息总线的示例如下:
@Component
public class DemoEventBus {
@Resource
private EventBus asyncEventBus;
@PostConstruct
public void init() {
asyncEventBus.register(this);
}
}
发送消息
asyncEventBus.post("需要发送的数据");
接收消息
@Subscribe
public void recieve(Object data) {
// 注意guava是根据入参的数据类型进行接收的
// 发送的数据可以被多个接收者同时接收
}
@PostConstruct public void checkConfig()
Copyright © 2021. All rights reserved.