Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @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());
- }
- }
Add Comment
Please, Sign In to add comment