Biz-SIP中间件之xbank项目实战(4)——应用层对客户域和账户域进行服务编排
xbank项目版本库:https://gitee.com/szhengye/xbank.git
项目实践:客户域和账户域服务在应用层的编排
上面已经分别实现了客户域和账户域服务的开发和部署,在应用层中,能方便地对域服务进行服务编排。
在xbank-app模块中,我们可以在PersonalAppService类中,方便地进行服务编排,代码如下:
@Service
public class PersonalAppService implements PersonalAppInterface {
private AccountSinkInterface accountSinkInterface = IntegratorClientFactory
.getSinkClient(AccountSinkInterface.class,"account-sink");
private CustomerSinkInterface customerSinkInterface = IntegratorClientFactory
.getSinkClient(CustomerSinkInterface.class,"customer-sink");
private BizMessageInterface payment1SinkInterface = IntegratorClientFactory
.getSinkClient(BizMessageInterface.class,"payment1-sink");
private BizMessageInterface payment2SinkInterface = IntegratorClientFactory
.getSinkClient(BizMessageInterface.class,"payment2-sink");
private PersonalAppInterface personalAppDelayInterface = IntegratorClientFactory
.getDelayBizServiceClient(PersonalAppInterface.class,"app/personal",
0,1000,2000,4000,8000,16000,32000);
@Override
public CustomerAndAccountList getCustomerAndAccountList(String customerId) {
Customer customer = this.customerSinkInterface.getCustomer(customerId);
List<Account> accountList = this.accountSinkInterface.getAccountListByCustomerId(customerId);
CustomerAndAccountList customerAndAccountList = new CustomerAndAccountList();
customerAndAccountList.setCustomer(customer);
customerAndAccountList.setAccountList(accountList);
return customerAndAccountList;
}
...
}
在getCustomerAndAccountList()方法中,我们可以同时调用客户域的接口customerSinkInterface,也可以调用账户域的接口accountSinkInterface,从而实现多个域服务的混合编排。
这个聚合服务通过bean-service进行部署:

,分别支持Biz-SIP开放平台接口访问和个性化的PersonController实现的REST接口:
- 通过Biz-SIP开放平台接口测试:
$ curl -H "Content-Type:application/json" -H "Biz-Service-Id:app/personal" -X POST --data '{"methodName":"getCustomerAndAccountList","params":["001"]}' http://localhost:8888/api|jq
{
"code": 0,
"message": "success",
"extMessage": null,
"traceId": "c3cda0e1b95f449e986dc5ee41e48716",
"parentTraceId": null,
"timestamp": 1630760469452,
"data": {
"result": {
"accountList": [
{
"accountId": "0001",
"balance": 100,
"customerId": "001"
},
{
"accountId": "0002",
"balance": 200,
"customerId": "001"
}
],
"customer": {
"sex": "1",
"customerName": "张三",
"customerId": "001",
"age": 30
}
}
}
}
- 通过个性化PersonController实现的REST接口,接口测试如下:
$ curl http://localhost:9001/personal/getCustomerAndAccountList\?customerId=001|jq
{
"customer": {
"customerId": "001",
"customerName": "张三",
"age": 30,
"sex": "1"
},
"accountList": [
{
"accountId": "0001",
"customerId": "001",
"balance": 100
},
{
"accountId": "0002",
"customerId": "001",
"balance": 200
}
]
}
Biz-SIP官方网站:http://bizsip.bizmda.com
Gitee:https://gitee.com/szhengye/biz-sip
浙公网安备 33010602011771号