简体   繁体   中英

Ways to implement Google Pub Sub

I found these 3 ways for implementing messaging with Google Pub Sub:

  1. with client libraries https://cloud.google.com/pubsub/docs/publisher

  2. with spring integration message channels and PubSubTemplate API https://dzone.com/articles/spring-boot-and-gcp-cloud-pubsub

  3. without message channels but with PubSubTemplate API https://medium.com/bb-tutorials-and-thoughts/gcp-how-to-subscribe-and-send-pubsub-messages-in-spring-boot-app-b27e2e8863e3

I want to understand the differences between them / when each is best to use and which would be useful for my case.

I have to implement a single Topic and a single Subscription to get the queue functionality. I think I'd rather not use Spring message channels if not needed, they seem to intermediate the communication between Pub Sub topic and the subscription and I don't want that. I want things simple, so I think the option 3 would be best but I am also wondering about option 1.

Option 1, client libraries, is universal. You don't need Spring to run it, you can use this library in Groovy or in Kotlin also.

Option 2, it's deeply integrated to Spring. It's quite invisible but if you have special thing to do, it's tricky to override this implementation

Option 3, it's a light spring integration. PubSubTemplate (the client in fact) is loaded automatically for you at startup, as any bean and you can use it easily in your code. It's my preferred option when I use Spring.

Google Cloud Pub/Sub Using Client Libraries :

  • Using Google Cloud Pub/Sub with Client libraries is one of the standard and easiest way to implement Cloud Pub/Sub.
  • A producer of the data publishes messages to Pub/Sub topic, a subscriber client then creates a subscription to that topic and consumes messages.
  • You need to install the client libraries. You can follow this setup and tutorial for further information.
  • Here you won't require Spring integration, you can directly use the client library to publish messages and pull it from subscription.

Spring Integration using spring channels :

  • This use case involves intensive integration of Spring Boot Application with Google Cloud Pub/Sub using Spring Integration to send and receive Pub/Sub messages. ie. Pub/Sub acts as intermediate messaging system
  • Here The Spring Application sends messages to Cloud Pub/Sub topic utilizing spring channels and the Application further receives messages from Pub/Sub through these channels.

Pub/Sub message in Spring-Boot App :

  • This use case is a simple and valid example of integrating Cloud Pub/Sub with Spring boot application.
  • The use case demonstrates how to subscribe to a subscription and send message to topics using Spring Boot Application
  • Message is published to the topic, queued in the respective subscription and then received by the subscriber Spring Boot Application

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM