异步处理方式,如下代码
ProcStatusChangeEvent<Supplier<Boolean>> eventSendMsg = new ProcStatusChangeEvent<>( () -> { //下方为业务代码,此处为发送短信例子 this.sendMsg(assignee,noteById.getCreateId(),buffer.toString()); return true; } ); //异步处理,可以看到GlobalEvent类的异步处理方式 GlobalEvent.asyncBus().post(eventSendMsg);
会有两个实体类
//第一个 public class ProcStatusChangeEvent<T> extends BaseEvent<T, ProcStatusChangeDealer<T>> { public ProcStatusChangeEvent(T data){ super(data); } } //第二个 @Slf4j public class ProcStatusChangeDealer<T> extends BaseDealer<T> { @Override public void accept(T t) { Supplier<Boolean> action = (Supplier<Boolean>)t; boolean actSuccess = action.get(); log.debug("event_dealer_ProcStatusChange 事件响应:"+(actSuccess?"成功":"失败")); } }
同时会封装一个实体类
// // Source code recreated from a .class file by IntelliJ IDEA // (powered by FernFlower decompiler) // package com.ll.igo.tools.event.entity; import java.util.Map; import java.util.function.Consumer; public class BaseDealer<T> implements Consumer<T> { protected Map<String, Object> paraMap = null; protected String type = null; public BaseDealer() { } public BaseDealer(Map<String, Object> paraMap) { this.paraMap = paraMap; } public void setParaMap(Map<String, Object> paraMap) { this.paraMap = paraMap; } public Map<String, Object> getParaMap() { return this.paraMap; } public void setType(String type) { this.type = type; } public String getType() { return this.type; } public void accept(T t) { } }
标签:异步,Map,处理,void,paraMap,type,public From: https://www.cnblogs.com/YHSDDJM/p/17844715.html