Search code examples
javagoogle-cloud-platformgoogle-cloud-pubsub

Different java client libraries for Google's PubSub and PubSub Lite needed?


I used the client lib for connecting PubSub so far:

<dependency>
  <groupId>com.google.cloud</groupId>
  <artifactId>google-cloud-pubsub</artifactId>
</dependency>

Now if I have to use PubSub Lite instead the question is if I have to switch to another client lib, like

<dependency>
  <groupId>com.google.cloud</groupId>
  <artifactId>google-cloud-pubsublite</artifactId>
</dependency>

Is that necessary or is there some compatibility?


Solution

  • Both PubSub and PubSub Lite can be called using the Java Client library with few changes in dependencies. PubSub has a broader range of features then PubSub Lite but both are scalable and managed messaging services. The difference while using PubSub and PubSub Lite is that while using PubSub Lite you need to add both PubSub and PubSub Lite artifacts in dependency in the pom.xml file which is mentioned below.

    PubSub

    <dependencyManagement>
      <dependencies>
        <dependency>
          <groupId>com.google.cloud</groupId>
          <artifactId>libraries-bom</artifactId>
          <version>26.1.5</version>
          <type>pom</type>
          <scope>import</scope>
        </dependency>
      </dependencies>
    </dependencyManagement>
     
    <dependencies>
      <dependency>
        <groupId>com.google.cloud</groupId>
        <artifactId>google-cloud-pubsub</artifactId>
      </dependency>
     
    </dependencies>
    

    PubSub Lite

    <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>google-cloud-pubsublite</artifactId>
      <version>1.9.1</version>
    </dependency>
    <dependency>
      <groupId>com.google.cloud</groupId>
      <artifactId>google-cloud-pubsub</artifactId>
      <version>1.122.1</version>
    </dependency>
    

    For more information you can check the Java Client Library for PubSub and PubSub Lite.