


- #SPRING BOOT MICROSERVICES DOCKER AND KUBERNETES WORKSHOP HOW TO#
- #SPRING BOOT MICROSERVICES DOCKER AND KUBERNETES WORKSHOP CODE#
In fact, the following short class encapsulate the logic used to interact with the queue: With those two components, you can publish messages to a queue (ActiveMQ) using a familiar interface (JMS) and use the same interface to receive messages.Īnd even better, Spring Boot has excellent integration with JMS so you can get up to speed in no time. The most popular message broker that you can consume with JMS is ActiveMQ - an open source messaging server. If you used the JDBC API in the past, you should find the JMS API familiar since it works similarly. Spring JMS (Java Message Service) is a powerful mechanism to send and receive messages using standard protocols.
#SPRING BOOT MICROSERVICES DOCKER AND KUBERNETES WORKSHOP HOW TO#
Writing Spring Boot applications is easy.Ī more interesting subject is learning how to connect Spring Boot to a message broker. If you inspect the logs, you should see the worker processing items. You can run the application and, as long as you have an ActiveMQ instance running locally, you should be able to buy items and having those processed by the system. Dry-run the applicationīy default, the application starts as a frontend and worker. You can configure the application in either mode, by changing the values in your application.yaml. Please note that in the sample project the processing is simulated by waiting for five seconds with a Thread.sleep(5000). The application can function in two modes:Īs frontend, the application renders the web page where people can buy items.Īs a worker, the application waits for messages in the queue and processes them. a /metrics endpoint to expose the number of pending messages in the queue (more on this later).a /submit endpoint that receives submissions from the form and creates messages in the queue.a /health endpoint to signal when the application is ready to receive traffic.an admin panel where you can inspect the number of messages in the queue.
#SPRING BOOT MICROSERVICES DOCKER AND KUBERNETES WORKSHOP CODE#
There's a single code base, and you can configure the project to run either as the front-end or backend. Please note that the application is written in Java 10 to leverage the improved Docker container integration. You can find a sample project with a front-end and backend application connected to JMS at learnk8s/spring-boot-k8s-hpa.

The backend is a worker consuming messages from a queue.Īnd since Spring Boot has excellent integration with JMS, you could use that to send and receive asynchronous messages. The front-end is a simple Spring Boot web app with the Thymeleaf templating engine. The service has three components: the front-end, the backend and a message broker. How do you design a service that can handle hundreds of thousands of requests?Īnd how do you deploy an application that scales dynamically?īefore diving into the details of deployment and scaling, let's focus on the application. Great, but how do you build such application? you could have hundreds of front-end services and a single instance of the backend you can scale the backend independently of the front-end - i.e.if the front-end is producing more messages than what the backend can handle, those messages are buffered in the queue.if the backend is unavailable, the queue acts as a buffer.The new architecture has some obvious benefits: The front-end posts messages to the queue, while the backend processes the pending messages one at a time.
