ny
23 小时以前 b6f169fe43a2b13f351aefc152374fc7f0bc8cb7
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package jnpf.consumers.controller;
 
import io.swagger.v3.oas.annotations.tags.Tag;
import io.swagger.v3.oas.annotations.Operation;
import jnpf.base.ActionResult;
import jnpf.entity.ContractEntity;
import jnpf.provider.example.ContractProvider;
import jnpf.util.ServletUtil;
import org.apache.dubbo.config.annotation.DubboReference;
import org.apache.dubbo.rpc.RpcContext;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
 
/**
 * @author JNPF开发平台组
 * @version V3.1.0
 * @copyright 引迈信息技术有限公司(https://www.jnpfsoft.com)
 * @date 2021-06-21
 */
@RestController
@Tag(description = "Contract", name = "Contract")
@RequestMapping("/Consumers")
public class DubboConsumersController {
    /**
     * 使用dubbo示例
     */
    @DubboReference
    private ContractProvider contractProvider;
 
    @Operation(summary = "使用dubbo调用,获取详情")
    @GetMapping("/{id}")
    public ActionResult consumers(@PathVariable("id") String id){
        /** 不建议常规业务使用!!! */
        /** 若有个别业务需要使用dubbo调用且携带token,使用隐式参数 */
        //获取token
        String token = ServletUtil.getRequest().getHeader("Authorization");
        //传递参数 K,V
        RpcContext.getContext().setAttachment("Authorization", token);
        ContractEntity entity = contractProvider.getInfo(id);
        return ActionResult.success(entity);
    }
}