1

Want to keep Spring boot pubsub stream application running without Web server (tomcat).

Application works great with Tomcat(spring-boot-starter-web) but If I remove web support it is not keep listing to but shutdown.

@SpringBootApplication
...

@Bean
public Consumer<String> consume() {
    return message -> {
            System.out.println("Received message " + message);
    };
}

// If I remove/comment Supplier this app will shutdown without listing to consume
public Supplier<String> publish() {
    return () -> {
        String message = "FromBean";
        System.out.println("Sending value: " + message);
        return message;
    };
}




spring:
  cloud:
    stream:
      function:
        definition: consume;publish
      bindings:
        publish-out-0:
          destination: my-topic
          group: myGroup1
        consume-in-0:
          destination: my-topic
          group: myGroup1
    gcp:
      pubsub:
        emulator-host: localhost:8511
        project-id: local-pubsub-emulator
      project-id: local-pubsub-emulator

POM.XML

<properties>
    <java.version>18</java.version>
    <spring.boot>2.7.1</java.version>
    <spring-cloud-gcp.version>3.3.0</spring-cloud-gcp.version>
    <spring-cloud.version>2021.0.3</spring-cloud.version>
    <testcontainers.version>1.17.2</testcontainers.version>
</properties>
        <dependency>
            <groupId>com.google.cloud</groupId>
            <artifactId>spring-cloud-gcp-pubsub-stream-binder</artifactId>
            <version>3.3.0</version>
        </dependency>

        <dependency>
            <groupId>com.google.protobuf</groupId>
            <artifactId>protobuf-java</artifactId>
            <version>3.21.2</version>
        </dependency>
Ravi Parekh
  • 5,253
  • 9
  • 46
  • 58
  • It should work. Without seeing more info, hard to tell what's going on. Try the property `spring.cloud.function.definition` and see if that makes a difference. – sobychacko Jul 05 '22 at 14:42
  • @sobychacko, I've updated with adequate code, App will listen on if I add, starter-web & @ Schedued, else only consumer is not working. Complete pom.xml - > https://justpaste.it/1sqe2 – Ravi Parekh Jul 06 '22 at 13:36
  • Oh, I didn't realize that you are using the GCP pubsub binder. You might want to tag that team (`spring-cloud-gcp`). – sobychacko Jul 06 '22 at 21:24
  • https://github.com/GoogleCloudPlatform/spring-cloud-gcp/issues/1182 – Ravi Parekh Jul 13 '22 at 14:09

0 Answers0