0

I am going to start a new project using Spring framework. As I dont have much experience in Spring I need your help to sort out few confusions.

Lets look at use case

My application uses Spring integration framework. The core functionality of my app is,

  1. I need to poll multiple directories from file system,
  2. read the files(csv mostly),
  3. process some operations on them and insert them to database.

Currently I have set up spring integration flow for it. Which has inbound-chaneell-adapter for polling and then file traverse through the channels and at the end inserted into database.

My concerns are

  1. Number of directories application supposed to poll will be decided at runtime. Hence I need to create inbound-chanell-adapter at runtime (as one chanell adapter can poll only one directory at once) and cant define them statically in my spring context xml (As I dont know the how many I need).

  2. Each directory has certain properties which should be applied to the file while processing.(While going through the integration flow)

  3. So right now what I am doing is I am loading new ClassPathXmlApplicationContext("/applicationContext.xml"); for each directory. And cache the required properties in that newly created context. And use them at the time of processing (in <int:service-activator>).

Drawbacks of current design

  1. Separate context is created for each directory.
  2. Unnecessary beans are duplicated. (Database session factories and like)

So is there any way to design the application in such a way that context will not be duplicated. And still I can use properties of each directory throughout the integration flow at the same time???

Thanks in advance.

M. Deinum
  • 115,695
  • 22
  • 220
  • 224
Zebronix_777
  • 345
  • 4
  • 25
  • 3
    Just create a factory which creates as many `inbound-channel-adapters` as you need. Never recreate a context as in the end you will run into strange memory, transaction issues etc. – M. Deinum May 27 '16 at 12:45
  • @MDeinum, Yes I can create factory for it but still not sure how should I pass corresponding properties throughout the channell flow. ????Every directory has specific properties upon which some operations supposed to perform on message payload. – Zebronix_777 May 28 '16 at 07:19

1 Answers1

3

See the dynamic ftp sample and the links in its readme about creating child contexts when needed, containing new inbound components.

Also see my answer to a similar question for multiple IMAP mail adapters using Java configuration and then a follow-up question.

You can also use a message source advice to reconfigure the FileReadingMessageSource on each poll to look at different directories. See Smart polling.

Community
  • 1
  • 1
Gary Russell
  • 166,535
  • 14
  • 146
  • 179