Acknowledeging a spring message












1















I have a spring integration application and I am using message driven channel adapter for consuming the messages. This is the definition of the adapter -



<jms:message-driven-channel-adapter id="messageAdapter" destination="inQueue"
connection-factory="connectionFactory"
error-channel="errorChannel"
concurrent-consumers="${consumer.concurrent-consumers}"
acknowledge="transacted"
transaction-manager="transactionManager"
channel="channel"
auto-startup="true"
receive-timeout="50000"/>


So this message goes to my core channel and then goes through a series of service activators. In between if there is a error than this message is moved to errorChannel where I handle the errors and decide on what needs to be done with this message. For one scenario I want the message to not rollback to the queue, is it possible? I am using 'transacted' in my adapter definition so I am not sure how to drive this behaviour. Any help is greatly appreciated!










share|improve this question





























    1















    I have a spring integration application and I am using message driven channel adapter for consuming the messages. This is the definition of the adapter -



    <jms:message-driven-channel-adapter id="messageAdapter" destination="inQueue"
    connection-factory="connectionFactory"
    error-channel="errorChannel"
    concurrent-consumers="${consumer.concurrent-consumers}"
    acknowledge="transacted"
    transaction-manager="transactionManager"
    channel="channel"
    auto-startup="true"
    receive-timeout="50000"/>


    So this message goes to my core channel and then goes through a series of service activators. In between if there is a error than this message is moved to errorChannel where I handle the errors and decide on what needs to be done with this message. For one scenario I want the message to not rollback to the queue, is it possible? I am using 'transacted' in my adapter definition so I am not sure how to drive this behaviour. Any help is greatly appreciated!










    share|improve this question



























      1












      1








      1








      I have a spring integration application and I am using message driven channel adapter for consuming the messages. This is the definition of the adapter -



      <jms:message-driven-channel-adapter id="messageAdapter" destination="inQueue"
      connection-factory="connectionFactory"
      error-channel="errorChannel"
      concurrent-consumers="${consumer.concurrent-consumers}"
      acknowledge="transacted"
      transaction-manager="transactionManager"
      channel="channel"
      auto-startup="true"
      receive-timeout="50000"/>


      So this message goes to my core channel and then goes through a series of service activators. In between if there is a error than this message is moved to errorChannel where I handle the errors and decide on what needs to be done with this message. For one scenario I want the message to not rollback to the queue, is it possible? I am using 'transacted' in my adapter definition so I am not sure how to drive this behaviour. Any help is greatly appreciated!










      share|improve this question
















      I have a spring integration application and I am using message driven channel adapter for consuming the messages. This is the definition of the adapter -



      <jms:message-driven-channel-adapter id="messageAdapter" destination="inQueue"
      connection-factory="connectionFactory"
      error-channel="errorChannel"
      concurrent-consumers="${consumer.concurrent-consumers}"
      acknowledge="transacted"
      transaction-manager="transactionManager"
      channel="channel"
      auto-startup="true"
      receive-timeout="50000"/>


      So this message goes to my core channel and then goes through a series of service activators. In between if there is a error than this message is moved to errorChannel where I handle the errors and decide on what needs to be done with this message. For one scenario I want the message to not rollback to the queue, is it possible? I am using 'transacted' in my adapter definition so I am not sure how to drive this behaviour. Any help is greatly appreciated!







      spring-integration spring-jms






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 22 '18 at 23:57









      Gary Russell

      84.2k84976




      84.2k84976










      asked Nov 22 '18 at 16:38









      VaibsVaibs

      164




      164
























          1 Answer
          1






          active

          oldest

          votes


















          0














          You don't describe what the transactionManager bean is. If it's a JmsTransactionManager, remove it and the container will just use local transactions.



          Then, the transaction will only roll back if the flow on the error-channel throws an exception. If that error flow exits normally ("consuming" the error), the transaction will not roll back.



          If it's some other transaction manager (e.g. JDBC) then remove it and start the JDBC transaction later in the flow (i.e. don't synchronize the JMS and JDBC transactions; again using a local JMS transaction).






          share|improve this answer
























          • Thanks for the reply Gary. I am using JPATransaction manager, so I effectively want that if database transaction is not committed than rollback message to the queue. With above settings it is working fine and message is getting rolled back, but for certain scenario's I want the message to not rollback (business scenarios). So is there a way to stop certain message from getting rolled back? If I remove transaction manager than all messages will stop going getting rolled back, so I hope I have to keep it.

            – Vaibs
            Nov 23 '18 at 9:34











          • If you synchronize the two transactions, you can't roll back one but not the other; that's the whole point of synchronizing them. See the last paragraph in my answer; use a local transaction on the container and start the JPA transaction in your message flow (after the adapter, e.g. with a @Transactional gateway or with a transaction advice on the channel). Then, after an exception, when the error flow gets the error, whether or not the JMS commits or rolls back is only dependent on what the error flow does.

            – Gary Russell
            Nov 23 '18 at 13:59











          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',
          autoActivateHeartbeat: false,
          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%2f53435186%2facknowledeging-a-spring-message%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









          0














          You don't describe what the transactionManager bean is. If it's a JmsTransactionManager, remove it and the container will just use local transactions.



          Then, the transaction will only roll back if the flow on the error-channel throws an exception. If that error flow exits normally ("consuming" the error), the transaction will not roll back.



          If it's some other transaction manager (e.g. JDBC) then remove it and start the JDBC transaction later in the flow (i.e. don't synchronize the JMS and JDBC transactions; again using a local JMS transaction).






          share|improve this answer
























          • Thanks for the reply Gary. I am using JPATransaction manager, so I effectively want that if database transaction is not committed than rollback message to the queue. With above settings it is working fine and message is getting rolled back, but for certain scenario's I want the message to not rollback (business scenarios). So is there a way to stop certain message from getting rolled back? If I remove transaction manager than all messages will stop going getting rolled back, so I hope I have to keep it.

            – Vaibs
            Nov 23 '18 at 9:34











          • If you synchronize the two transactions, you can't roll back one but not the other; that's the whole point of synchronizing them. See the last paragraph in my answer; use a local transaction on the container and start the JPA transaction in your message flow (after the adapter, e.g. with a @Transactional gateway or with a transaction advice on the channel). Then, after an exception, when the error flow gets the error, whether or not the JMS commits or rolls back is only dependent on what the error flow does.

            – Gary Russell
            Nov 23 '18 at 13:59
















          0














          You don't describe what the transactionManager bean is. If it's a JmsTransactionManager, remove it and the container will just use local transactions.



          Then, the transaction will only roll back if the flow on the error-channel throws an exception. If that error flow exits normally ("consuming" the error), the transaction will not roll back.



          If it's some other transaction manager (e.g. JDBC) then remove it and start the JDBC transaction later in the flow (i.e. don't synchronize the JMS and JDBC transactions; again using a local JMS transaction).






          share|improve this answer
























          • Thanks for the reply Gary. I am using JPATransaction manager, so I effectively want that if database transaction is not committed than rollback message to the queue. With above settings it is working fine and message is getting rolled back, but for certain scenario's I want the message to not rollback (business scenarios). So is there a way to stop certain message from getting rolled back? If I remove transaction manager than all messages will stop going getting rolled back, so I hope I have to keep it.

            – Vaibs
            Nov 23 '18 at 9:34











          • If you synchronize the two transactions, you can't roll back one but not the other; that's the whole point of synchronizing them. See the last paragraph in my answer; use a local transaction on the container and start the JPA transaction in your message flow (after the adapter, e.g. with a @Transactional gateway or with a transaction advice on the channel). Then, after an exception, when the error flow gets the error, whether or not the JMS commits or rolls back is only dependent on what the error flow does.

            – Gary Russell
            Nov 23 '18 at 13:59














          0












          0








          0







          You don't describe what the transactionManager bean is. If it's a JmsTransactionManager, remove it and the container will just use local transactions.



          Then, the transaction will only roll back if the flow on the error-channel throws an exception. If that error flow exits normally ("consuming" the error), the transaction will not roll back.



          If it's some other transaction manager (e.g. JDBC) then remove it and start the JDBC transaction later in the flow (i.e. don't synchronize the JMS and JDBC transactions; again using a local JMS transaction).






          share|improve this answer













          You don't describe what the transactionManager bean is. If it's a JmsTransactionManager, remove it and the container will just use local transactions.



          Then, the transaction will only roll back if the flow on the error-channel throws an exception. If that error flow exits normally ("consuming" the error), the transaction will not roll back.



          If it's some other transaction manager (e.g. JDBC) then remove it and start the JDBC transaction later in the flow (i.e. don't synchronize the JMS and JDBC transactions; again using a local JMS transaction).







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 22 '18 at 23:56









          Gary RussellGary Russell

          84.2k84976




          84.2k84976













          • Thanks for the reply Gary. I am using JPATransaction manager, so I effectively want that if database transaction is not committed than rollback message to the queue. With above settings it is working fine and message is getting rolled back, but for certain scenario's I want the message to not rollback (business scenarios). So is there a way to stop certain message from getting rolled back? If I remove transaction manager than all messages will stop going getting rolled back, so I hope I have to keep it.

            – Vaibs
            Nov 23 '18 at 9:34











          • If you synchronize the two transactions, you can't roll back one but not the other; that's the whole point of synchronizing them. See the last paragraph in my answer; use a local transaction on the container and start the JPA transaction in your message flow (after the adapter, e.g. with a @Transactional gateway or with a transaction advice on the channel). Then, after an exception, when the error flow gets the error, whether or not the JMS commits or rolls back is only dependent on what the error flow does.

            – Gary Russell
            Nov 23 '18 at 13:59



















          • Thanks for the reply Gary. I am using JPATransaction manager, so I effectively want that if database transaction is not committed than rollback message to the queue. With above settings it is working fine and message is getting rolled back, but for certain scenario's I want the message to not rollback (business scenarios). So is there a way to stop certain message from getting rolled back? If I remove transaction manager than all messages will stop going getting rolled back, so I hope I have to keep it.

            – Vaibs
            Nov 23 '18 at 9:34











          • If you synchronize the two transactions, you can't roll back one but not the other; that's the whole point of synchronizing them. See the last paragraph in my answer; use a local transaction on the container and start the JPA transaction in your message flow (after the adapter, e.g. with a @Transactional gateway or with a transaction advice on the channel). Then, after an exception, when the error flow gets the error, whether or not the JMS commits or rolls back is only dependent on what the error flow does.

            – Gary Russell
            Nov 23 '18 at 13:59

















          Thanks for the reply Gary. I am using JPATransaction manager, so I effectively want that if database transaction is not committed than rollback message to the queue. With above settings it is working fine and message is getting rolled back, but for certain scenario's I want the message to not rollback (business scenarios). So is there a way to stop certain message from getting rolled back? If I remove transaction manager than all messages will stop going getting rolled back, so I hope I have to keep it.

          – Vaibs
          Nov 23 '18 at 9:34





          Thanks for the reply Gary. I am using JPATransaction manager, so I effectively want that if database transaction is not committed than rollback message to the queue. With above settings it is working fine and message is getting rolled back, but for certain scenario's I want the message to not rollback (business scenarios). So is there a way to stop certain message from getting rolled back? If I remove transaction manager than all messages will stop going getting rolled back, so I hope I have to keep it.

          – Vaibs
          Nov 23 '18 at 9:34













          If you synchronize the two transactions, you can't roll back one but not the other; that's the whole point of synchronizing them. See the last paragraph in my answer; use a local transaction on the container and start the JPA transaction in your message flow (after the adapter, e.g. with a @Transactional gateway or with a transaction advice on the channel). Then, after an exception, when the error flow gets the error, whether or not the JMS commits or rolls back is only dependent on what the error flow does.

          – Gary Russell
          Nov 23 '18 at 13:59





          If you synchronize the two transactions, you can't roll back one but not the other; that's the whole point of synchronizing them. See the last paragraph in my answer; use a local transaction on the container and start the JPA transaction in your message flow (after the adapter, e.g. with a @Transactional gateway or with a transaction advice on the channel). Then, after an exception, when the error flow gets the error, whether or not the JMS commits or rolls back is only dependent on what the error flow does.

          – Gary Russell
          Nov 23 '18 at 13:59




















          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.




          draft saved


          draft discarded














          StackExchange.ready(
          function () {
          StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53435186%2facknowledeging-a-spring-message%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







          這個網誌中的熱門文章

          Xamarin.form Move up view when keyboard appear

          Post-Redirect-Get with Spring WebFlux and Thymeleaf

          Anylogic : not able to use stopDelay()