Skip to main content

CurateClick

CurateClick favicon

ooooo-protocol

一个Java开源库,提供基于接口的声明式方式来对接各种第三方协议(如Dubbo、HTTP),支持动态刷新配置,简化了第三方接口的适配工作。

Check out ooooo-protocol on CurateClick

• Copy the embed code to showcase this product on your website

• Share on X to spread the word about this amazing tool

开源地址 https://github.com/ooooo-youwillsee/ooooo-protocol## ooooo-protocol 提供基于接口的声明式方式来对接第三方接口,支持动态刷新。### 使用示例配置如下:yamlooooo: protocol: # 配置的协议 id demo: # 扫描的包 base-packages: - com.ooooo.protocol.core.service.** # 协议类 (需要自己编写) protocol-class: com.ooooo.protocol.core.request.DemoProtocol # 自定义包装类(需要自己编写),可以用于填充默认参数,校验参数,解析结果 protocol-wrapper-class: - com.ooooo.protocol.core.request.AProtocolWrapper - com.ooooo.protocol.core.request.BProtocolWrapper # 协议的配置 config: a: b实现上述的 DemoProtocol 类:(这里只是简单实现, 复杂可以看 DubboProtocol, HttpProtocol)java@Getterpublic class DemoProtocol implements Protocol { private ProtocolProperties properties; public DemoProtocol(ProtocolProperties properties) { this.properties = properties; } @Override public Object execute(Invocation invocation) throws Throwable { String url = APIServiceContext.getAPIMethodConfig().getUrl(); Object[] args = invocation.getArguments(); String data = null; switch (url) { case HelloService.INVOKE_NORMAL_METHOD: data = (String) args[0]; break; case HelloService.INVOKE_DEFAULT_VALUE: data = ((HelloService.DefaultValueHolder) args[0]).getName(); break; case HelloService.INVOKER_REFRESH_VALUE: data = (String) properties.getConfig().get("a"); break; } return data; }}声明自己的 HelloService 接口:(配置 base-packages 会扫描到这个类,会被自动注册为 spring 的 bean,因此可以直接使用 @Autowired)java@APIServicepublic interface HelloService { String INVOKE_NORMAL_METHOD = "HelloService#invokeNormalMethod"; String INVOKE_DEFAULT_VALUE = "HelloService#invokeDefaultValue"; String INVOKER_REFRESH_VALUE = "HelloService#invokerRefreshValue"; @APIMapping(INVOKE_NORMAL_METHOD) String invokeNormalMethod(String name); @APIMapping(INVOKE_DEFAULT_VALUE) String invokeDefaultValue(DefaultValueHolder holder); @APIMapping(INVOKER_REFRESH_VALUE) String invokerRefreshValue(); default String invokeDefaultMethod(String name) { return name + "123"; } default String invokeDefaultMethodForNormalMethod(String name) { return invokeNormalMethod(name); } @Data class DefaultValueHolder { private String name; }}在代码中使用:(这里只是一部分测试类,详细见 DemoProtocolTest)@SpringBootTest(classes = CoreProtocolTestConfiguration.class)public class DemoProtocolTest { @Autowired private ApplicationContext context; @Autowired private AbstractEnvironment environment; @Autowired private APIServiceProtocolPropertiesRefresher refresher; @Test public void testApiService() { HelloService bean = context.getBean(HelloService.class); assertEquals("123", bean.invokeNormalMethod("123")); IAPIService service = (IAPIService) bean; APIServiceConfig apiServiceConfig = service.getAPIServiceConfig(); assertEquals("demo", apiServiceConfig.getProtocolId()); }}### 模块说明1. protocol-core 实现了对接第三方接口的核心逻辑, 2. protocol-dubbo 实现了对 dubbo 接口的适配3. protocol-http 实现了对 http 接口的适配

Latest Weekly Picks

Independent audiophile gear reviews with a transparent scoring system, plus 16 free in-browser audio tools.

CurateClick favicon

getfacereport.com

Private face analysis with personalized style guidance and hairstyle previews.

CurateClick favicon

lovableapp.org

Discover beautiful apps built with vibe coding

CurateClick favicon

antiquescanner.org

Identify antiques, vintage items and collectibles from photos, with estimated market value.

CurateClick favicon

imagelayered.com

AI-powered image decomposition tool that transforms flat images into editable layers.

CurateClick favicon

kaigpt.ai

gpt代充:如何快速申请免手续费的充值服务?

CurateClick favicon

magiclayers.net

Magic Layers – Official Website, What It Is & How to Use

CurateClick favicon

lifepathcalculator.app

Life Path Calculator - free deterministic numerology: your number, strengths, challenges, and shareable cards.