2

According to the docs here the currently supported binders (Rabbit and Kafka) rely on RetryTemplate. And for the GCP?

Detail of my project

Spring Boot Version 2.1.3.RELEASE

Dependency pom.xml

<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-gcp-starter-pubsub</artifactId>
    <version>1.1.0.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework.cloud</groupId>
    <artifactId>spring-cloud-gcp-pubsub-stream-binder</artifactId>
    <version>1.1.0.RELEASE</version>
</dependency>

application.properties

spring.cloud.stream.bindings.input.destination=inputtopic
spring.cloud.stream.bindings.output.destination=outputtopic

spring.cloud.gcp.project-id=testinggcp
spring.cloud.gcp.credentials.location=file:C:/Users/my_gcp_credentials.json

RestController

@EnableBinding({Source.class,Sink.class})
@RestController
public class SourceExample {

    @Autowired
    private Source source;


    @GetMapping("/newMessage")
    public UserMessage sendMessage(@RequestParam("messageBody") String messageBody,
                                   @RequestParam("username") String username) {
        UserMessage userMessage = new UserMessage(messageBody, username, LocalDateTime.now());

        this.source.output().send(new GenericMessage<>(userMessage));
        return userMessage;
    }


    @StreamListener(target = Sink.INPUT)
    public void handle(UserMessage userMessage) throws IOException {
        System.out.println(userMessage);
    }


}
Panup Pong
  • 1,871
  • 2
  • 22
  • 44

1 Answers1

1

No, Spring Cloud GCP Pub/Sub Binder doesn't provide any retry hooks.

It is easy to use a RequestHandlerRetryAdvice on the @ServiceActivator instead of @StreamListener. So, all your failures in the POJO method are going to be retried according your configuration. The RequestHandlerRetryAdvice has a RecoveryCallback options which could be just simple ErrorMessageSendingRecoverer where you can configure some error processing and send wrong message to some Dead Letter Topic on GCP Pub/Sub.

See more info in the Reference Manual: https://docs.spring.io/spring-integration/docs/current/reference/html/#retry-advice

And a bit bellow about Advising Endpoints Using Annotations.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • I'm really confused the ServiceActivator doesn't work. AFAIK GCP has pubSubAcknowledgementExecutor if exception thrown it automatically recall handle function (Sink.INPUT). That mean it is not necessary for the implementation of Re-queue Failed Messages? – Panup Pong Mar 06 '19 at 04:38
  • 1
    Well, in that case I think so. The ack is automatic if message has been delivered to the listener. – Artem Bilan Mar 06 '19 at 20:09
  • And how to retry a message when producer throw exception at this line this.source.output() – Panup Pong Mar 07 '19 at 07:07