超时动态 HTTP 出站网关请求工厂 [英] timeout dynamic HTTP outbound gateway request-factory

查看:35
本文介绍了超时动态 HTTP 出站网关请求工厂的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经为 HTTP 出站网关配置了超时,使用 request-factory 属性提供对 ClientHttpRequestFactory bean 的引用:

I have configured timeouts for the HTTP Outbound Gateway providing a reference to a ClientHttpRequestFactory bean using the request-factory attribute:

<int-http:outbound-gateway request-channel="channelGetByCustomer"
    request-factory="requestFactoryGetByCustomer"
    reply-channel="jsonToObjectChannel" url="${getbycustomer.endpoint.url}"
    http-method="GET" expected-response-type="com.mbracero.integration.dto.Item[]">

    <int-http:uri-variable name="customerid" expression="payload.customerid"/>

</int-http:outbound-gateway>

<beans:bean id="requestFactoryGetByCustomer" class="org.springframework.http.client.SimpleClientHttpRequestFactory">
    <beans:property name="connectTimeout" value="${getbycustomer.timeout}"/>
    <beans:property name="readTimeout" value="${getbycustomer.timeout}"/>
</beans:bean>

但我想从 DDBB(或以编程方式)而不是从 Spring 初始启动动态加载这些属性.

But I want to load these attributes dynamically from DDBB (or programmatically) and not from Spring initial boot.

我该怎么做?

推荐答案

您可以通过编程方式执行此操作,只需从您的任何服务注入 requestFactoryGetByCustomer bean 并使用其设置器即可:

Programmatically you can do that just from any your service injecting that requestFactoryGetByCustomer bean and using its setters:

@Autowired
private SimpleClientHttpRequestFactory requestFactoryGetByCustomer;

....

this.requestFactoryGetByCustomer.setConnectTimeout(30_000);

要从 DB 中读取这些选项并使用 Spring Container 功能将它们填充到 bean 定义中(例如在您当前的情况下的属性占位符),您应该查看 Commons Configuration 框架并从 DB SELECT 填充 Properties 对象代码>.

To read those options from the DB and populate them to the bean definition using Spring Container features (e.g. Property Placeholder like in your current case) you should take a look to the Commons Configuration framework and populate Properties object from the DB SELECT.

这篇关于超时动态 HTTP 出站网关请求工厂的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