Microservices – A Lean Thinking Approach
Microservices – A Lean Thinking Approach
Microservices is often quoted as an architectural style for software development as a variant derived from the foundations of Service Oriented Architecture(SOA). However, the primary reason for embracing this approach is to encourage lean thinking in software development. The emphasis is on building a set of business capabilities that are self-contained, autonomous and loosely coupled. Another desirable aspect of this approach is to have independent and manageable lifecycles with enterprises embarking on choices related to DevOps and cloud. The important point to take note is that principles learned from Service Oriented Architecture (SOA) are still relevant with this approach regardless of size and scale of business operations.
Some of the principles to consider while designing microservices are “service granularity” and “loose coupling”. Service granularity defines the scope of the business functionality and structure of the message. Loose coupling defines the degree of independence practicable between two interconnecting components in Microservices architectural style. It’s important to address the following questions or concerns below to achieve service granularity:
- Does the application address a single business operation or fulfill multiple functions without adding design complexity?
- Any special skills required in development efforts?
- Are industry standards followed in building Microservices development?
Some of the standards and protocols to consider are discussed in the next section.
Although there is no agreed upon standard to enable a microservices approach, its desirable to use lightweight protocols like SOAP, REST or messaging protocols. While SOAP and REST rely primarily on HTTP/HTTPS as transport, messaging protocols could follow standards such as JMS and AMQP specifications. Other development patterns like Webhooks, Non-blocking callback or event driven approaches can blend in seamlessly with Microservices architectural style.
In this blog, I’m going to detail the steps for building an application using Apache Camel in Talend ESB studio and deploy it as a Microservice. The example showcases an order processing system where a batch of orders received in a file are split into individual orders and published to a queue. The consumer receives the orders and load balances them across multiple console outputs. The scenario chosen demonstrates the principles of service granularity and loose coupling very well in addition to showcasing the pattern commonly used in real-time transaction processing systems.
Talend’s ESB studio uses Spring boot features to export and deploy applications as independent and self-managed services. The services built can be deployed as independent jar files or Apache Karaf runtime engines by building Karaf Archive (kar) files.
- If you haven’t downloaded Talend ESB studio you can grab a trial of it here
- Have Active MQ installed or use the Included Active MQ in Talend ESB
- Disabled offline setting in Studio preferences as given under Maven as shown below. This will help in getting essential libraries to build if required from the internet. Enabling this feature would allow any dependencies to be resolved automatically while building solutions but for the example we won’t need it.
The first microservice to build is the order service. This microservice will listen to a JMS queue and load balance the messages in a round-robin fashion. After consuming messages off the queue, the service will display them on the log console. The first step is to create a route as described below in Figure 2 and name it “ConsumeAndProcess”.
We are going to be working with cMQConnectionFactory, cJMS, cLoadBalancer which are Talend components that we’ll use to interact with Message Brokers. As mentioned earlier, our plan is to log the messages received so we’ll use the cLog component for this process. When we finish this example our microservice will look similar to this:
The first thing we’ll need to do is Configure the cMQConnectionFactory component to use “ActiveMQ” as the broker and provide the Broker URI. After dropping the component on the canvas I’ll modify the settings in the component viewer. It should look like the following described in Figure 4.
Next we need to configure the JMS receiver component (cJMS) by setting the endpoint type as “queue” and queue name under “destination” as follows. Also, specify the ConnectionFactory to be the cMQConnectionFactory configured in the previous step. The details posted in Figure 5 below.
Once we’ve configured the cJMS component we need to add a cLoadBalancer. There are a number of load balancing strategies available within this component but for today’s example Round Robin will work perfectly.
To finish off this example we just need to add the cLog components to the canvas and configure the trace level.
By right clicking on the route that we created as shown below in Figure 8. We can start the build process.
Select the build option to “ESB Microservice (Spring Boot)” and click “Finish” to create jar file as given below here:
The jar file built can be deployed as an independent Microservice. The jar file can be executed as an independent self-contained service or Java process as shown below in Figure 10. The command to run the container is given below. You’ll notice the jar takes its name from the route name.
By default, the monitoring port is set as 8605. However, this can be overridden by using the example below:
java -jar AuditService_0.1.jar --server.port=50000
The Microservices can also be exported as zip files providing scripts like *.bat in Windows server environment and *.sh files in Linux/Unix environments to start the Microservice. The build option has been demonstrated in Figure 10 below.
Microservices rapidly enable build and deploy applications with faster feedback loops. The Microservices architecture style also enforces modularity lending it to continuous delivery practices which is ideal for business-driven development and cloud application architectures. Through this example we’ve demonstrated just how easy it is to build microservices using Talend’s ESB studio. If this is something you’re interested in exploring more or have any questions let me know!
Most Downloaded Resources
Browse our most popular resources - You can never just have one.