timeout dynamic HTTP outbound gateway request-factory

三世轮回 提交于 2021-01-27 20:23:30

问题


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>

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

How can I do this?


回答1:


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);

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.



来源:https://stackoverflow.com/questions/31793760/timeout-dynamic-http-outbound-gateway-request-factory

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!