diff --git a/Milkomeda/pom.xml b/Milkomeda/pom.xml index 50dc9471..d26a0637 100755 --- a/Milkomeda/pom.xml +++ b/Milkomeda/pom.xml @@ -11,7 +11,7 @@ 1.8 - 3.11.3-SNAPSHOT + 3.11.4-SNAPSHOT 2.2.4 Hoxton.RELEASE 2.1.1 @@ -67,7 +67,7 @@ sonatype-oss-release - 3.11.3 + 3.11.4 diff --git a/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/halo/EnableHalo.java b/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/halo/EnableHalo.java index 0c25ae58..06cd25fe 100644 --- a/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/halo/EnableHalo.java +++ b/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/halo/EnableHalo.java @@ -1,6 +1,5 @@ package com.github.yizzuide.milkomeda.halo; -import com.github.yizzuide.milkomeda.pulsar.EnablePulsar; import org.springframework.context.annotation.Import; import java.lang.annotation.*; @@ -10,14 +9,13 @@ * * @author yizzuide * @since 2.5.0 - * @version 2.7.5 + * @version 3.11.4 * Create at 2020/01/30 18:42 */ @Target({ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited -@EnablePulsar @Import(HaloConfig.class) public @interface EnableHalo { } diff --git a/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/halo/HaloContext.java b/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/halo/HaloContext.java index 6cdf965c..c67fc880 100644 --- a/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/halo/HaloContext.java +++ b/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/halo/HaloContext.java @@ -5,7 +5,6 @@ import org.springframework.context.ApplicationListener; import org.springframework.context.event.ContextRefreshedEvent; import org.springframework.lang.NonNull; -import org.springframework.scheduling.annotation.Async; import java.util.ArrayList; import java.util.HashMap; @@ -27,10 +26,6 @@ public class HaloContext implements ApplicationListener { * 监听类型的方法属性名 */ public static final String ATTR_TYPE = "type"; - /** - * 调用处理异步方式的方法属性名 - */ - public static final String ATTR_ASYNC = "async"; private static Map> tableNameMap = new HashMap<>(); @@ -42,11 +37,9 @@ public class HaloContext implements ApplicationListener { public void onApplicationEvent(@NonNull ContextRefreshedEvent event) { tableNameMap = AopContextHolder.getHandlerMetaData(HaloHandler.class, HaloListener.class, (annotation, handlerAnnotation, metaData) -> { HaloListener haloListener = (HaloListener) annotation; - boolean isAsyncPresentOn = metaData.getMethod().isAnnotationPresent(Async.class); // 设置其它属性方法的值 Map attrs = new HashMap<>(4); attrs.put(ATTR_TYPE, haloListener.type()); - attrs.put(ATTR_ASYNC, isAsyncPresentOn || haloListener.async()); metaData.setAttributes(attrs); String value = haloListener.value(); cacheWithType(haloListener.type() == HaloType.PRE ? preTableNameMap : postTableNameMap, value, metaData); diff --git a/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/halo/HaloInterceptor.java b/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/halo/HaloInterceptor.java index df7e9763..5d003177 100644 --- a/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/halo/HaloInterceptor.java +++ b/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/halo/HaloInterceptor.java @@ -1,6 +1,5 @@ package com.github.yizzuide.milkomeda.halo; -import com.github.yizzuide.milkomeda.pulsar.PulsarHolder; import com.github.yizzuide.milkomeda.universe.metadata.HandlerMetaData; import com.github.yizzuide.milkomeda.util.MybatisUtil; import lombok.extern.slf4j.Slf4j; @@ -35,7 +34,7 @@ * * @author yizzuide * @since 2.5.0 - * @version 3.11.1 + * @version 3.11.4 * Create at 2020/01/30 20:38 */ @Slf4j @@ -164,13 +163,7 @@ private void invokeWithTable(String tableName, String matchTableName, String sql if (CollectionUtils.isEmpty(metaDataList)) { return; } - metaDataList.forEach(handlerMetaData -> { - if ((boolean) handlerMetaData.getAttributes().get(HaloContext.ATTR_ASYNC)) { - PulsarHolder.getPulsar().post(() -> invokeHandler(tableName, handlerMetaData, sql, mappedStatement, param, result)); - } else { - invokeHandler(tableName, handlerMetaData, sql, mappedStatement, param, result); - } - }); + metaDataList.forEach(handlerMetaData -> invokeHandler(tableName, handlerMetaData, sql, mappedStatement, param, result)); } private void invokeHandler(String tableName, HandlerMetaData handlerMetaData, String sql, MappedStatement mappedStatement, Object param, Object result) { diff --git a/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/halo/HaloListener.java b/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/halo/HaloListener.java index f1cecdb4..eea06614 100644 --- a/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/halo/HaloListener.java +++ b/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/halo/HaloListener.java @@ -1,7 +1,6 @@ package com.github.yizzuide.milkomeda.halo; import org.springframework.core.annotation.AliasFor; -import org.springframework.scheduling.annotation.Async; import java.lang.annotation.*; @@ -20,7 +19,7 @@ * * @author yizzuide * @since 2.5.0 - * @version 3.11.1 + * @version 3.11.4 * Create at 2020/01/30 22:36 */ @Documented @@ -46,12 +45,4 @@ * @return 默认为后置监听 */ HaloType type() default HaloType.POST; - - /** - * 是否异步处理 - * @return 默认同步处理 - * @deprecated since 3.11.1, using {@link Async} for instead. - */ - @Deprecated - boolean async() default false; } diff --git a/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/universe/context/AopContextHolder.java b/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/universe/context/AopContextHolder.java index e7aa81bd..e3bf23c3 100644 --- a/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/universe/context/AopContextHolder.java +++ b/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/universe/context/AopContextHolder.java @@ -24,7 +24,7 @@ * * @author yizzuide * @since 1.13.4 - * @version 3.11.1 + * @version 3.11.4 * Create at 2019/10/24 21:17 */ public class AopContextHolder { @@ -83,9 +83,10 @@ public static Map> getHandlerMetaData( for (String key : beanMap.keySet()) { Object target = beanMap.get(key); // 查找AOP切面(通过Proxy.isProxyClass()判断类是否是代理的接口类,AopUtils.isAopProxy()判断对象是否被代理),可以通过AopUtils.getTargetClass()获取原Class - Method[] methods = ReflectionUtils.getAllDeclaredMethods(AopUtils.isAopProxy(target) ? - AopUtils.getTargetClass(target) : target.getClass()); - Annotation handlerAnnotation = target.getClass().getAnnotation(handlerAnnotationClazz); + Class targetClass = AopUtils.isAopProxy(target) ? + AopUtils.getTargetClass(target) : target.getClass(); + Method[] methods = ReflectionUtils.getAllDeclaredMethods(targetClass); + Annotation handlerAnnotation = targetClass.getAnnotation(handlerAnnotationClazz); for (Method method : methods) { // 获取指定方法上的注解的属性 final Annotation executeAnnotation = AnnotationUtils.findAnnotation(method, executeAnnotationClazz); diff --git a/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/wormhole/EnableWormhole.java b/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/wormhole/EnableWormhole.java index 6f2c53f7..330e9b10 100755 --- a/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/wormhole/EnableWormhole.java +++ b/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/wormhole/EnableWormhole.java @@ -1,6 +1,5 @@ package com.github.yizzuide.milkomeda.wormhole; -import com.github.yizzuide.milkomeda.pulsar.EnablePulsar; import org.springframework.context.annotation.Import; import java.lang.annotation.*; @@ -10,13 +9,13 @@ * * @author yizzuide * @since 3.3.0 + * @version 3.11.4 * Create at 2020/05/05 13:57 */ @Target({ElementType.TYPE}) @Retention(RetentionPolicy.RUNTIME) @Documented @Inherited -@EnablePulsar @Import(WormholeConfig.class) public @interface EnableWormhole { } diff --git a/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/wormhole/WormholeEventBus.java b/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/wormhole/WormholeEventBus.java index bb9aefd5..5c74ac3e 100644 --- a/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/wormhole/WormholeEventBus.java +++ b/Milkomeda/src/main/java/com/github/yizzuide/milkomeda/wormhole/WormholeEventBus.java @@ -1,6 +1,5 @@ package com.github.yizzuide.milkomeda.wormhole; -import com.github.yizzuide.milkomeda.pulsar.PulsarHolder; import com.github.yizzuide.milkomeda.universe.metadata.HandlerMetaData; import com.github.yizzuide.milkomeda.util.ReflectUtil; import lombok.Data; @@ -18,7 +17,7 @@ * * @author yizzuide * @since 3.3.0 - * @version 3.11.1 + * @version 3.11.4 * Create at 2020/05/05 14:30 */ @Slf4j @@ -60,7 +59,7 @@ public void publish(WormholeEvent event, String action, } boolean isAsync = (boolean) handler.getAttributes().get(WormholeRegistration.ATTR_ASYNC); WormholeTransactionHangType hangType = (WormholeTransactionHangType) handler.getAttributes().get(WormholeRegistration.ATTR_HANG_TYPE); - // 非事件回调执行 + // 非事务回调执行 if (hangType == WormholeTransactionHangType.NONE) { execute(isAsync, handler, event, action, callback); } else { @@ -108,19 +107,14 @@ private void execute(boolean isAsync, HandlerMetaData handler, WormholeEvent Object result = null; Exception e = null; try { - if (isAsync) { - result = PulsarHolder.getPulsar().postForResult(() -> ReflectUtil.invokeWithWrapperInject(handler.getTarget(), handler.getMethod(), - Collections.singletonList(event), WormholeEvent.class, WormholeEvent::getData, WormholeEvent::setData)); - } else { - result = ReflectUtil.invokeWithWrapperInject(handler.getTarget(), handler.getMethod(), - Collections.singletonList(event), WormholeEvent.class, WormholeEvent::getData, WormholeEvent::setData); - } + result = ReflectUtil.invokeWithWrapperInject(handler.getTarget(), handler.getMethod(), + Collections.singletonList(event), WormholeEvent.class, WormholeEvent::getData, WormholeEvent::setData); } catch (Exception ex) { e = ex; } if (callback != null) { - if (isAsync && result != null) { + if (isAsync && result instanceof Future) { try { callback.callback(event, action, ((Future) result).get(), e); } catch (Exception exception) { diff --git a/MilkomedaDemo/pom.xml b/MilkomedaDemo/pom.xml index 91a32ced..08c11c86 100644 --- a/MilkomedaDemo/pom.xml +++ b/MilkomedaDemo/pom.xml @@ -20,7 +20,7 @@ UTF-8 1.8 Hoxton.RELEASE - 3.11.3-SNAPSHOT + 3.11.4-SNAPSHOT 2.1.1 3.12.5 3.4.14 diff --git a/MilkomedaDemo/src/main/java/com/github/yizzuide/milkomeda/demo/wormhole/AuditController.java b/MilkomedaDemo/src/main/java/com/github/yizzuide/milkomeda/demo/wormhole/AuditController.java index ef516d4e..74517ce3 100644 --- a/MilkomedaDemo/src/main/java/com/github/yizzuide/milkomeda/demo/wormhole/AuditController.java +++ b/MilkomedaDemo/src/main/java/com/github/yizzuide/milkomeda/demo/wormhole/AuditController.java @@ -20,6 +20,7 @@ public class AuditController { @Resource private CreditAuditApplicationService creditAuditApplicationService; + // http://localhost:8091/audit/callback?callbackId=123&orderId=12432434&state=0 @RequestMapping("callback") public Object audit(AuditCommand auditCommand) { creditAuditApplicationService.audit(auditCommand);