0

I use "spring-cloud-azure-stream-binder-eventhubs" for event hubs development. Now when I deal with consumers, there may be some business exceptions.

my config

    stream:
      function:
        definition: consumer
      bindings:
        consumer-in-0:
          destination: test-eventhub
          group: $Default
          consumer:
            max-attempts: 3
        supply-out-0:
          destination: test-eventhub

my consumer

@Bean
    public Consumer<Message<String>> consumer() {
        return message -> {
            if (message.equals("a")) {
                throw new RuntimeException("run time exception");
            }
        };

my global exception handler

    @ServiceActivator(inputChannel = "errorChannel")
    public void globalConsumerError(Message<?> message) {
        MessageHandlingException messageHandlingException = (MessageHandlingException) message.getPayload();
        log.info("message : {}", new String((byte[]) messageHandlingException.getFailedMessage().getPayload()));
        log.error("error info: {}", message);
        // do something
    }

I hope that if an exception occurs, it can start retrying by setting max-attempts. But it didn't work, please help me with my doubts, thanks

James
  • 1

1 Answers1

0

Now spring-cloud-azure-stream-binder-eventhubs doesn't support spring.cloud.stream.binding.xxx.consumer.max-attempts property. And event hub SDK doesn't support retry feature. Refs: https://github.com/Azure/azure-sdk-for-java/issues/18344.

Here is a workaround:

    @Bean
    public Consumer<Message<String>> consumer() {
        return message -> {
            for (int i = 0; i < 3; i ++) {
                // Your codes
            }
        };
    }
chenrujun
  • 126
  • 4