Service Activator Design Pattern
Start course
3h 59m

In this course, we will learn the concepts of microservice and spring framework with a focus on design patterns.

Learning Objectives

  • Learn about various design patterns

Intended Audience

  • Beginner Java developers
  • Java developers interested in learning how to Build and Deploy RESTful Web Services
  • Java Developers who want to develop web applications using the Spring framework
  • Java Developers who want to develop web applications with microservices
  • Java Developers who wish to develop Spring Boot Microservices with Spring Cloud


  • Basic Java knowledge

Hello, dear friends. In this video, we will examine the Service Activator Pattern. So, let's begin. Before we begin, I'd like to make it clear that we cannot provide examples for all of these patterns. For instance, the Service Activator Pattern requires a large structure, which will be difficult to demonstrate in this course. So, as a result, I will only provide examples of patterns that can be implemented with small projects. Okay, so let's get going. In enterprise applications, a majority of the processing is done in a synchronous manner. A client invokes a business service and waits until the business service returns from processing. However, the business processing in some use cases takes considerable time and resources. The business processing might even span applications, possibly integrating with applications inside and outside the enterprise.

For these long-lived processes, it is not feasible for application clients to wait until the business processing completes. So, in this case, we want to invoke services asynchronously. Some long-running use cases take a long time. Instead of blocking the users, we can run these asynchronously. JMS is a good example of Service Activator Pattern. JMS, as Java Message Service, is an API that provides this facility to create, send, and read messages. It provides loosely coupled, reliable, and asynchronous communication. Okay, let's examine the UML of Service Activator. The Client is any client in the application that needs to invoke a business service in an asynchronous manner. The Client can be any type of application component, such as a POJO or an EJB component that can create and send JMS messages. The Request is the message object created by the Client and sent to the ServiceActivator using the Message-Oriented Middleware.

According to the JMS specification, the request object must implement the javax.jms.Message interface. The JMS API provides several message types, such as text message, object message, and so on. That can be used as request objects depending on what type of message you want to send. The ServiceActivator is the main class of the pattern. It implements the javax.jms.MessageListener interface, which is defined by the JMS specification. The ServiceActivator implements an on-message method that is invoked when a new message arrives. The ServiceActivator parses the message to determine what needs to be done. The ServiceActivator might use a service locator to look up or create business service components.

The business service is the target object that the Client asks to do asynchronous processing. The response is a message object created and sent either by the Service Activator or a business service. The response can be an acknowledgement to let the Client know that the request was received. The response can also be the result of asynchronous processing. Okay, I believe that covers the Service Activator Pattern in JMS. In the next video, we will look into the DAO pattern. See you in the next video.


About the Author
Learning Paths

OAK Academy is made up of tech experts who have been in the sector for years and years and are deeply rooted in the tech world. They specialize in critical areas like cybersecurity, coding, IT, game development, app monetization, and mobile development.