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 会扫描到这个类,会被自动注册为 springbean,因此可以直接使用 @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

CurateClick favicon

lifepathcalculator.app

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

CurateClick favicon

freeadhd.com

ADHD Test - a free, no-sign-up adult ADHD self-screening tool with instant results.

CurateClick favicon

pixmira.ai

Free AI photo editor and image generator for fast visual creation.

CurateClick favicon

pslratings.com

Free PSL Rating gives an instant AI PSL score with tier and four category breakdowns, no signup.

CurateClick favicon

gothic1remake.com

Gothic 1 Remake Guide — Release, Walkthroughs & Quests

CurateClick favicon

viralitypredictor.net

Predict video virality before you publish.

CurateClick favicon

motionvideoai.com

Powerful Motion Control AI Video Generator

PlusGO 是面向中国大陆用户的 ChatGPT Plus 代充值服务平台。使用官方 CDKey,支持支付宝和微信扫码支付,平均 2 分钟完成 Plus 开通,自 2025 年起已为超过 10,000 名用户完成充值。