Created
December 19, 2018 02:22
-
-
Save fmachado091/1832ce3ac664fe26401339898d178951 to your computer and use it in GitHub Desktop.
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 | |
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