[英]Spring Integration file processing send it to http
我在春季集成中有一些要解决的问题,我是春季集成中的新手。
该方案是处理三个dbf文件并提取数据,并将其作为JSON发送到HTTP rest服务,如果3分钟内该服务没有响应,则应等待10分钟,然后再次尝试。 其余服务将以json回复。
现在我有三到四件事我无法解决:
在我的Spring集成配置下面:
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/file http://www.springframework.org/schema/integration/file/spring-integration-file.xsd
http://www.springframework.org/schema/task http://www.springframework.org/schema/task/spring-task.xsd
http://www.springframework.org/schema/integration/http http://www.springframework.org/schema/integration/http/spring-integration-http.xsd"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-file="http://www.springframework.org/schema/integration/file"
xmlns:int-http="http://www.springframework.org/schema/integration/http"
xmlns:task="http://www.springframework.org/schema/task">
<int:service-activator input-channel="filesInChannelDBF"
output-channel="requestChannel" >
<bean class="com.mm.integration.serviceactivator.FileProcessor" />
</int:service-activator>
<int:channel id="requestChannel" />
<int-http:outbound-gateway request-channel="requestChannel"
url="http://localhost:8090/receiveGateway" http-method="POST" />
<int-file:inbound-channel-adapter id="filesInChannelDBF"
directory="file:input" filename-pattern="FILENAME*">
<int:poller id="poller" fixed-rate="100" task-executor="executor" />
</int-file:inbound-channel-adapter>
<task:executor id="executor" pool-size="10" />
</beans>
这是我的pom:
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven- 4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.mm.integration</groupId>
<artifactId>XXXX</artifactId>
<version>0.0.1-SNAPSHOT</version>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.1.9.RELEASE</version>
</parent>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-integration</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-logging</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
</project>
这是我春季的入口
@RestController
@EnableAutoConfiguration
@EnableIntegration
@ImportResource("classpath:spring/config/concurrentFileProcessing-config.xml")
public class MainApp {
@RequestMapping(value="/receiveGateway" , method=RequestMethod.POST)
public String testGateway(String jSon){
System.out.println("Starting process the message [reciveing]");
return "{HelloMessage: \"Hello\"}";
}
public static void main(String[] args) throws Exception {
SpringApplication.run(MainApp.class, args);
}
}
1-我需要阅读其余服务的回复,并根据该回复决定重试还是完成该过程。
任何processor
(例如<int-http:outbound-gateway>
)端点都可以使用<request-handler-advice-chain>
进行配置。 并且为您提供了现成的建议: RequestHandlerRetryAdvice
和ExpressionEvaluatingRequestHandlerAdvice
。 您可以将重试建议指定为第一个,将表达式指定为第二个。 对于最后一个,您可以决定是否引发异常以启动该包装重试。 因为这只能在异常时重试。 拥有处理RetryContext
的能力比指定异常独立地指定自定义RetryPolicy
。
另外,请考虑使用带有超时选项的request-factory
来处理no response
情况。
2-我需要从动态文件夹名称中获取多个文件,例如({whereever / 20140101 / HERE将找到三个DBF文件)。
考虑使用RecursiveLeafOnlyDirectoryScanner
从指定的根目录扫描那些时间戳目录。 从另一面看,您甚至可以提供任何DirectoryScanner
实施以实现要求。
3-有可能通过Spring集成处理dbf文件并将其转换为json
不,Spring Integration不支持该功能。 您可以考虑使用一些现有工具来读取DBF( https://github.com/iryndin/jdbf ),然后手动构建JSON。
另一方面,可以使用适当的适配器将其作为扩展扩展回框架。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.