微服务框架ServiceComb源码解析之一——Consumer发起request请求

Consumer的rest client consumer发送请求,主要是用Spring的RestTemplate,ServiceComb做了一层包装,兼容ServiceComb格式的uri,如cse://business/business/v1/channel/news/subscribe。包装类主要的类图如下,
微服务框架ServiceComb源码解析之一——Consumer发起request请求
文章图片

以servicecomb-java-chassis项目下的demo例子,
微服务框架ServiceComb源码解析之一——Consumer发起request请求
文章图片

【微服务框架ServiceComb源码解析之一——Consumer发起request请求】如下是把cse://格式的uri调用过程中关键方法,

class ConsumerMain: new Consumer().invokeBusiness("cse://business/business/v1", new ChannelRequestBase()); ... class Consumer: ResponseEntity response = template.postForEntity(url, entity, AppClientDataRsp.class); ... class RestTemplateWrapper: getRestTemplate(url).postForEntity(url, request, responseType, uriVariables); ... class RestTemplate: (ResponseEntity)nonNull(this.execute(url, HttpMethod.POST, requestCallback, responseExtractor, uriVariables)); this.getUriTemplateHandler().expand(url, uriVariables); ... abstract class AbstractUriTemplateHandler: public URI expand(String uriTemplate, Object... uriVariables) { URI url = this.expandInternal(uriTemplate, uriVariables); return this.insertBaseUrl(url); } ... class CseUriTemplateHandler: createUri(uriTemplate, uriComponents);

    推荐阅读