应用平台 APPSTAGE-使用Gray SDK:服务消费端集成示例

时间:2024-10-21 16:40:47

服务消费端集成示例

照常通过 CS E调用服务提供者,无需额外编码。

例如,参考CSE的消费端开发,从消费端调用服务提供端(demoB),无需额外修改。

package com.service.demo.controller;

import org.springframework.stereotype.Component;
import org.apache.servicecomb.provider.springmvc.reference.RestTemplateBuilder;
import org.springframework.web.client.RestTemplate;
@Component
publicclass DemoDelegate {

public String helloworld(String name){

if ( null == name || "".equals(name))
{
return "thename is empty, no need send to beckend MS";
}

RestTemplate restTemplate = RestTemplateBuilder.create();
String rslt = "";
String qryStr = "";
qryStr = "name=" + name;

// to call another MicroService, name is demoB. path:/demo,interface:helloworld
rslt = restTemplate
.getForObject("cse://demoB/demo/helloworld?" + qryStr, String.class);
return rslt;
}
}
support.huaweicloud.com/sdkreference-appstage/appstage_08_0039.html