Announcement Announcement Module
No announcement yet.
Questions about usage of jdbc:inbound-channel-adapter Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • Questions about usage of jdbc:inbound-channel-adapter

    I'm using jdbc:inbound-channel-adapter (spring-integration-jdbc-2.1.2 version). I have a flow that has two components:
    1.a database fetcher (using jdbc:inbound-channel-adapter and a poller policy)
    2. a service activator that performs some actions on the retrieved database data
    query="SELECT id from mytable WHERE status=0"
    channel="input" data-source="mydbcTemplate" row-mapper="myMapper" max-rows-per-poll="2" update="UPDATE mytable set status=1 WHERE id in (:id)" >
    <sioller fixed-rate="4000" />

    My questions are related with jdbc:inbound-channel-adapter:

    1. My use case needs a preparation step that should be executed before the data is fetched from the database by the poller. When I start the integration pipeline I have to reset the status field to 0 to all the records.
    Q: How can I implement such a feature to execute an update of the database before the jdbc:ibound-channel to be executed?

    2. How to determine that the select "query" declared in the jdbc:ibound-channel retrieves no results?
    3. When the update query of jdbc:ibound-channel will be executed? Immediately after the data is fetched from database and rowmapper populated or after the pipeline finish the process the entire fetched batch (given by the max-row-per-poll)?

    I look forward for your answers.


  • #2

    1. As I understand you mustn't read DB before you make an UPDATE. In this case you should control lifecycle of <int-jdbc:inbound-channel-adapter> via Control Bus: call its start()/stop().
    From other side you should have another <int-jdbc:inbound-channel-adapter> to call UPDATE and delegate to the Control Bus channel stop() of this new "update"-adapter and start() for your reader.
    And here you have to decide when you will "swap" them to start a new polling flow.

    2. The MessageSource doesn't return anything, so Message won't be sended.
    You can change it to some complex <chain> flow with several <jdbc:outbound-gateway> & <filter> to check a result of 'SELECT count(*) FROM'

    3. Of course, in DB the data will be update after transaction commit.

    Florin, if it isn't so clear, do not be shy - ask questions.

    Take care,


    • #3
      Hi, Artem!
      Thank you for your answers. As far as I can see it looks quite complicated (as I'm a beginner).
      I will give you more information about my use case:
      The pipeline behavior should be as follow:
      1. When is started, it should update status for all rows. This step should be executed ONCE.
      2.After the first step, a second component should check if there any rows that fulfill the criteria for further processing
      3. a) If step 2 has returned a non zero value then go to step 4
      b) If step 2 has returned a zero value then the whole pipeline should be stopped
      4. A component should fetch the db data that fulfill the criteria and go to step 5
      5. A component will take the db data from step 4 and will do its job. Then go to step 2

      1. For the step 1, I have put the update statement in the init method of the RowMapper used for jdbc:inbound adapter. Is that ok?
      2. For the remaining components I'm afraid that I don't know exactly how to implement in terms of configuration. Can you please give me some examples of configuration settings?
      3. Regarding the "update" event that of jdbc:inbound-adapter, I would like to know if it is executed after the data has been fetched from the DB and sent to the next component or after the pipeline has completed to execute the other components of the pipeline?

      I look forward for your answers.