💎一站式轻松地调用各大LLM模型接口,支持GPT4、智谱、星火、月之暗面及文生图 广告
## 一、概述 对于一个新的对外服务业务需求,如何快速开发并对外提供服务能力呢?这个章节,简单介绍一下,如何利用wbase uniframework平台的微服务平台架构,编写代码,来实现对外服务的提供; ## 二、代码实现示范 我们定义的微服务,包含上述两种类型,一种是同步执行的,一种是异步执行的,具体差异,参考上述章节,这里举例说明其实现方法; 同步执行微服务编写示范代码: ``` @UniOauthApi(name = "同步api测试实例", url = "/test/syn", responseMode = ResponseMode.IMMEDIATELY_SYN, desc = "同步api测试") public class SynRealTimeTest extends UniOauthApiAction { @Override public Feedback response(Map<String, String> requestParamaters, OauthClient oauthClient, OauthApi oauthApi, OauthDao singleTransactionDao) { Feedback feedback = Feedback.instance().setBusinessMessage("即可执行查询并返回结果").setBusinessSuccess(true); return feedback; } @Override public UniOauthParameterRequirement parameterRequirement() { return null; } @Override public AsynJobResult doInJobWhenIamAsyn(OauthApiRequest request, OauthApi oauthapi, SingleTransactionJobManager singleTransactionManager) { return null; } } ``` 异步执行微服务编写示范代码: ``` @UniOauthApi(name = "异步api测试", url = "/test/asy", responseMode = ResponseMode.LATER_ASYN, desc = "异步api测试,返回完毕之后,再去真正执行业务") public class AsynTestApi extends UniOauthApiAction { @Override public Feedback response(Map<String, String> requestParamaters, OauthClient oauthClient, OauthApi oauthApi, OauthDao singleTransactionDao) { Feedback feedback = Feedback.instance().setBusinessMessage("立刻返回结果,后续再去执行").setBusinessSuccess(true); feedback.setData(""); return feedback; } @Override public UniOauthParameterRequirement parameterRequirement() { return null; } @Override public AsynJobResult doInJobWhenIamAsyn(OauthApiRequest request, OauthApi oauthapi, SingleTransactionJobManager singleTransactionManager) { AsynJobResult result = AsynJobResult.instance().setSuccess(true).setExecutionData("ok"); return result; } } ``` ## 三、发布 代码编写完成后,按照普通的打包服务,微服务平台启动的时候,会自动搜索已经定义的微服务,通过上一章节的业务操作,自动发布。可以看到,整个流程非常简单。