SpringCloud 異步休息模板

2023-12-02 11:27 更新

 從Sleuth 2.0.0開始,我們不再注冊AsyncRestTemplate類型的bean。 創(chuàng)建這樣的bean取決于您。然后我們對其進(jìn)行檢測。

要阻止AsyncRestTemplate功能,請將spring.sleuth.web.async.client.enabled設(shè)置為false。要禁用默認(rèn)TraceAsyncClientHttpRequestFactoryWrapper的創(chuàng)建,請將spring.sleuth.web.async.client.factory.enabled設(shè)置為false 如果根本不想創(chuàng)建AsyncRestClient,請將spring.sleuth.web.async.client.template.enabled設(shè)置為false

多個異步休息模板

有時您需要使用異步實現(xiàn)模板的多個實現(xiàn)。在以下代碼段中,您可以看到一個如何設(shè)置這樣的自定義AsyncRestTemplate的示例:

@Configuration
@EnableAutoConfiguration
static class Config {

	@Bean(name = "customAsyncRestTemplate")
	public AsyncRestTemplate traceAsyncRestTemplate() {
		return new AsyncRestTemplate(asyncClientFactory(),
				clientHttpRequestFactory());
	}

	private ClientHttpRequestFactory clientHttpRequestFactory() {
		ClientHttpRequestFactory clientHttpRequestFactory = new CustomClientHttpRequestFactory();
		// CUSTOMIZE HERE
		return clientHttpRequestFactory;
	}

	private AsyncClientHttpRequestFactory asyncClientFactory() {
		AsyncClientHttpRequestFactory factory = new CustomAsyncClientHttpRequestFactory();
		// CUSTOMIZE HERE
		return factory;
	}

}


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號