Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save fmachado091/1832ce3ac664fe26401339898d178951 to your computer and use it in GitHub Desktop.
Save fmachado091/1832ce3ac664fe26401339898d178951 to your computer and use it in GitHub Desktop.
@Configuration
public class HelloPubSubSubscriberConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(HelloPubSubSubscriberConfig.class);
private final PubSubTemplate pubSubTemplate;
private final HelloPubSubConsumer helloPubSubConsumer;
@Autowired
public HelloPubSubSubscriberConfig(PubSubTemplate pubSubTemplate, HelloPubSubConsumer helloPubSubConsumer) {
this.pubSubTemplate = pubSubTemplate;
this.helloPubSubConsumer = helloPubSubConsumer;
}
/**
* It's called only when the application is ready to receive requests.
* Passes a consumer implementation when subscribing to a Pub/Sub topic.
*/
@EventListener(ApplicationReadyEvent.class)
public void subscribe() {
LOGGER.info("Subscribing {} to {}", helloPubSubConsumer.getClass().getSimpleName(),
helloPubSubConsumer.subscription());
pubSubTemplate.subscribe(helloPubSubConsumer.subscription(), helloPubSubConsumer.consumer());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment