Discovering RabbitMQ in PCF

Let's return to our application. The whole system is based on asynchronous communication over RabbitMQ. As we might have learned from Chapter 8Scaling Up with Cloud Streams, all we have to do to set up a connection with a local RabbitMQ instance is to provide two additional Spring Boot dependencies. Additionally, for the Cloud infrastructure, we have to add spring-cloud-spring-service-connector and spring-cloud-cloudfoundry-connector dependencies. Finally, we have to provide a configuration depicted in the following code snippet and additional @ScanCloud annotation:

@Configuration
@Profile("cloud")
public class CloudConfig extends AbstractCloudConfig {
  @Bean
  public ConnectionFactory rabbitMQConnectionFactory() {
    return connectionFactory().rabbitConnectionFactory();
  }
}

For better flexibility, we use the @Profile("cloud") annotation, which enables the RabbitMQ configuration only when running on the cloud, and not locally during development.

For RabbitMQ on a PCF case, it is not necessary to provide additional configurations since Cloud Foundry is highly tuned for a Spring ecosystem, so all required injections take place at runtime without extra hassle. However, it is essential to follow that practice (at least providing a @ScanCloud annotation) to be compatible with all cloud providers. In case of the deployed Application crashing, please check whether the RabbitMQ service provided by the PCF is bound to the application.
..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
13.59.227.82