News & Events

How to Create Production-Ready Microservices with Spring Boot and Cloud Foundry

Published on January 6, 2020

Solace makes it easy to implement production-ready microservices using Spring Boot and Cloud Foundry.

Write Once, Run Anywhere (WORA) was a slogan coined by Sun Microsystems to illustrate the cross-platform benefits of Java.

While in many cases Java lived up to this promise, today we need to Write Once, Deploy/Scale Anywhere.

How to Create Production-Ready Microservices with Spring Boot and Cloud Foundry

The bane of many developers (including myself) is the inability to inject operating environment properties into applications. This problem becomes even more pronounced when trying to develop production-ready microservices in the most agile way possible.

Why? Simply put, there are external dependencies (such as messaging) whose information can only be known at runtime.

Imagine creating a simple Spring Boot application that runs on your laptop. This application receives product information from a JMS Queue, does an inventory query and republishes the data to a JMS Topic. Everything works fine so it's time to integrate it into your Cloud Foundry development environment and let it live in the broader enterprise ecosystem.

I'll explain by way of example. A few weeks ago I was developing some microservices. I had all the JMS connection properties in a configuration file (application.xml) but needed them to be dynamically injected at runtime by Cloud Foundry (VCAP_Services). Since I was using Solace as my message broker, I was able to use Solace's Spring Cloud Connectors to look up these values in runtime.

Perfect right? Not quite.

Later that week, I was flying to a customer engagement and the airplane WiFi was so slow I couldn't use Cloud Foundry. I needed to make progress on my Spring Boot application, so I turned back to my laptop development sandbox which did not have Cloud Foundry... 30 minutes of code modifications later, I was back to using the Solace Spring Boot Starters and able to develop again, but faced a nasty conundrum:

Do I write my application to use properties files or Cloud Foundry?

This deployment dependency revelation had shattered my Write Once, Deploy Anywhere dreams.

All I wanted was to fall back to using a properties file if I was not deployed to Cloud Foundry... and of course not have these time-wasting code changes ever again!

The Solace development team took this feedback and made my dreams come true!

Our Spring Boot Starters now have support for not just properties files, but also Spring Cloud Connectors. Essentially, we check for the existence of VCAP_Services and if it does not exist we fall back to looking for a properties file which defines our URI, Username, Password, etc.

If it does exist, we take advantage of Spring Cloud Connectors to look up these values out of VCAP_Services. All of this is done under the covers in our solace-jms-spring-boot-autoconfigure (or solace-java-boot-autoconfigure if using our jcsmp API).

Pretty slick since it realizes the dream of Write Once, Deploy/Scale Anywhere!

The other key benefit the solace-jms-spring-boot-autoconfigure option provides is the ability to seamlessly integrate into Spring's JMS framework so that you can focus on writing business value (not JMS boilerplate).

All you have to do is have the requisite Spring (spring-jms) and Solace (solace-jms-spring-boot-autoconfigure) libraries in your classpath and use the @Autowired annotation for a JmsTemplate for sending messages or @JmsListener annotation for receiving.

How to Create Production-Ready Microservices with Spring Boot and Cloud Foundry

These new capabilities in our Spring Boot autoconfigure implementation are key to our upcoming support for Spring Cloud Streams.

Stay tuned for that announcement and know that Solace has your back if you're a developer working to create production-ready microservices!

Author: Jonathan Schabowsky

Source: Solace

PT Strategic Partner Solution

  The Bellezza Shopping Arcade
    2nd Floor Unit SA15-16
    Jl. Arteri Permata Hijau, Kec. Kby. Lama
    DKI Jakarta 12210
  +62 812 8700 0879



  Jl. Jend. Sudirman No. 757
    Bandung 40212
(62-22) 603 0590 (Hunting)
(62-22) 603 0967


  Kawasan Industri Medan Star
    Jl. Pelita Raya I Blok F No. 5
    Tanjung Morawa Km 19,2
    Deli Serdang 20362
  (62-61) 7940800
  (62-61) 7941990


  Jl. Tambak Aji I / 6
    Komp. Industri Guna Mekar
    Semarang 50185
  (62-24) 866 3521
  (62-24) 866 3529


  Jl. Ngemplak No. 30
    Komplek Ambengan Plaza
    Blok B 35-37
    Surabaya 60272
  (62-31) 531 9635 (Hunting)
  (62-31) 531 9634


  Perumahan Gunung Madu Plantation
    Jalan Pulau Morotai Blok B No. 1
    Kecamatan Sukarame - Tanjung Baru
    Bandar Lampung


  Jalan Melati No. 2,
    Kelurahan Purwosari
    Laweyan, Surakarta


  Komplek Ilir Barat Permai
    Blok D.I. No. 31
    Kelurahan 24 Ilir, Palembang


  Jalan Ir. Sutami, Pergudangan Tahap II
    Blok S No.3B
    Karang Asam, Samarinda


  Jalan Ir. Sutami,
    Komplek Pergudangan Parangloe Indah
    Blok C-II 3/6, Makassar


  Jalan Raya Wajok Hilir Km. 15,65
    Siantan, Pontianak