简体   繁体   English

Spring Integration xml to java dsl - 如何定义入站/出站通道适配器,轮询器等

[英]Spring Integration xml to java dsl - how to define inbound/outbound channel adaptors, pollers, etc

This is my spring integration xml: A simple stuff i'm using for learning... 这是我的spring集成xml:我用来学习的一个简单的东西......

<int-file:inbound-channel-adapter id="executionMessageFileInputChannel"
                                  directory="file:${fpml.messages.input}"
                                  prevent-duplicates="false" filename-pattern="*.xml">
    <int:poller fixed-delay="20000" max-messages-per-poll="20"/>
</int-file:inbound-channel-adapter>

<int:service-activator input-channel="executionMessageFileInputChannel"
                       output-channel="executionMessageFileArchiveChannel"
                       ref="dummyService" method="myMethod"/>


<int-file:outbound-channel-adapter id="executionMessageFileArchiveChannel"
                                   directory="file:${fpml.messages.archive}"
                                   delete-source-files="true" auto-create-directory="true"/>

I couldn't really find a good tutorial on this.. could you please point me to a good tutorial for integration java dsl? 我真的找不到一个很好的教程..请你指点一下java dsl集成的好教程? Also, please help me convert this from xml to dsl. 另外,请帮我把它从xml转换为dsl。

UPDATE: (after Gary's Response ) : 更新:(Gary的回应之后 ):

I managed to translate it till this. 我设法把它翻译到这个。

@MessagingGateway
public interface Archive {
    @Gateway(requestChannel = "archiveFile.input")
    void archive();
}

@Bean
    public IntegrationFlow archiveFile() {
        return IntegrationFlows
                .from(Files.inboundAdapter(new File(dirPath))
                                .patternFilter("*.xml")
                                .preventDuplicatesFilter(false),
                        e -> e.poller(Pollers.fixedDelay(20000)
                                .maxMessagesPerPoll(20)))
                .handle("app","myMethod")
                .handle(Files.outboundAdapter(new File(outDirPath)).deleteSourceFiles(true).autoCreateDirectory(true))
                .get();
    }

Just not sure if this I'm doing it right. 只是不确定我是否正确行事。 Posted it as soon as I translated, will test it out. 我翻译后立即发布,将测试出来。

Tested it : getting the following error: 测试它:得到以下错误:

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'archiveFile' defined in si.jdsl.App: Bean instantiation via factory method failed; org.springframework.beans.factory.BeanCreationException:在si.jdsl.App中定义了名为'archiveFile'的bean时出错:通过工厂方法实例化Bean失败; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.integration.dsl.IntegrationFlow]: Factory method 'archiveFile' threw exception; 嵌套异常是org.springframework.beans.BeanInstantiationException:无法实例化[org.springframework.integration.dsl.IntegrationFlow]:工厂方法'archiveFile'抛出异常; nested exception is java.lang.IllegalArgumentException: The 'filter' (org.springframework.integration.file.filters.CompositeFileListFilter@48e64352) is already configured for the FileReadingMessageSource 嵌套异常是java.lang.IllegalArgumentException:已经为FileReadingMessageSource配置了'filter'(org.springframework.integration.file.filters.CompositeFileListFilter@48e64352)

Any thoughts? 有什么想法吗?

UPDATE 2: 更新2:

Thanks Gary, That solved the filter issue: Getting issue with service activator. 谢谢Gary,这解决了过滤器问题:服务激活器出现问题。 Following is my service activator: 以下是我的服务激活者:

@Bean
    @ServiceActivator(inputChannel = "archiveFile.input")
    public Message<File> myMethod (File inputFile){
        Map<String, Object> contextHeader = new HashMap<String, Object>();
        return new GenericMessage<File>(inputFile, contextHeader);
    }

Initialization of bean failed; bean的初始化失败; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'myMethod' defined in si.jdsl.App: Unsatisfied dependency expressed through constructor argument with index 0 of type [java.io.File]: : No qualifying bean of type [java.io.File] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. 嵌套异常是org.springframework.beans.factory.UnsatisfiedDependencyException:在si.jdsl.App中定义名为'myMethod'的bean时出错:通过构造函数参数表达的不满意的依赖关系,索引0的类型为[java.io.File] :::否为依赖项找到类型[java.io.File]的限定bean:预期至少有1个bean,它有资格作为此依赖项的autowire候选者。 Dependency annotations: {}; 依赖注释:{}; nested exception is org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualifying bean of type [java.io.File] found for dependency: expected at least 1 bean which qualifies as autowire candidate for this dependency. 嵌套异常是org.springframework.beans.factory.NoSuchBeanDefinitionException:没有为依赖项找到类型为[java.io.File]的限定bean:期望至少有一个bean可以作为此依赖项的autowire候选者。 Dependency annotations: {} 依赖注释:{}

