美文网首页
Spring Cloud获取服务在Consul中的配置

Spring Cloud获取服务在Consul中的配置

作者: EasyNetCN | 来源:发表于2020-02-29 22:04 被阅读0次
@RestController
@RequestMapping("consul")
public class ConsulServiceController {
    @Value("${spring.profiles.active}")
    private String profile;

    @Autowired
    private ConsulConfigProperties consulConfigProperties;

    @Autowired
    private ConsulClient connsulClient;

    @GetMapping("config")
    public Mono<Response<List<GetValue>>> config(String service) {
        var key = new StringBuilder(consulConfigProperties.getPrefix()).append("/").append(service)
                .append(consulConfigProperties.getProfileSeparator()).append(profile).append("/")
                .append(consulConfigProperties.getDataKey()).toString();

        var response = connsulClient.getKVValues(key, consulConfigProperties.getAclToken(), QueryParams.DEFAULT);

        return Mono.justOrEmpty(response);
    }

}

相关文章

网友评论

      本文标题:Spring Cloud获取服务在Consul中的配置

      本文链接:https://www.haomeiwen.com/subject/kjyihhtx.html