Guest User

Untitled

a guest
Dec 18th, 2018
249
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.99 KB | None | 0 0
  1. @Configuration
  2. public class HelloPubSubSubscriberConfig {
  3.  
  4. private static final Logger LOGGER = LoggerFactory.getLogger(HelloPubSubSubscriberConfig.class);
  5.  
  6. private final PubSubTemplate pubSubTemplate;
  7.  
  8. private final HelloPubSubConsumer helloPubSubConsumer;
  9.  
  10. @Autowired
  11. public HelloPubSubSubscriberConfig(PubSubTemplate pubSubTemplate, HelloPubSubConsumer helloPubSubConsumer) {
  12. this.pubSubTemplate = pubSubTemplate;
  13. this.helloPubSubConsumer = helloPubSubConsumer;
  14. }
  15.  
  16. /**
  17. * It's called only when the application is ready to receive requests.
  18. * Passes a consumer implementation when subscribing to a Pub/Sub topic.
  19. */
  20. @EventListener(ApplicationReadyEvent.class)
  21. public void subscribe() {
  22. LOGGER.info("Subscribing {} to {}", helloPubSubConsumer.getClass().getSimpleName(),
  23. helloPubSubConsumer.subscription());
  24. pubSubTemplate.subscribe(helloPubSubConsumer.subscription(), helloPubSubConsumer.consumer());
  25. }
  26.  
  27. }
Add Comment
Please, Sign In to add comment