Please let me know what i'm missing? 请让我知道我错过了什么?

Use the Files namespace factory. 使用Files命名空间工厂。 See the DSL reference manual . 请参阅DSL参考手册 There's a general tutorial here which walks through a line-by-line conversion of the cafe sample app. 有一个通用教程这里通过管路,通过在线变换网吧示例应用程序的散步。 (Java 6/7 version here ). 这里是 Java 6/7版本)。

EDIT : 编辑

This looks like a bug, the DSL is complaining that you are setting two filters and it won't allow it. 这看起来像一个错误,DSL抱怨你正在设置两个过滤器,它不会允许它。

In this case, you actually don't need this 在这种情况下,您实际上不需要这个

.preventDuplicatesFilter(false),

because that's the default when you provide another filter. 因为这是您提供另一个过滤器时的默认值。

If you do need to compose a filter you can use 如果您确实需要编写可以使用的过滤器

.filter(myFilter())

where myFilter is a CompositeFileListFilter bean with pattern filter etc. 其中myFilter是一个带有模式过滤器等的CompositeFileListFilter bean。

EDIT 2 : 编辑2

@Bean s are constructed at initialization time, clearly this is a runtime method. @Bean是在初始化时构造的,显然这是一个运行时方法。

See the documentation . 请参阅文档

When a @Bean is annotated with @ServiceActivator , it must be of type MessageHandler . 使用@ServiceActivator注释@Bean ,它必须是MessageHandler类型。 To use POJO messaging, you need a @MessageEndpoint bean... 要使用POJO消息传递,您需要一个@MessageEndpoint bean ...

@Bean
public MyPojo myPojo() {
    return new MyPojo();
}

@MessageEndpoint
public static class MyPojo {

    @ServiceActivator(inputChannel = "archiveFile.input")
    public Message<File> myMethod (File inputFile){
        Map<String, Object> contextHeader = new HashMap<String, Object>();
        return new GenericMessage<File>(inputFile, contextHeader);
    }

}

You can have multiple messaging methods in the POJO. 您可以在POJO中使用多种消息传递方法。

@Bean
    @InboundChannelAdapter(value = "fileInputChannel", poller = @Poller(fixedDelay = "1000"))
    public MessageSource<File> fileReadingMessageSource() {
        CompositeFileListFilter<File> filters =new CompositeFileListFilter<>();
        filters.addFilter(new SimplePatternFileListFilter("*.log"));
        filters.addFilter(new LastModifiedFileFilter());

        FileReadingMessageSource source = new FileReadingMessageSource();
        source.setAutoCreateDirectory(true);
        source.setDirectory(new File(DIRECTORY));
        source.setFilter(filters);

        return source;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将 Spring 集成 xml 转换为 Java DSL - Inbound Channel 适配器中的调用方法 - Converting Spring integration xml to Java DSL - Invoke method in Inbound Channel adapter Spring Integration Java DSL中的JPA出站通道适配器配置 - JPA outbound channel adapter config in Spring Integration Java DSL Spring集成 - 入站和出站通道适配器 - Spring Integration - Inbound vs Outbound Channel Adapters Spring Integration DSL JDBC 入站通道适配器 - Spring Integration DSL JDBC inbound channel adapter 在 Spring Integration 5 上使用 Spring Integration Java DSL 在入站通道上配置目录扫描器 - Configure a directory scanner on an inbound channel with Spring Integration Java DSL on Spring Integration 5 如何将 Spring 集成 XML 转换为 Java DSL - How to convert Spring Integration XML to Java DSL 如何在Spring Integration Java DSL中处理ExecutorChannel的错误通道 - How to handle error channel for ExecutorChannel in Spring Integration Java DSL spring 与 java DSL 集成中的空闲队列通道 - Free queue channel in spring integration with java DSL Spring Integration Java DSL:文件入站异常传播 - Spring Integration Java DSL: file inbound exception propagation Spring Integration Java DSL - Http Outbound Gateway uri 变量表达式 - Spring Integration Java DSL - Http Outbound Gateway uri variable Expression
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM