Commit 3a6fdb37 by guojuxing

dubbo泛化回调工具

parent 98d62223
package com.gic.enterprise.utils;
import org.apache.dubbo.config.ReferenceConfig;
import org.apache.dubbo.config.RegistryConfig;
import org.apache.dubbo.config.utils.ReferenceConfigCache;
import org.apache.dubbo.rpc.service.GenericService;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import com.alibaba.fastjson.JSONObject;
/**
* 异步回调工具
* @ClassName: AsyncCallbackUtils

* @Description: 

* @author guojuxing

* @date 2019/10/31 3:41 PM

*/
public class AsyncCallbackUtils {
private static Logger logger = LogManager.getLogger(AsyncCallbackUtils.class);
/**
* 回调
* @Title: callBack

* @Description:

 * @author guojuxing
* @param obj 需要传递的参数对象
* @param interfaceUrl 接口路径 例如com.gic.open.api.service.market.PayCallbackApiService
* @param method
 方法名称 payCallbackTransfer
* @return void


 */
public static void callBack(Object obj, String interfaceUrl, String method) {
logger.info("回调:{},接口路径:{},接口方法名称:{}" ,JSONObject.toJSONString(obj), interfaceUrl, method);
RegistryConfig registry = new RegistryConfig();
registry.setAddress("zookeeper://10.105.220.75:2199");
registry.setCheck(false);
ReferenceConfig<GenericService> reference = new ReferenceConfig<>();
reference.setInterface(interfaceUrl);
reference.setRegistry(registry);
reference.setGeneric(true);
ReferenceConfigCache cache = ReferenceConfigCache.getCache();
GenericService genericService = cache.get(reference);
// 注意! Cache会持有ReferenceConfig,不要在外部再调用ReferenceConfig的destroy方法,导致Cache内的ReferenceConfig失效!
genericService.$invoke(method, new String[]{String.class.getName()}, new String[]{JSONObject.toJSONString(obj)});
}
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment