Biz-SIP业务中台案例实战(5)——通过接口类方法调用App服务和Sink服务

Biz-SIP金融级业务中台(http://bizsip.bizmda.com))是一套基于领域驱动设计(DDD),用于快速构建金融级云原生架构的服务整合中间件,包含了在金融场景里锤炼出来的最佳实践。

Biz-SIP业务中台在交易处理时,是按照Source模块->App服务->Sink服务的调用框架,Source模块调用App服务和App服务调用Sink服务的调用方式,除了采用平台内部标准的JSONObject对象作为出入参调用外,还支持通过纯粹的接口类方法来进行调用。
本节案例中Source模块->App服务->Sink服务调用链的实现,就是围绕接口类方法来实现的:
在这里插入图片描述

其中,Source模块是采用HelloSourceController实现,App服务(HelloAppService类)和Sink服务(HelloBeanSinkService类),都是实现了HelloInterface接口的Spring Bean:

public interface HelloInterface {
    String hello(String message);
}

具体代码和配置可以查看Biz-SIP源代码中的Sample相关测试案例(https://gitee.com/szhengye/biz-sip

一、Sink层Sink服务的开发和配置

首先,我们需要编写一个Sink服务类(HelloBeanSinkService.java):

@Slf4j
@Service
public class HelloBeanSinkService extends AbstractSinkService implements HelloInterface {
    @Override
    public String hello(String message) {
        log.info("hello({})",message);
        return "hello,"+message;
    }
}

HelloBeanSinkService类继承了AbstractSinkService类(Sink服务类一般都要继承AbstractSinkService类),实现了HelloInterface接口中的hello()方法,这个方法是在传入的message参数前,加上“hello,”串。
然后,在在Biz-SIP配置目录的sink.yml中,配置对应的Sink服务:

- id: hello-bean-sink
  type: rest
  processor: bean
  url: http://bizsip-sample-sink/hello-bean-sink
  class-name: com.bizmda.bizsip.sample.sink.service.HelloBeanSinkService

可以看到hello-bean-sink这个Sink服务,关联了上面编写的HelloBeanSinkService类,是通过接口类方法来实现的Sink服务,配置中processor应设置为“bean”。
最后,还需要在SampleSinkApplication的应用配置文件application-local.yml中,在bizsip.sink-id配置项中,增加hello-sink以便启动Sink服务:

bizsip:
  config-path: /var/bizsip/config
  sink-id: hello-sink,echo-sink,hello-bean-sink

二、App层App服务的开发和配置

首先,我们需要编写一个App服务类(HelloAppService.java):

@Service
public class HelloAppService implements HelloInterface {
    private HelloInterface helloInterface =  AppClientFactory.getSinkClient(HelloInterface.class,"hello-bean-sink");;

    @Override
    public String hello(String message) {
        return this.helloInterface.hello(message);
    }
}

HelloAppService类继承了HelloInterface接口,实现了hello()方法。
HelloAppService类中还申请了一个调用“hello-bean-sink”Sink服务的调用接口,在hello()方法中,通过这个接口接口,来调用Sink服务。
当然,在app.yml中,需要配置对应的App服务:

- app-service-id: /bean/hello
  type: bean-service
  class-name: com.bizmda.bizsip.sample.app.service.HelloAppService

通过接口类方法来实现的App服务type应为“bean-service”。

三、Source模块的开发

对于Source模块,我们这里编写了一个Controller类来实现message的接收以及响应返回:

@Controller
public class HelloSourceController {
    private HelloInterface helloInterface = SourceClientFactory
            .getAppServiceClient(HelloInterface.class,"/bean/hello");

    @GetMapping(value = "/hello")
    @ResponseBody
    public String doService(String message) {
        return this.helloInterface.hello(message);
    }
}

HelloSourceController类中还申请了一个调用“/bean/hello”App服务的调用接口,并在doService()方法中,通过这个接口接口,来调用App服务。

四、启动应用进行测试

启动SampleSourceApplication、SampleSinkApplication和SampleAppApplication应用,通过curl发起请求,就可以接收到响应,响应的报文是在message域前加上了“hello,”:

$ curl http://localhost:8080/hello?message=world

hello,world

Biz-SIP官方网站:http://bizsip.bizmda.com
Gitee:https://gitee.com/szhengye/biz-sip

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值