【问题标题】:Spring Integration file processing send it to httpSpring Integration 文件处理发送到 http
【发布时间】:2014-12-09 06:14:24
【问题描述】:

我在 Spring 集成中有一些要解决的问题,我是 Spring 集成的新手。

场景是处理三个 dbf 文件并提取数据并将其作为 JSON 发送到 HTTP REST 服务,如果该服务在 3 分钟内没有响应,则应等待 10 分钟并再次尝试。其余服务将以 json 回复。

现在我有三到四件事无法解决:

  1. 我需要阅读来自 rest 服务的回复,并根据该回复决定是重试还是完成该过程。 (如果我发送消息休息并且没有响应也应该重试)
  2. 例如,我需要从动态文件夹名称中获取多个文件({wherever}/20140101/HERE 将找到三个 DBF 文件)。有没有可能将文件夹名称作为模式或特定格式的日期?并且文件适配器可以处理多个文件或逐个文件。
  3. 有任何可能通过spring集成处理dbf文件并将其转换为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);
    }

}

【问题讨论】:

    标签: java spring rest soa spring-integration


    【解决方案1】:

    1- 我需要阅读来自休息服务的回复,并根据该回复决定重试或完成该过程。

    任何processor(例如&lt;int-http:outbound-gateway&gt;)端点都可以配置为&lt;request-handler-advice-chain&gt;。还有现成可用的建议:RequestHandlerRetryAdviceExpressionEvaluatingRequestHandlerAdvice。您可以将重试建议指定为第一个,将表达式指定为第二个。最后,您可以决定是否抛出异常来启动包装重试。因为这个只能在异常时重试。能够独立于异常指定自定义RetryPolicy 比与RetryContext 打交道要好。

    另外考虑使用带有超时选项的request-factory 来处理no response 的情况。

    2- 例如,我需要从动态文件夹名称中获取多个文件({wherever}/20140101/HERE 将找到三个 DBF 文件)。

    考虑使用RecursiveLeafOnlyDirectoryScanner 从指定的根目录扫描那些时间戳目录。另一方面,您甚至可以提供任何DirectoryScanner 实现来实现需求。

    3-有任何可能通过spring集成处理dbf文件并将其转换为json

    不,Spring Integration 不支持该功能。您可以考虑使用一些现有的工具来读取 DBF (https://github.com/iryndin/jdbf),然后手动构建 JSON。

    从其他方面随意将其作为 extension 和适当的适配器回馈给框架。

    【讨论】:

    猜你喜欢
    • 2018-09-17
    • 2014-10-08
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-02-06
    • 1970-01-01
    • 2013-10-01
    相关资源
    最近更新 更多