我正在使用注入的RestTemplateBuilders,并在构造函数中创建一个RestTemplate。我正在使用RestTemplate发出请求...
我想做的是我想向默认指标添加一个自定义标签,该标签由Actuator自动检测。 (http.client.requests指标)
有一种实现RestTemplateExchangeTagsProvider的可能性,但我至少需要阅读请求的正文,我找不到任何选项。为此,我应该重写的功能是:
@Override
public Iterable<Tag> getTags(String urlTemplate, HttpRequest request, ClientHttpResponse response)
对我来说,更清洁的选择是能够在执行请求时添加标签...
对于那些想通过代码块了解我想要的东西的人:
@Service
public class SomeRestService {
private final RestTemplate restTemplate;
public SomeRestService(RestTemplateBuilder restTemplateBuilder) {
this.restTemplate = restTemplateBuilder.build();
}
public void doSomething(String urlString, SomeObject someObject){
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<SomeObject> request = new HttpEntity<>(someObject, headers);
//What I would like to do is having a custom tag while doing the next request.
ResponseEntity<String> response = restTemplate.postForEntity(urlString, request, String.class);
}
}