A method that implements Google Pub Sub
I found these 3 ways to implement messaging using Google Pub Sub:
Use the client library
https://cloud.google.com/pubsub/docs/publisherUse the Spring Integration Message Channel and PubSubTemplate API
https://dzone.com/articles/spring-boot-and-gcp-cloud-pubsubThere is no message channel, but there is a PubSubTemplate API
https://medium.com/bb-tutorials-and-thoughts/gcp-how-to-subscribe-and-send-pubsub-messages-in-spring-boot-app-b27e2e8863e3
I would like to know the difference between them/when is the best time to use them and which ones are useful for my situation.
I have to implement a single topic and a single subscription to get the queue functionality. I think I’d rather not use the Spring Message channel if I don’t need to, they seem to act as communication middleware between the Pub Sub topic and the subscription, which I don’t want. I want something simple, so I think option 3 is best, but I also want to know option 1.
Solution
Google Cloud Pub/Sub Using Client Libraries :
- Using Google Cloud Pub/Sub with the client library is one of the standard and easiest ways to implement Cloud Pub/Sub.
- The producer of the data publishes the message to a Pub/Sub topic, and then the subscriber client creates a subscription to the topic and consumes the message.
- You need to install the client library. You can follow this setup and tutorial for more information.
- Spring integration is not required here, you can directly use the client library to publish messages and subscribe to pulls.
Spring Integration using spring channels :
- This use case involves using Spring Integration to intensively integrate Spring Boot applications with Google Cloud Pub/Sub to send and receive Pub/Sub messages. IE。 Pub/Sub acts as an intermediate messaging system
- Here the Spring application uses spring channels to send messages to Cloud Pub/Sub topics, 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 effective example of integrating Cloud Pub/Sub with a Spring boot application.
- The use case demonstrates how to subscribe to a subscription and send messages to a topic using a Spring Boot application
- Messages are published to a topic, queued in the appropriate subscription, and then received by the subscriber Spring Boot application