Deploying to Pivotal Cloud Foundry

When talking about PaaS options of an application deployment, Spring Boot brings excellent support for the Google Cloud Platform (GCP), Heroku, and Pivotal Cloud Foundry (PCF). Here, we cover integration with PCF, but other options are treated similarly and with almost the same level of detail.

As the first step in setting up the releasing process with PCF, it is essential to understand how the Spring ecosystem helps in deploying an application onto the PaaS platform.

Suppose that we have a microservice streaming application that has three major parts:

  • A UI Service that provides a UI to users and additionally plays the role of a service gateway
  • A Storage Service that persists streaming data and transforms them into a user's view model so that a UI Service may handle it and multicast to each subscriber
  • A Connectors Service that is responsible for setting proper configurations between particular data sources and then transferring events from them to the storage service

All of these services interact with one another over a message queue that, in our example, is a RabbitMQ broker. Moreover, to persist received data, the application uses MongoDB as a flexible, partition tolerant and a fast data-storage provider.

To generalize, we have three deployable services that message each other over RabbitMQ, and one of them communicates with MongoDB. For a successful operation, all those services should be running. With IaaS and CaaS it would be our responsibility to deploy and support RabbitMQ and MongoDB. With PaaS, the cloud provider serves those services if required and reduces operational responsibilities even more.

To deploy service to the PCF, we have to install a Cloud Foundry CLI, package our service with mvn package, log in to PCF and run the following command:

cf push <reactive-app-name> -p target/app-0.0.1.jar

After a few seconds of the deployment process, the application should be available at http://<reactive-app-name>.cfapps.io. CPF recognizes Spring Boot applications and makes an educated guess about the most optimal configuration for the service, but of course, developers may define his/her preferences with the manifest.yml file.

To read more about deploying Java application to CPF, please read the following article: https://docs.cloudfoundry.org/buildpacks/java/java-tips.html.

It is neat that the platform takes care of the application startup and basic configuration. On the other hand, PaaS is highly opinionated about service discovery and network topology, so we can't deploy all services on the same server or configure the overall virtual network. Consequently, all external services could be located via a localhost URI. Such limitation leads to the fact that we lose configuration flexibility. Fortunately, modern PaaS providers expose platform information and the knowledge about add-ons or connected services to the deployed application. Therefore, all crucial data can be retrieved, and all necessary configurations can be done right after that. However, we still have to write clients or particular infrastructure code to integrate with a concrete PaaS provider's API. At that moment, Spring Cloud Connectors (https://cloud.spring.io/spring-cloud-connectors) came to the rescue:

Spring Cloud Connectors simplify the process of connecting to services and gaining operating environment awareness in cloud platforms such as Cloud Foundry and Heroku, especially for Spring applications.

Spring Cloud Connectors reduce dedicated boilerplate codes for interaction with Cloud platforms. Here, we do not outline details of service configuration since that information will be described on the official page of the project. Instead, we are going to achieve out of the box support for Reactive features within a Reactive Application deployed to PCF. We will also describe what is needed to run Reactive Spring Application inside a PaaS.

..................Content has been hidden....................

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