Spring xml integration in java dsl - how to identify inbound / outbound channel adapters, counters, etc.

This is my x spring integrator: simple material that I use for training ...

<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 could not find a good tutorial on this. Could you tell me a good tutorial for integrating java dsl? Also, please help me convert this from xml to dsl.

UPDATE: (after Gary Response ):

I managed to translate it before that.

 @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 what I'm doing it right. Wrote it, as soon as I translated, check it out.

Tested: getting the following error:

org.springframework.beans.factory.BeanCreationException: error creating bean with name "archiveFile" defined in si.jdsl.App: bean instance through factory method failed; nested exception org.springframework.beans.BeanInstantiationException: instantiate failed [org.springframework.integration.dsl.IntegrationFlow]: factory method 'archiveFile' threw an exception; java.lang.IllegalArgumentException nested exception: "Filter" (Org.s pringframework.integration.file.filters.CompositeFileListFilter@ 48e64352) is already configured for FileReadingMessageSource

Any thoughts?

UPDATE 2:

Thanks, Gary, solved the filter problem: the problem with the service activator. The 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); } 

Bean initialization failed; org.springframework.beans.factory.UnsatisfiedDependencyException nested exception: Error creating a bean with the name 'myMethod' defined in si.jdsl.App: An unsatisfied dependency is expressed through a constructor argument with index 0 of type [java.io.File] :: Not qualified bean type found [java.io.File] found for dependency: at least 1 bean is expected that qualifies as an autowire candidate for this dependency. Dependency Annotations: {}; nested exception org.springframework.beans.factory.NoSuchBeanDefinitionException: No qualification bean of type [java.io.File] found for a dependency: at least 1 bean is expected that qualifies as a candidate for auto-bracing for this dependency. Dependency Annotations: {}

Please let me know what I am missing?

+4
source share
2 answers

Use the Files factory namespace. See the DSL Reference Guide . There is a general tutorial here that goes through a phased conversion of an example cafe app. (Java version 6/7 is here ).

EDIT

This seems like an error, DSL complains that you are installing two filters and are not allowing it.

In this case, you really do not need it

 .preventDuplicatesFilter(false), 

because it is the default value when providing another filter.

If you need to create a filter, you can use

 .filter(myFilter()) 

where myFilter is a CompositeFileListFilter bean with a filter of templates, etc.

EDIT 2 :

@Bean are created during initialization, obviously this is a runtime method.

See the documentation .

When a @Bean annotated using @ServiceActivator , it must be of type MessageHandler . To use POJO messaging, you need an @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); } } 

In POJO, you can use several messaging methods.

+2
source
 @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; } 
0
source

All Articles