spring 集成Reactor 异步框架 (java config)

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u014087707/article/details/79284920

spring 集成Reactor 异步框架

  • 加入依赖
  <dependency>
      <groupId>org.projectreactor</groupId>
      <artifactId>reactor-core</artifactId>
      <version>1.0.0.RELEASE</version>
  </dependency>
  <dependency>
      <groupId>org.projectreactor</groupId>
      <artifactId>reactor-groovy</artifactId>
      <version>1.0.0.RELEASE</version>
  </dependency>
  <dependency>
      <groupId>org.projectreactor</groupId>
      <artifactId>reactor-spring</artifactId>
      <version>1.0.0.RELEASE</version>
  </dependency>
  • 配置reactor
@Configuration
@EnableReactor
@ComponentScan(value = {"com.portal.reactor"})
public class ReactorConfig {

    /**
     * 〈注册审计日志 Reactor〉
     */
    @Bean(name = "sysLog")
    public Reactor sysLogReactor(Environment env) {
        return Reactors.reactor().env(env).get();

    }
}
  • 处理者
//消费者
@Component
public class LogOperationHandler {

    @Selector(value = "sysLog", reactor = "@sysLog")
    public void handleSysLog(Event<Object> evt) {
        try {
            Thread.sleep(2000);

        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        System.out.println(evt);
    }

}
  • 测试
    //注入这个东西
    @Autowired
    @Qualifier("sysLog")
    private Reactor sysLog;

    /**
     * 测试异步消费
     *
     * @return DataResponseVo
     */
    @RequestMapping(value = "/push", method = RequestMethod.GET)
    public DataResponseVo<String> push() {
        //seriesDataEventQueueHelper.publishEvent(new SeriesData("test"));
        sysLog.notify("sysLog", Event.wrap("test"));
        return new DataResponseVo<String>(200, "ok");
    }
展开阅读全文

没有更多推荐了,返回首页