java - 超时动态 HTTP 出站网关请求工厂

标签 java spring spring-integration

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

<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 初始启动。

我该怎么做?

最佳答案

以编程方式,您可以通过注入(inject) requestFactoryGetByCustomer bean 并使用其 setter 的任何服务来做到这一点:

@Autowired
private SimpleClientHttpRequestFactory requestFactoryGetByCustomer;

....

this.requestFactoryGetByCustomer.setConnectTimeout(30_000);

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

关于java - 超时动态 HTTP 出站网关请求工厂,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31793760/

相关文章:

java - Spring集成验证

java - 使用 Maven 预填充 MongoDB 数据库

java - Hazelcast MapStrore#store()

java - Spring Boot应用程序找不到webjar文件

java - Spring集成中的"Repeat until condition satisfied"

java - 运行使用 Cucumber 实现 CommandLineRunner 的 SpringBoot 应用程序,在运行功能测试用例之前运行主应用程序

java - 防止导入 android.R

java - XMLStreamException : Parse error

spring - 如何使用 Spring Integration 仅在事务成功完成时发送消息?

spring - 从 Spring Boot 2.1.9 升级到 2.2.1 (Spring Integration) 后的 ClassCastException