This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
b.c.q.s.c.HelloPubSubController : received a POST at /hello/publish with message=[Hello, Pub/Sub] | |
b.c.q.s.publishers.PubSubPublisher : publishing to topic [hello-pubsub], message: [Hello, Pub/Sub] | |
b.c.q.s.s.consumers.HelloPubSubConsumer : message received: Hello, Pub/Sub |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RestController | |
@RequestMapping("/hello") | |
public class HelloPubSubController { | |
private static final Logger LOGGER = LoggerFactory.getLogger(HelloPubSubController.class); | |
private final HelloPubSubPublisher publisher; | |
@Autowired | |
public HelloPubSubController(HelloPubSubPublisher publisher) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
public class HelloPubSubPublisher extends PubSubPublisher { | |
@Autowired | |
public HelloPubSubPublisher(PubSubTemplate pubSubTemplate) { | |
super(pubSubTemplate); | |
} | |
@Override | |
protected String topic() { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class PubSubPublisher { | |
private static final Logger LOGGER = LoggerFactory.getLogger(PubSubPublisher.class); | |
private final PubSubTemplate pubSubTemplate; | |
protected PubSubPublisher(PubSubTemplate pubSubTemplate) { | |
this.pubSubTemplate = pubSubTemplate; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# list pub/sub topics (in case you don't remeber the your topic's name) | |
$ gcloud pubsub topics list | |
# setting up topic (just for readability purposes) | |
$ PUBSUB_TOPIC=projects/hello-spring-cloud-gcp/topics/hello-pubsub | |
# publish to topic | |
$ gcloud pubsub topics publish ${PUBSUB_TOPIC}\ | |
--message "Hello, Pub/Sub" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
s.SpringCloudGcpPubSubExampleApplication : Started SpringCloudGcpPubSubExampleApplication in 2.824 seconds (JVM running for 3.432) | |
b.c.q.s.c.HelloPubSubSubscriberConfig : Subscribing HelloPubSubConsumer to hello-pubsub-subscription |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Configuration | |
public class HelloPubSubSubscriberConfig { | |
private static final Logger LOGGER = LoggerFactory.getLogger(HelloPubSubSubscriberConfig.class); | |
private final PubSubTemplate pubSubTemplate; | |
private final HelloPubSubConsumer helloPubSubConsumer; | |
@Autowired |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@Component | |
public class HelloPubSubConsumer extends PubSubConsumer { | |
private static final Logger LOGGER = LoggerFactory.getLogger(HelloPubSubConsumer.class); | |
@Override | |
public String subscription() { | |
return "hello-pubsub-subscription"; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public abstract class PubSubConsumer { | |
/** | |
* Name of an existing Pub/Sub subscription. | |
*/ | |
public abstract String subscription(); | |
/** | |
* The actual consumer logic. | |
* |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* Send a message to Pub/Sub. | |
*/ | |
public <T> ListenableFuture<String> publish(String topic, T payload); | |
/** | |
* Add a callback method to an existing subscription. | |
*/ | |
public Subscriber subscribe(String subscription, Consumer<BasicAcknowledgeablePubsubMessage> messageConsumer); |
NewerOlder