Spring AMQP RPC consumer and throw exception












1














I have a consumer (RabbitListner) in RPC mode and I would like to know if it is possible to throw exception that can be treated by the publisher.



To make more clear my explication the case is as follow :




  • The publisher send a message in RPC mode

  • The consumer receive the message, check the validity of the message and if the message can not be take in count, because of missing parameters, then I would like to throw Exception. The exception can be a specific business exception or a particular AmqpException but I want that the publisher can handle this exception if it is not go in timeout.


I try with the AmqpRejectAndDontRequeueException, but my publisher do not receive the exception, but just a response which is empty.



Is it possible to be done or may be it is not a good practice to implement like that ?



EDIT 1 :



After the @GaryRussel response here is the resolution of my question:





  1. For the RabbitListner I create an error handler :



     @Configuration
    public class RabbitErrorHandler implements RabbitListenerErrorHandler {
    @Override public Object handleError(Message message, org.springframework.messaging.Message<?> message1, ListenerExecutionFailedException e) {
    throw e;
    }


    }




  2. Define the bean into a configuration file :



    @Configuration
    public class RabbitConfig extends RabbitConfiguration {



    @Bean
    public RabbitTemplate getRabbitTemplate() {
    Message.addWhiteListPatterns(RabbitConstants.CLASSES_TO_SEND_OVER_RABBITMQ);
    return new RabbitTemplate(this.connectionFactory());


    }



    /**
    * Define the RabbitErrorHandle
    * @return Initialize RabbitErrorHandle bean
    */
    @Bean
    public RabbitErrorHandler rabbitErrorHandler() {
    return new RabbitErrorHandler();
    }
    }



  3. Create the @RabbitListner with parameters where rabbitErrorHandler is the bean that I defined previously :



    @Override
    @RabbitListener(queues = "${rabbit.queue}"
    , errorHandler = "rabbitErrorHandler"
    , returnExceptions = "true")
    public ReturnObject receiveMessage(Message message) {



  4. For the RabbitTemplate I set this attribute :



       rabbitTemplate.setMessageConverter(new RemoteInvocationAwareMessageConverterAdapter());



When the messsage threated by the consumer, but it sent an error, I obtain a RemoteInvocationResult which contains the original exception into e.getCause().getCause().










share|improve this question





























    1














    I have a consumer (RabbitListner) in RPC mode and I would like to know if it is possible to throw exception that can be treated by the publisher.



    To make more clear my explication the case is as follow :




    • The publisher send a message in RPC mode

    • The consumer receive the message, check the validity of the message and if the message can not be take in count, because of missing parameters, then I would like to throw Exception. The exception can be a specific business exception or a particular AmqpException but I want that the publisher can handle this exception if it is not go in timeout.


    I try with the AmqpRejectAndDontRequeueException, but my publisher do not receive the exception, but just a response which is empty.



    Is it possible to be done or may be it is not a good practice to implement like that ?



    EDIT 1 :



    After the @GaryRussel response here is the resolution of my question:





    1. For the RabbitListner I create an error handler :



       @Configuration
      public class RabbitErrorHandler implements RabbitListenerErrorHandler {
      @Override public Object handleError(Message message, org.springframework.messaging.Message<?> message1, ListenerExecutionFailedException e) {
      throw e;
      }


      }




    2. Define the bean into a configuration file :



      @Configuration
      public class RabbitConfig extends RabbitConfiguration {



      @Bean
      public RabbitTemplate getRabbitTemplate() {
      Message.addWhiteListPatterns(RabbitConstants.CLASSES_TO_SEND_OVER_RABBITMQ);
      return new RabbitTemplate(this.connectionFactory());


      }



      /**
      * Define the RabbitErrorHandle
      * @return Initialize RabbitErrorHandle bean
      */
      @Bean
      public RabbitErrorHandler rabbitErrorHandler() {
      return new RabbitErrorHandler();
      }
      }



    3. Create the @RabbitListner with parameters where rabbitErrorHandler is the bean that I defined previously :



      @Override
      @RabbitListener(queues = "${rabbit.queue}"
      , errorHandler = "rabbitErrorHandler"
      , returnExceptions = "true")
      public ReturnObject receiveMessage(Message message) {



    4. For the RabbitTemplate I set this attribute :



         rabbitTemplate.setMessageConverter(new RemoteInvocationAwareMessageConverterAdapter());



    When the messsage threated by the consumer, but it sent an error, I obtain a RemoteInvocationResult which contains the original exception into e.getCause().getCause().










    share|improve this question



























      1












      1








      1







      I have a consumer (RabbitListner) in RPC mode and I would like to know if it is possible to throw exception that can be treated by the publisher.



      To make more clear my explication the case is as follow :




      • The publisher send a message in RPC mode

      • The consumer receive the message, check the validity of the message and if the message can not be take in count, because of missing parameters, then I would like to throw Exception. The exception can be a specific business exception or a particular AmqpException but I want that the publisher can handle this exception if it is not go in timeout.


      I try with the AmqpRejectAndDontRequeueException, but my publisher do not receive the exception, but just a response which is empty.



      Is it possible to be done or may be it is not a good practice to implement like that ?



      EDIT 1 :



      After the @GaryRussel response here is the resolution of my question:





      1. For the RabbitListner I create an error handler :



         @Configuration
        public class RabbitErrorHandler implements RabbitListenerErrorHandler {
        @Override public Object handleError(Message message, org.springframework.messaging.Message<?> message1, ListenerExecutionFailedException e) {
        throw e;
        }


        }




      2. Define the bean into a configuration file :



        @Configuration
        public class RabbitConfig extends RabbitConfiguration {



        @Bean
        public RabbitTemplate getRabbitTemplate() {
        Message.addWhiteListPatterns(RabbitConstants.CLASSES_TO_SEND_OVER_RABBITMQ);
        return new RabbitTemplate(this.connectionFactory());


        }



        /**
        * Define the RabbitErrorHandle
        * @return Initialize RabbitErrorHandle bean
        */
        @Bean
        public RabbitErrorHandler rabbitErrorHandler() {
        return new RabbitErrorHandler();
        }
        }



      3. Create the @RabbitListner with parameters where rabbitErrorHandler is the bean that I defined previously :



        @Override
        @RabbitListener(queues = "${rabbit.queue}"
        , errorHandler = "rabbitErrorHandler"
        , returnExceptions = "true")
        public ReturnObject receiveMessage(Message message) {



      4. For the RabbitTemplate I set this attribute :



           rabbitTemplate.setMessageConverter(new RemoteInvocationAwareMessageConverterAdapter());



      When the messsage threated by the consumer, but it sent an error, I obtain a RemoteInvocationResult which contains the original exception into e.getCause().getCause().










      share|improve this question















      I have a consumer (RabbitListner) in RPC mode and I would like to know if it is possible to throw exception that can be treated by the publisher.



      To make more clear my explication the case is as follow :




      • The publisher send a message in RPC mode

      • The consumer receive the message, check the validity of the message and if the message can not be take in count, because of missing parameters, then I would like to throw Exception. The exception can be a specific business exception or a particular AmqpException but I want that the publisher can handle this exception if it is not go in timeout.


      I try with the AmqpRejectAndDontRequeueException, but my publisher do not receive the exception, but just a response which is empty.



      Is it possible to be done or may be it is not a good practice to implement like that ?



      EDIT 1 :



      After the @GaryRussel response here is the resolution of my question:





      1. For the RabbitListner I create an error handler :



         @Configuration
        public class RabbitErrorHandler implements RabbitListenerErrorHandler {
        @Override public Object handleError(Message message, org.springframework.messaging.Message<?> message1, ListenerExecutionFailedException e) {
        throw e;
        }


        }




      2. Define the bean into a configuration file :



        @Configuration
        public class RabbitConfig extends RabbitConfiguration {



        @Bean
        public RabbitTemplate getRabbitTemplate() {
        Message.addWhiteListPatterns(RabbitConstants.CLASSES_TO_SEND_OVER_RABBITMQ);
        return new RabbitTemplate(this.connectionFactory());


        }



        /**
        * Define the RabbitErrorHandle
        * @return Initialize RabbitErrorHandle bean
        */
        @Bean
        public RabbitErrorHandler rabbitErrorHandler() {
        return new RabbitErrorHandler();
        }
        }



      3. Create the @RabbitListner with parameters where rabbitErrorHandler is the bean that I defined previously :



        @Override
        @RabbitListener(queues = "${rabbit.queue}"
        , errorHandler = "rabbitErrorHandler"
        , returnExceptions = "true")
        public ReturnObject receiveMessage(Message message) {



      4. For the RabbitTemplate I set this attribute :



           rabbitTemplate.setMessageConverter(new RemoteInvocationAwareMessageConverterAdapter());



      When the messsage threated by the consumer, but it sent an error, I obtain a RemoteInvocationResult which contains the original exception into e.getCause().getCause().







      exception rabbitmq spring-amqp






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Nov 15 '18 at 17:07







      Sofia

















      asked Nov 13 '18 at 10:26









      SofiaSofia

      124




      124
























          2 Answers
          2






          active

          oldest

          votes


















          1














          See the returnExceptions property on @RabbitListener (since 2.0). Docs here.




          The returnExceptions attribute, when "true" will cause exceptions to be returned to the sender. The exception is wrapped in a RemoteInvocationResult object.



          On the sender side, there is an available RemoteInvocationAwareMessageConverterAdapter which, if configured into the RabbitTemplate, will re-throw the server-side exception, wrapped in an AmqpRemoteException. The stack trace of the server exception will be synthesized by merging the server and client stack traces.



          Important



          This mechanism will generally only work with the default SimpleMessageConverter, which uses Java serialization; exceptions are generally not "Jackson-friendly" so can’t be serialized to JSON. If you are using JSON, consider using an errorHandler to return some other Jackson-friendly Error object when an exception is thrown.







          share|improve this answer





















          • Thank you for this answer. Thanks also for the discussion with theMayer. Finally I decide to make like you propose by using the error handler. Initialy I had been done like theMayer propose, but it is more secure to have exceptions and in cases when I do not catch everyting the handler will assure to not lost the exception. May be I will put some of my code in my question, because I found that it is not very easy (I am new into Spring AMQP) so I take a time to find a way to do, and maybe it is not the right one. Thanks
            – Sofia
            Nov 15 '18 at 16:50










          • Hi, now I understand what you means with your phrase for the exceptions that are not Jackson-friendly. Before I used the rabbit template with the SimpleMessageConverter, that serialize my java object, but now I would like to use it as JSON. So if I want to use the Jackson converter I can do juste new RemoteInvocationAwareMessageConverterAdapter(new Jackson2JsonMessageConverter()). Can you give me some insights how to do ?
            – Sofia
            Dec 13 '18 at 15:15










          • No, it's not that simple; as I stated above; you will need changes on the server side to catch the exception and return some special error object; you will then have to interpret that error object on the client side to throw it as an exception.
            – Gary Russell
            Dec 13 '18 at 15:48










          • Thank you. I have implemented your suggestion. I create a custom object returned in error cases from my RabbitErrorHandler.
            – Sofia
            Dec 14 '18 at 16:01



















          0














          You have to return a message as an error, which the consuming application can choose to treat as an exception. However, I don't think normal exception handling flows apply with messaging. Your publishing application (the consumer of the RPC service) needs to know what can go wrong and be programmed to deal with those possibilities.






          share|improve this answer





















          • If you use java serialization, you can configure exceptions to be propagated to the client, where they can be re-thrown there. See my answer.
            – Gary Russell
            Nov 13 '18 at 14:13










          • @GaryRussell - that's a pretty good answer. I still think "exceptions" are reserved for code that doesn't work correctly as opposed to service failures, the boundaries of which are often much better defined and should be programmed to deal with all off-nominal conditions as a matter of first-class code.
            – theMayer
            Nov 13 '18 at 16:15










          • This was added at the request of the community, but I agree that it would be better to set up some protocol to return a meaningful error to the sender, avoiding this tight coupling.
            – Gary Russell
            Nov 13 '18 at 16:21










          • Thank you for your reply. Finally I decide to do like @GaryRussell propose. Your answer is also interesent and show me that even like that it is not a bad practice.
            – Sofia
            Nov 15 '18 at 16:51













          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%2f53278894%2fspring-amqp-rpc-consumer-and-throw-exception%23new-answer', 'question_page');
          }
          );

          Post as a guest















          Required, but never shown

























          2 Answers
          2






          active

          oldest

          votes








          2 Answers
          2






          active

          oldest

          votes









          active

          oldest

          votes






          active

          oldest

          votes









          1














          See the returnExceptions property on @RabbitListener (since 2.0). Docs here.




          The returnExceptions attribute, when "true" will cause exceptions to be returned to the sender. The exception is wrapped in a RemoteInvocationResult object.



          On the sender side, there is an available RemoteInvocationAwareMessageConverterAdapter which, if configured into the RabbitTemplate, will re-throw the server-side exception, wrapped in an AmqpRemoteException. The stack trace of the server exception will be synthesized by merging the server and client stack traces.



          Important



          This mechanism will generally only work with the default SimpleMessageConverter, which uses Java serialization; exceptions are generally not "Jackson-friendly" so can’t be serialized to JSON. If you are using JSON, consider using an errorHandler to return some other Jackson-friendly Error object when an exception is thrown.







          share|improve this answer





















          • Thank you for this answer. Thanks also for the discussion with theMayer. Finally I decide to make like you propose by using the error handler. Initialy I had been done like theMayer propose, but it is more secure to have exceptions and in cases when I do not catch everyting the handler will assure to not lost the exception. May be I will put some of my code in my question, because I found that it is not very easy (I am new into Spring AMQP) so I take a time to find a way to do, and maybe it is not the right one. Thanks
            – Sofia
            Nov 15 '18 at 16:50










          • Hi, now I understand what you means with your phrase for the exceptions that are not Jackson-friendly. Before I used the rabbit template with the SimpleMessageConverter, that serialize my java object, but now I would like to use it as JSON. So if I want to use the Jackson converter I can do juste new RemoteInvocationAwareMessageConverterAdapter(new Jackson2JsonMessageConverter()). Can you give me some insights how to do ?
            – Sofia
            Dec 13 '18 at 15:15










          • No, it's not that simple; as I stated above; you will need changes on the server side to catch the exception and return some special error object; you will then have to interpret that error object on the client side to throw it as an exception.
            – Gary Russell
            Dec 13 '18 at 15:48










          • Thank you. I have implemented your suggestion. I create a custom object returned in error cases from my RabbitErrorHandler.
            – Sofia
            Dec 14 '18 at 16:01
















          1














          See the returnExceptions property on @RabbitListener (since 2.0). Docs here.




          The returnExceptions attribute, when "true" will cause exceptions to be returned to the sender. The exception is wrapped in a RemoteInvocationResult object.



          On the sender side, there is an available RemoteInvocationAwareMessageConverterAdapter which, if configured into the RabbitTemplate, will re-throw the server-side exception, wrapped in an AmqpRemoteException. The stack trace of the server exception will be synthesized by merging the server and client stack traces.



          Important



          This mechanism will generally only work with the default SimpleMessageConverter, which uses Java serialization; exceptions are generally not "Jackson-friendly" so can’t be serialized to JSON. If you are using JSON, consider using an errorHandler to return some other Jackson-friendly Error object when an exception is thrown.







          share|improve this answer





















          • Thank you for this answer. Thanks also for the discussion with theMayer. Finally I decide to make like you propose by using the error handler. Initialy I had been done like theMayer propose, but it is more secure to have exceptions and in cases when I do not catch everyting the handler will assure to not lost the exception. May be I will put some of my code in my question, because I found that it is not very easy (I am new into Spring AMQP) so I take a time to find a way to do, and maybe it is not the right one. Thanks
            – Sofia
            Nov 15 '18 at 16:50










          • Hi, now I understand what you means with your phrase for the exceptions that are not Jackson-friendly. Before I used the rabbit template with the SimpleMessageConverter, that serialize my java object, but now I would like to use it as JSON. So if I want to use the Jackson converter I can do juste new RemoteInvocationAwareMessageConverterAdapter(new Jackson2JsonMessageConverter()). Can you give me some insights how to do ?
            – Sofia
            Dec 13 '18 at 15:15










          • No, it's not that simple; as I stated above; you will need changes on the server side to catch the exception and return some special error object; you will then have to interpret that error object on the client side to throw it as an exception.
            – Gary Russell
            Dec 13 '18 at 15:48










          • Thank you. I have implemented your suggestion. I create a custom object returned in error cases from my RabbitErrorHandler.
            – Sofia
            Dec 14 '18 at 16:01














          1












          1








          1






          See the returnExceptions property on @RabbitListener (since 2.0). Docs here.




          The returnExceptions attribute, when "true" will cause exceptions to be returned to the sender. The exception is wrapped in a RemoteInvocationResult object.



          On the sender side, there is an available RemoteInvocationAwareMessageConverterAdapter which, if configured into the RabbitTemplate, will re-throw the server-side exception, wrapped in an AmqpRemoteException. The stack trace of the server exception will be synthesized by merging the server and client stack traces.



          Important



          This mechanism will generally only work with the default SimpleMessageConverter, which uses Java serialization; exceptions are generally not "Jackson-friendly" so can’t be serialized to JSON. If you are using JSON, consider using an errorHandler to return some other Jackson-friendly Error object when an exception is thrown.







          share|improve this answer












          See the returnExceptions property on @RabbitListener (since 2.0). Docs here.




          The returnExceptions attribute, when "true" will cause exceptions to be returned to the sender. The exception is wrapped in a RemoteInvocationResult object.



          On the sender side, there is an available RemoteInvocationAwareMessageConverterAdapter which, if configured into the RabbitTemplate, will re-throw the server-side exception, wrapped in an AmqpRemoteException. The stack trace of the server exception will be synthesized by merging the server and client stack traces.



          Important



          This mechanism will generally only work with the default SimpleMessageConverter, which uses Java serialization; exceptions are generally not "Jackson-friendly" so can’t be serialized to JSON. If you are using JSON, consider using an errorHandler to return some other Jackson-friendly Error object when an exception is thrown.








          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 13 '18 at 14:12









          Gary RussellGary Russell

          79.4k74471




          79.4k74471












          • Thank you for this answer. Thanks also for the discussion with theMayer. Finally I decide to make like you propose by using the error handler. Initialy I had been done like theMayer propose, but it is more secure to have exceptions and in cases when I do not catch everyting the handler will assure to not lost the exception. May be I will put some of my code in my question, because I found that it is not very easy (I am new into Spring AMQP) so I take a time to find a way to do, and maybe it is not the right one. Thanks
            – Sofia
            Nov 15 '18 at 16:50










          • Hi, now I understand what you means with your phrase for the exceptions that are not Jackson-friendly. Before I used the rabbit template with the SimpleMessageConverter, that serialize my java object, but now I would like to use it as JSON. So if I want to use the Jackson converter I can do juste new RemoteInvocationAwareMessageConverterAdapter(new Jackson2JsonMessageConverter()). Can you give me some insights how to do ?
            – Sofia
            Dec 13 '18 at 15:15










          • No, it's not that simple; as I stated above; you will need changes on the server side to catch the exception and return some special error object; you will then have to interpret that error object on the client side to throw it as an exception.
            – Gary Russell
            Dec 13 '18 at 15:48










          • Thank you. I have implemented your suggestion. I create a custom object returned in error cases from my RabbitErrorHandler.
            – Sofia
            Dec 14 '18 at 16:01


















          • Thank you for this answer. Thanks also for the discussion with theMayer. Finally I decide to make like you propose by using the error handler. Initialy I had been done like theMayer propose, but it is more secure to have exceptions and in cases when I do not catch everyting the handler will assure to not lost the exception. May be I will put some of my code in my question, because I found that it is not very easy (I am new into Spring AMQP) so I take a time to find a way to do, and maybe it is not the right one. Thanks
            – Sofia
            Nov 15 '18 at 16:50










          • Hi, now I understand what you means with your phrase for the exceptions that are not Jackson-friendly. Before I used the rabbit template with the SimpleMessageConverter, that serialize my java object, but now I would like to use it as JSON. So if I want to use the Jackson converter I can do juste new RemoteInvocationAwareMessageConverterAdapter(new Jackson2JsonMessageConverter()). Can you give me some insights how to do ?
            – Sofia
            Dec 13 '18 at 15:15










          • No, it's not that simple; as I stated above; you will need changes on the server side to catch the exception and return some special error object; you will then have to interpret that error object on the client side to throw it as an exception.
            – Gary Russell
            Dec 13 '18 at 15:48










          • Thank you. I have implemented your suggestion. I create a custom object returned in error cases from my RabbitErrorHandler.
            – Sofia
            Dec 14 '18 at 16:01
















          Thank you for this answer. Thanks also for the discussion with theMayer. Finally I decide to make like you propose by using the error handler. Initialy I had been done like theMayer propose, but it is more secure to have exceptions and in cases when I do not catch everyting the handler will assure to not lost the exception. May be I will put some of my code in my question, because I found that it is not very easy (I am new into Spring AMQP) so I take a time to find a way to do, and maybe it is not the right one. Thanks
          – Sofia
          Nov 15 '18 at 16:50




          Thank you for this answer. Thanks also for the discussion with theMayer. Finally I decide to make like you propose by using the error handler. Initialy I had been done like theMayer propose, but it is more secure to have exceptions and in cases when I do not catch everyting the handler will assure to not lost the exception. May be I will put some of my code in my question, because I found that it is not very easy (I am new into Spring AMQP) so I take a time to find a way to do, and maybe it is not the right one. Thanks
          – Sofia
          Nov 15 '18 at 16:50












          Hi, now I understand what you means with your phrase for the exceptions that are not Jackson-friendly. Before I used the rabbit template with the SimpleMessageConverter, that serialize my java object, but now I would like to use it as JSON. So if I want to use the Jackson converter I can do juste new RemoteInvocationAwareMessageConverterAdapter(new Jackson2JsonMessageConverter()). Can you give me some insights how to do ?
          – Sofia
          Dec 13 '18 at 15:15




          Hi, now I understand what you means with your phrase for the exceptions that are not Jackson-friendly. Before I used the rabbit template with the SimpleMessageConverter, that serialize my java object, but now I would like to use it as JSON. So if I want to use the Jackson converter I can do juste new RemoteInvocationAwareMessageConverterAdapter(new Jackson2JsonMessageConverter()). Can you give me some insights how to do ?
          – Sofia
          Dec 13 '18 at 15:15












          No, it's not that simple; as I stated above; you will need changes on the server side to catch the exception and return some special error object; you will then have to interpret that error object on the client side to throw it as an exception.
          – Gary Russell
          Dec 13 '18 at 15:48




          No, it's not that simple; as I stated above; you will need changes on the server side to catch the exception and return some special error object; you will then have to interpret that error object on the client side to throw it as an exception.
          – Gary Russell
          Dec 13 '18 at 15:48












          Thank you. I have implemented your suggestion. I create a custom object returned in error cases from my RabbitErrorHandler.
          – Sofia
          Dec 14 '18 at 16:01




          Thank you. I have implemented your suggestion. I create a custom object returned in error cases from my RabbitErrorHandler.
          – Sofia
          Dec 14 '18 at 16:01













          0














          You have to return a message as an error, which the consuming application can choose to treat as an exception. However, I don't think normal exception handling flows apply with messaging. Your publishing application (the consumer of the RPC service) needs to know what can go wrong and be programmed to deal with those possibilities.






          share|improve this answer





















          • If you use java serialization, you can configure exceptions to be propagated to the client, where they can be re-thrown there. See my answer.
            – Gary Russell
            Nov 13 '18 at 14:13










          • @GaryRussell - that's a pretty good answer. I still think "exceptions" are reserved for code that doesn't work correctly as opposed to service failures, the boundaries of which are often much better defined and should be programmed to deal with all off-nominal conditions as a matter of first-class code.
            – theMayer
            Nov 13 '18 at 16:15










          • This was added at the request of the community, but I agree that it would be better to set up some protocol to return a meaningful error to the sender, avoiding this tight coupling.
            – Gary Russell
            Nov 13 '18 at 16:21










          • Thank you for your reply. Finally I decide to do like @GaryRussell propose. Your answer is also interesent and show me that even like that it is not a bad practice.
            – Sofia
            Nov 15 '18 at 16:51


















          0














          You have to return a message as an error, which the consuming application can choose to treat as an exception. However, I don't think normal exception handling flows apply with messaging. Your publishing application (the consumer of the RPC service) needs to know what can go wrong and be programmed to deal with those possibilities.






          share|improve this answer





















          • If you use java serialization, you can configure exceptions to be propagated to the client, where they can be re-thrown there. See my answer.
            – Gary Russell
            Nov 13 '18 at 14:13










          • @GaryRussell - that's a pretty good answer. I still think "exceptions" are reserved for code that doesn't work correctly as opposed to service failures, the boundaries of which are often much better defined and should be programmed to deal with all off-nominal conditions as a matter of first-class code.
            – theMayer
            Nov 13 '18 at 16:15










          • This was added at the request of the community, but I agree that it would be better to set up some protocol to return a meaningful error to the sender, avoiding this tight coupling.
            – Gary Russell
            Nov 13 '18 at 16:21










          • Thank you for your reply. Finally I decide to do like @GaryRussell propose. Your answer is also interesent and show me that even like that it is not a bad practice.
            – Sofia
            Nov 15 '18 at 16:51
















          0












          0








          0






          You have to return a message as an error, which the consuming application can choose to treat as an exception. However, I don't think normal exception handling flows apply with messaging. Your publishing application (the consumer of the RPC service) needs to know what can go wrong and be programmed to deal with those possibilities.






          share|improve this answer












          You have to return a message as an error, which the consuming application can choose to treat as an exception. However, I don't think normal exception handling flows apply with messaging. Your publishing application (the consumer of the RPC service) needs to know what can go wrong and be programmed to deal with those possibilities.







          share|improve this answer












          share|improve this answer



          share|improve this answer










          answered Nov 13 '18 at 13:29









          theMayertheMayer

          7,93833049




          7,93833049












          • If you use java serialization, you can configure exceptions to be propagated to the client, where they can be re-thrown there. See my answer.
            – Gary Russell
            Nov 13 '18 at 14:13










          • @GaryRussell - that's a pretty good answer. I still think "exceptions" are reserved for code that doesn't work correctly as opposed to service failures, the boundaries of which are often much better defined and should be programmed to deal with all off-nominal conditions as a matter of first-class code.
            – theMayer
            Nov 13 '18 at 16:15










          • This was added at the request of the community, but I agree that it would be better to set up some protocol to return a meaningful error to the sender, avoiding this tight coupling.
            – Gary Russell
            Nov 13 '18 at 16:21










          • Thank you for your reply. Finally I decide to do like @GaryRussell propose. Your answer is also interesent and show me that even like that it is not a bad practice.
            – Sofia
            Nov 15 '18 at 16:51




















          • If you use java serialization, you can configure exceptions to be propagated to the client, where they can be re-thrown there. See my answer.
            – Gary Russell
            Nov 13 '18 at 14:13










          • @GaryRussell - that's a pretty good answer. I still think "exceptions" are reserved for code that doesn't work correctly as opposed to service failures, the boundaries of which are often much better defined and should be programmed to deal with all off-nominal conditions as a matter of first-class code.
            – theMayer
            Nov 13 '18 at 16:15










          • This was added at the request of the community, but I agree that it would be better to set up some protocol to return a meaningful error to the sender, avoiding this tight coupling.
            – Gary Russell
            Nov 13 '18 at 16:21










          • Thank you for your reply. Finally I decide to do like @GaryRussell propose. Your answer is also interesent and show me that even like that it is not a bad practice.
            – Sofia
            Nov 15 '18 at 16:51


















          If you use java serialization, you can configure exceptions to be propagated to the client, where they can be re-thrown there. See my answer.
          – Gary Russell
          Nov 13 '18 at 14:13




          If you use java serialization, you can configure exceptions to be propagated to the client, where they can be re-thrown there. See my answer.
          – Gary Russell
          Nov 13 '18 at 14:13












          @GaryRussell - that's a pretty good answer. I still think "exceptions" are reserved for code that doesn't work correctly as opposed to service failures, the boundaries of which are often much better defined and should be programmed to deal with all off-nominal conditions as a matter of first-class code.
          – theMayer
          Nov 13 '18 at 16:15




          @GaryRussell - that's a pretty good answer. I still think "exceptions" are reserved for code that doesn't work correctly as opposed to service failures, the boundaries of which are often much better defined and should be programmed to deal with all off-nominal conditions as a matter of first-class code.
          – theMayer
          Nov 13 '18 at 16:15












          This was added at the request of the community, but I agree that it would be better to set up some protocol to return a meaningful error to the sender, avoiding this tight coupling.
          – Gary Russell
          Nov 13 '18 at 16:21




          This was added at the request of the community, but I agree that it would be better to set up some protocol to return a meaningful error to the sender, avoiding this tight coupling.
          – Gary Russell
          Nov 13 '18 at 16:21












          Thank you for your reply. Finally I decide to do like @GaryRussell propose. Your answer is also interesent and show me that even like that it is not a bad practice.
          – Sofia
          Nov 15 '18 at 16:51






          Thank you for your reply. Finally I decide to do like @GaryRussell propose. Your answer is also interesent and show me that even like that it is not a bad practice.
          – Sofia
          Nov 15 '18 at 16:51




















          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%2f53278894%2fspring-amqp-rpc-consumer-and-throw-exception%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

          Bressuire

          Vorschmack

          Quarantine