Intermediate result storage for Spring Batch processing REST service











up vote
0
down vote

favorite












I would like to get a document out of REST service, process with Spring Batch and then send to other REST service without saving anything to any database.



Considering each Step needs it's ItemReader and ItemWriter, I imagine I would need to implement one ItemReader that will download documents from input service, one ItemWriter that will somehow store intermediate results in memory, then an ItemReader that will read such results from memory for next steps and the last ItemWriter that will send results once all processing is done.



Would that be a good approach or does anyone have any better ideas?










share|improve this question


























    up vote
    0
    down vote

    favorite












    I would like to get a document out of REST service, process with Spring Batch and then send to other REST service without saving anything to any database.



    Considering each Step needs it's ItemReader and ItemWriter, I imagine I would need to implement one ItemReader that will download documents from input service, one ItemWriter that will somehow store intermediate results in memory, then an ItemReader that will read such results from memory for next steps and the last ItemWriter that will send results once all processing is done.



    Would that be a good approach or does anyone have any better ideas?










    share|improve this question
























      up vote
      0
      down vote

      favorite









      up vote
      0
      down vote

      favorite











      I would like to get a document out of REST service, process with Spring Batch and then send to other REST service without saving anything to any database.



      Considering each Step needs it's ItemReader and ItemWriter, I imagine I would need to implement one ItemReader that will download documents from input service, one ItemWriter that will somehow store intermediate results in memory, then an ItemReader that will read such results from memory for next steps and the last ItemWriter that will send results once all processing is done.



      Would that be a good approach or does anyone have any better ideas?










      share|improve this question













      I would like to get a document out of REST service, process with Spring Batch and then send to other REST service without saving anything to any database.



      Considering each Step needs it's ItemReader and ItemWriter, I imagine I would need to implement one ItemReader that will download documents from input service, one ItemWriter that will somehow store intermediate results in memory, then an ItemReader that will read such results from memory for next steps and the last ItemWriter that will send results once all processing is done.



      Would that be a good approach or does anyone have any better ideas?







      spring rest spring-batch






      share|improve this question













      share|improve this question











      share|improve this question




      share|improve this question










      asked Nov 11 at 12:15









      Leonid Bor

      5151920




      5151920
























          1 Answer
          1






          active

          oldest

          votes

















          up vote
          0
          down vote














          I would like to get a document out of REST service, process with Spring Batch and then send to other REST service




          You can do it in one chunk-oriented step. The reader to get data from the REST service, a processor to process data and a write to post/put data to the other REST service.




          without saving anything to any database.




          Even though you don't want to save anything to a database (I guess you mean to a separate database server), you can still use an in-memory database and save intermediate processing results to a staging table. A first step would get the data from the REST service, process it and write it to the staging table. The second step reads data from the staging table and send it to the second REST service. The advantage of this technique is that you can do aggregation on processing results on the staging table before starting the second step.




          Would that be a good approach or does anyone have any better ideas?




          A third way to do it is to use a staging in-memory java.util.Queue. Here, you can use two steps like with the staging table but using the queue as the staging storage.



          Hope this helps.






          share|improve this answer





















          • What if i run two or more such jobs at the same time? I guess i’ll have to use locking ob the table, which might affect performance. What about storing data in job context? Is it possible via ItemProcessor interface? I need to have more than one processor btw
            – Leonid Bor
            Nov 13 at 21:22










          • no need for locking, you can have a staging table per job instance, or a discriminator column to distinguish between records. Storing data in job context is not recommended if the data is big enough because the execution context end up serialized and persisted in the database.
            – Mahmoud Ben Hassine
            Nov 13 at 22:57












          • You mean the context is persisted after the job is done?
            – Leonid Bor
            Nov 15 at 10:29










          • no, the step execution context is persisted after each chunk, whereas the job execution context is persisted after each step. Please refer to last paragraph of this section: docs.spring.io/spring-batch/4.1.x/reference/html/….
            – Mahmoud Ben Hassine
            Nov 15 at 10:33











          Your Answer






          StackExchange.ifUsing("editor", function () {
          StackExchange.using("externalEditor", function () {
          StackExchange.using("snippets", function () {
          StackExchange.snippets.init();
          });
          });
          }, "code-snippets");

          StackExchange.ready(function() {
          var channelOptions = {
          tags: "".split(" "),
          id: "1"
          };
          initTagRenderer("".split(" "), "".split(" "), channelOptions);

          StackExchange.using("externalEditor", function() {
          // Have to fire editor after snippets, if snippets enabled
          if (StackExchange.settings.snippets.snippetsEnabled) {
          StackExchange.using("snippets", function() {
          createEditor();
          });
          }
          else {
          createEditor();
          }
          });

          function createEditor() {
          StackExchange.prepareEditor({
          heartbeatType: 'answer',
          convertImagesToLinks: true,
          noModals: true,
          showLowRepImageUploadWarning: true,
          reputationToPostImages: 10,
          bindNavPrevention: true,
          postfix: "",
          imageUploader: {
          brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
          contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
          allowUrls: true
          },
          onDemand: true,
          discardSelector: ".discard-answer"
          ,immediatelyShowMarkdownHelp:true
          });


          }
          });














          draft saved

          draft discarded


















          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248654%2fintermediate-result-storage-for-spring-batch-processing-rest-service%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          1 Answer
          1






          active

          oldest

          votes








          1 Answer
          1






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes








          up vote
          0
          down vote














          I would like to get a document out of REST service, process with Spring Batch and then send to other REST service




          You can do it in one chunk-oriented step. The reader to get data from the REST service, a processor to process data and a write to post/put data to the other REST service.




          without saving anything to any database.




          Even though you don't want to save anything to a database (I guess you mean to a separate database server), you can still use an in-memory database and save intermediate processing results to a staging table. A first step would get the data from the REST service, process it and write it to the staging table. The second step reads data from the staging table and send it to the second REST service. The advantage of this technique is that you can do aggregation on processing results on the staging table before starting the second step.




          Would that be a good approach or does anyone have any better ideas?




          A third way to do it is to use a staging in-memory java.util.Queue. Here, you can use two steps like with the staging table but using the queue as the staging storage.



          Hope this helps.






          share|improve this answer





















          • What if i run two or more such jobs at the same time? I guess i’ll have to use locking ob the table, which might affect performance. What about storing data in job context? Is it possible via ItemProcessor interface? I need to have more than one processor btw
            – Leonid Bor
            Nov 13 at 21:22










          • no need for locking, you can have a staging table per job instance, or a discriminator column to distinguish between records. Storing data in job context is not recommended if the data is big enough because the execution context end up serialized and persisted in the database.
            – Mahmoud Ben Hassine
            Nov 13 at 22:57












          • You mean the context is persisted after the job is done?
            – Leonid Bor
            Nov 15 at 10:29










          • no, the step execution context is persisted after each chunk, whereas the job execution context is persisted after each step. Please refer to last paragraph of this section: docs.spring.io/spring-batch/4.1.x/reference/html/….
            – Mahmoud Ben Hassine
            Nov 15 at 10:33















          up vote
          0
          down vote














          I would like to get a document out of REST service, process with Spring Batch and then send to other REST service




          You can do it in one chunk-oriented step. The reader to get data from the REST service, a processor to process data and a write to post/put data to the other REST service.




          without saving anything to any database.




          Even though you don't want to save anything to a database (I guess you mean to a separate database server), you can still use an in-memory database and save intermediate processing results to a staging table. A first step would get the data from the REST service, process it and write it to the staging table. The second step reads data from the staging table and send it to the second REST service. The advantage of this technique is that you can do aggregation on processing results on the staging table before starting the second step.




          Would that be a good approach or does anyone have any better ideas?




          A third way to do it is to use a staging in-memory java.util.Queue. Here, you can use two steps like with the staging table but using the queue as the staging storage.



          Hope this helps.






          share|improve this answer





















          • What if i run two or more such jobs at the same time? I guess i’ll have to use locking ob the table, which might affect performance. What about storing data in job context? Is it possible via ItemProcessor interface? I need to have more than one processor btw
            – Leonid Bor
            Nov 13 at 21:22










          • no need for locking, you can have a staging table per job instance, or a discriminator column to distinguish between records. Storing data in job context is not recommended if the data is big enough because the execution context end up serialized and persisted in the database.
            – Mahmoud Ben Hassine
            Nov 13 at 22:57












          • You mean the context is persisted after the job is done?
            – Leonid Bor
            Nov 15 at 10:29










          • no, the step execution context is persisted after each chunk, whereas the job execution context is persisted after each step. Please refer to last paragraph of this section: docs.spring.io/spring-batch/4.1.x/reference/html/….
            – Mahmoud Ben Hassine
            Nov 15 at 10:33













          up vote
          0
          down vote










          up vote
          0
          down vote










          I would like to get a document out of REST service, process with Spring Batch and then send to other REST service




          You can do it in one chunk-oriented step. The reader to get data from the REST service, a processor to process data and a write to post/put data to the other REST service.




          without saving anything to any database.




          Even though you don't want to save anything to a database (I guess you mean to a separate database server), you can still use an in-memory database and save intermediate processing results to a staging table. A first step would get the data from the REST service, process it and write it to the staging table. The second step reads data from the staging table and send it to the second REST service. The advantage of this technique is that you can do aggregation on processing results on the staging table before starting the second step.




          Would that be a good approach or does anyone have any better ideas?




          A third way to do it is to use a staging in-memory java.util.Queue. Here, you can use two steps like with the staging table but using the queue as the staging storage.



          Hope this helps.






          share|improve this answer













          I would like to get a document out of REST service, process with Spring Batch and then send to other REST service




          You can do it in one chunk-oriented step. The reader to get data from the REST service, a processor to process data and a write to post/put data to the other REST service.




          without saving anything to any database.




          Even though you don't want to save anything to a database (I guess you mean to a separate database server), you can still use an in-memory database and save intermediate processing results to a staging table. A first step would get the data from the REST service, process it and write it to the staging table. The second step reads data from the staging table and send it to the second REST service. The advantage of this technique is that you can do aggregation on processing results on the staging table before starting the second step.




          Would that be a good approach or does anyone have any better ideas?




          A third way to do it is to use a staging in-memory java.util.Queue. Here, you can use two steps like with the staging table but using the queue as the staging storage.



          Hope this helps.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 11 at 19:21









          Mahmoud Ben Hassine

          3,4551714




          3,4551714












          • What if i run two or more such jobs at the same time? I guess i’ll have to use locking ob the table, which might affect performance. What about storing data in job context? Is it possible via ItemProcessor interface? I need to have more than one processor btw
            – Leonid Bor
            Nov 13 at 21:22










          • no need for locking, you can have a staging table per job instance, or a discriminator column to distinguish between records. Storing data in job context is not recommended if the data is big enough because the execution context end up serialized and persisted in the database.
            – Mahmoud Ben Hassine
            Nov 13 at 22:57












          • You mean the context is persisted after the job is done?
            – Leonid Bor
            Nov 15 at 10:29










          • no, the step execution context is persisted after each chunk, whereas the job execution context is persisted after each step. Please refer to last paragraph of this section: docs.spring.io/spring-batch/4.1.x/reference/html/….
            – Mahmoud Ben Hassine
            Nov 15 at 10:33


















          • What if i run two or more such jobs at the same time? I guess i’ll have to use locking ob the table, which might affect performance. What about storing data in job context? Is it possible via ItemProcessor interface? I need to have more than one processor btw
            – Leonid Bor
            Nov 13 at 21:22










          • no need for locking, you can have a staging table per job instance, or a discriminator column to distinguish between records. Storing data in job context is not recommended if the data is big enough because the execution context end up serialized and persisted in the database.
            – Mahmoud Ben Hassine
            Nov 13 at 22:57












          • You mean the context is persisted after the job is done?
            – Leonid Bor
            Nov 15 at 10:29










          • no, the step execution context is persisted after each chunk, whereas the job execution context is persisted after each step. Please refer to last paragraph of this section: docs.spring.io/spring-batch/4.1.x/reference/html/….
            – Mahmoud Ben Hassine
            Nov 15 at 10:33
















          What if i run two or more such jobs at the same time? I guess i’ll have to use locking ob the table, which might affect performance. What about storing data in job context? Is it possible via ItemProcessor interface? I need to have more than one processor btw
          – Leonid Bor
          Nov 13 at 21:22




          What if i run two or more such jobs at the same time? I guess i’ll have to use locking ob the table, which might affect performance. What about storing data in job context? Is it possible via ItemProcessor interface? I need to have more than one processor btw
          – Leonid Bor
          Nov 13 at 21:22












          no need for locking, you can have a staging table per job instance, or a discriminator column to distinguish between records. Storing data in job context is not recommended if the data is big enough because the execution context end up serialized and persisted in the database.
          – Mahmoud Ben Hassine
          Nov 13 at 22:57






          no need for locking, you can have a staging table per job instance, or a discriminator column to distinguish between records. Storing data in job context is not recommended if the data is big enough because the execution context end up serialized and persisted in the database.
          – Mahmoud Ben Hassine
          Nov 13 at 22:57














          You mean the context is persisted after the job is done?
          – Leonid Bor
          Nov 15 at 10:29




          You mean the context is persisted after the job is done?
          – Leonid Bor
          Nov 15 at 10:29












          no, the step execution context is persisted after each chunk, whereas the job execution context is persisted after each step. Please refer to last paragraph of this section: docs.spring.io/spring-batch/4.1.x/reference/html/….
          – Mahmoud Ben Hassine
          Nov 15 at 10:33




          no, the step execution context is persisted after each chunk, whereas the job execution context is persisted after each step. Please refer to last paragraph of this section: docs.spring.io/spring-batch/4.1.x/reference/html/….
          – Mahmoud Ben Hassine
          Nov 15 at 10:33


















          draft saved

          draft discarded




















































          Thanks for contributing an answer to Stack Overflow!


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.





          Some of your past answers have not been well-received, and you're in danger of being blocked from answering.


          Please pay close attention to the following guidance:


          • Please be sure to answer the question. Provide details and share your research!

          But avoid



          • Asking for help, clarification, or responding to other answers.

          • Making statements based on opinion; back them up with references or personal experience.


          To learn more, see our tips on writing great answers.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53248654%2fintermediate-result-storage-for-spring-batch-processing-rest-service%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown





















































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown

































          Required, but never shown














          Required, but never shown












          Required, but never shown







          Required, but never shown







          Popular posts from this blog

          Full-time equivalent

          さくらももこ

          13 indicted, 8 arrested in Calif. drug cartel investigation