@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);
}
}
网友评论