标签:SIP service app 中间件 sample bean sink message
HelloWorld项目版本库:https://gitee.com/szhengye/biz-sip-helloworld.git
三、app服务实现对sink服务的聚合和编排
在Biz-SIP中间件中,app层不仅能实现sink服务个性化处理,还能对sink服务服务聚合和服务编排。
这里的例子是通过app层的app/sample-bean-service,实现对2个sink服务(sample-sink-bean-sink、sample-bean-sink)的聚合:
app层的app/sample-bean-service服务,是bean-service类型服务,bean-service类型是基于Java接口的调用,和app-bean-service类型基于JSON接口不同。
sink层的sample-sink-bean-sink和sample-bean-sink服务,分别是sink-bean类型和bean类型服务,调用接口分别是基于JSON接口和Java接口的。
主要实现步骤如下:
1、创建Java接口:
- 在“biz-sip-client”模块下,创建“app-client”子模块;
- 在“app-client”子模块中,创建接口类:
public interface SampleBeanServiceInterface {
public String callSampleSinkBeanSink(String message);
public String callSampleBeanSink(String message);
}
2、sink层的sample-sink-bean-sink服务和sample-bean-sink服务,在前面的二个例子中已经创建,这里直接引用即可。
3、创建app层的app/sample-bean-service服务:
- 在biz-sip-app模块中,增加bean类型的服务类,该类需要继承前面创建的SampleBeanServiceInterface接口,实现callSampleSinkBeankSink()和callSampleBeanSink()方法。另外,对于sink层服务的调用,是通过IntegratorClientFactory.getSinkClient()来获得调用接口类的,其中sample-sink-bean-sink是JSON接口,采用BizMessageInterface来作为调用接口,而sample-bean-sink是基于HelloInterface实现的bean-sink服务,是采用HelloInterface来作为调用接口的:
@Service
public class SampleBeanService implements SampleBeanServiceInterface {
private BizMessageInterface sampleSinkBeankSinkInterface = IntegratorClientFactory
.getSinkClient(BizMessageInterface.class,"sample-sink-bean-sink");
private HelloInterface helloInterface = IntegratorClientFactory
.getSinkClient(HelloInterface.class,"sample-bean-sink");
@Override
public String callSampleSinkBeanSink(String message) {
JSONObject jsonObject = new JSONObject();
jsonObject.set("message",message);
BizMessage<JSONObject> bizMessage;
try {
bizMessage = sampleSinkBeankSinkInterface.call(jsonObject);
} catch (BizException e) {
e.printStackTrace();
return null;
}
return (String)bizMessage.getData().get("message");
}
@Override
public String callSampleBeanSink(String message) {
return this.helloInterface.hello(message);
}
}
- 在service.yml中把实现app/sample-bean-service服务的定义和服务类的挂接:
- bizServiceId: app/sample-bean-service
type: bean-service
className: com.sample.app.service.SampleBeanService
4、通过app层的开放平台OpenAPI接口,可以直接进行测试访问:
$ curl -H "Content-Type:application/json" -H "Biz-Service-Id:app/sample-bean-service" -X POST --data '{"methodName":"callSampleSinkBeanSink","params":["world"]}' http://localhost:8888/api|jq
{
"code": 0,
"message": "success",
"extMessage": null,
"traceId": "eff84bfb85414034aa76f9966a49c1a4",
"parentTraceId": null,
"timestamp": 1633604250385,
"data": {
"result": "sample-sink-bean-sink: Hello,world"
}
}
$ curl -H "Content-Type:application/json" -H "Biz-Service-Id:app/sample-bean-service" -X POST --data '{"methodName":"callSampleBeanSink","params":["world"]}' http://localhost:8888/api|jq
{
"code": 0,
"message": "success",
"extMessage": null,
"traceId": "69f5e8c9a9384814b8d49774f848a088",
"parentTraceId": null,
"timestamp": 1633604304089,
"data": {
"result": "sample-bean-sink: Hello,world"
}
}
Biz-SIP官方网站:http://bizsip.bizmda.com
Gitee:[https://gitee.com/szhengye/biz-sip]
标签:SIP,service,app,中间件,sample,bean,sink,message 来源: https://blog.csdn.net/shizhengye/article/details/120648594
本站声明: 1. iCode9 技术分享网(下文简称本站)提供的所有内容,仅供技术学习、探讨和分享; 2. 关于本站的所有留言、评论、转载及引用,纯属内容发起人的个人观点,与本站观点和立场无关; 3. 关于本站的所有言论和文字,纯属内容发起人的个人观点,与本站观点和立场无关; 4. 本站文章均是网友提供,不完全保证技术分享内容的完整性、准确性、时效性、风险性和版权归属;如您发现该文章侵犯了您的权益,可联系我们第一时间进行删除; 5. 本站为非盈利性的个人网站,所有内容不会用来进行牟利,也不会利用任何形式的广告来间接获益,纯粹是为了广大技术爱好者提供技术内容和技术思想的分享性交流网站。