Springing into Real-Time: Crafting a Lightstreamer Remote Adapter with Spring Boot

Spring Boot is an ideal framework for building stand-alone applications that implement remote adapters for Lightstreamer. There are several compelling reasons for choosing Spring Boot in this context:

1. Simplicity and Speed: Spring Boot simplifies the development process by providing a wide range of pre-configured templates, which significantly speeds up application setup and deployment. This is crucial when implementing adapters for real-time data streaming services like Lightstreamer.

2. Integration Capabilities: Spring Boot offers a powerful and easy-to-use way to integrate with various technologies and protocols. When building remote adapters for Lightstreamer, it’s essential to seamlessly connect to different data sources, and Spring Boot excels in this regard.

3. Dependency Management: Spring Boot simplifies dependency management through its built-in dependency injection system. This is valuable when dealing with the complexities of remote data integration, as it streamlines the handling of external libraries and components.

4. Configuration Management: Spring Boot provides a highly flexible configuration system that allows you to externalize configuration properties. This feature is essential when configuring various adapter endpoints and handling dynamic changes in adapter behavior.

5. Auto-Configuration: Spring Boot’s auto-configuration feature automatically sets up the application based on its dependencies. When developing Lightstreamer adapters, this functionality simplifies the initialization process, reducing the need for manual configuration.

6. Testing and Debugging: Spring Boot offers excellent support for testing and debugging, helping you ensure the reliability and performance of your Lightstreamer adapters.

7. Scalability: Spring Boot is designed with scalability in mind. As your application grows and the demand for real-time data increases, Spring Boot’s architecture allows for easy horizontal scaling, ensuring your Lightstreamer adapters can handle more connections.

8. Community and Ecosystem: Spring Boot boasts a vibrant community and a rich ecosystem of libraries, plugins, and tools. This provides access to a wealth of resources for solving problems and optimizing your Lightstreamer adapters.

In summary, Spring Boot simplifies the development of stand-alone applications that implement remote adapters for Lightstreamer by offering a wealth of features, from simplified configuration and integration capabilities to robust testing and scalability options.

Leveraging the power of Spring Boot can streamline your development process and ensure that your Lightstreamer adapters are efficient, reliable, and easy to maintain.

Moving the in-process chat demo adapter into a Spring Boot stand-alone application

We have revamped one of our most historical and popular demonstrations: the ‘Basic Chat’ demo. This demo includes an adapter implementation using the Java In-Process interface, running in the same JVM as the Lightstreamer kernel. To expand its accessibility, we’ve opted to present a remote version by creating a standalone application using Spring Boot.

The Lightstreamer – Basic Chat Demo serves as a straightforward chat application, relying on Lightstreamer for real-time communication. The client part of the demo uses the web application ‘Basic Chat Demo – Web Client‘ and required no substantial changes.

Instead, in this application, adapters are implemented using Java Remote interfaces, and a utility class facilitates connections to the Lightstreamer server for Metadata and Data adapters. Conversely, the server part relies on previously developed Java adapters in in-process mode, specifically ‘Basic Chat Demo – Java Adapter‘. The Java code from this project, handling metadata and data adapters, has been repurposed for a standalone application context.

The ‘Spring Boot’ adapters project comprises the following Java source files:

  • ChatAdapterSpringbootApplication.java: Implements the ApplicationRunner interface of the Spring framework. The @Value annotation interprets input parameters for configuring the adapters.
  • ServerStarter.java: A utility class facilitating the instantiation and launch of data and metadata adapters. It also manages TCP connections with the Lightstreamer server.
  • ChatDataAdapter.java: Contains the source code for the Chat Data Adapter, which accepts message submissions for a unique chat room. The sender is identified by an IP address and a nickname. Additionally, chat history can be flushed based on an optional parameter.
  • ChatMetaDataAdapter.java: Contains the source code for the metadata adapter, inheriting from the reusable LiteralBasedProvider. It adds simple support for message submissions but is not recommended as a reference for client-originated message handling due to the absence of guaranteed delivery and clustering support.

The code of the ChatMetadataAdapter and ChatDataAdapter classes is adapted from the in-process adapter project, with only minimal changes. The metadata class had a minor alteration to replace the logging implementation, with no substantial impact on the application perspective.

For the data adapter, a more significant change was necessary. It involved replacing SmartDataProvider, unavailable for remote APIs, with the DataProvider interface. This transition required using the specific item name instead of the handle object used in the SmartDataProvider interface. Changes include adjustments to the subscribe and unsubscribe method signatures, as well as invocations of the update and clearSnapshot methods of the ItemEventListener interface.

Build and run the demo

If you want to build and run a version of this demo with your local Lightstreamer Server, follow these steps (the project requires Apache Maven installed on your system):

  1. Download Lightstreamer Server (Lightstreamer Server comes with a free non-expiring demo license for 20 connected users) from Lightstreamer Download page, and install it, as explained in the GETTING_STARTED.TXT file in the installation home directory.
  2. Create a folder called RemoteChat in the LS_HOME/adapters folder.
  3. Create a file named adapters.xml in the RemoteChat folder, with the contents from the section above.
  4. Launch Lightstreamer Server. The Server startup will complete only after a successful connection between the Proxy Data Adapter and the Remote Data Adapter.
  5. In a terminal window, with the working directory set to the chat-adapter-springboot folder of the GitHub project, run the following command: 
./mvnw spring-boot:run "-Dspring-boot.run.arguments=--server.name=chat-spring
  1. Wait the connections with the Lightsreamer server, and then test the Adapter, launching the Lightstreamer – Basic Chat Demo – HTML Client
  2. To make the front-end pages get data from the newly installed Adapter Set, you need to modify the front-end pages and set the required Adapter Set name to PROXY_NODECHAT when creating the LightstreamerClient instance. So edit the lsClient.js file of the Basic Chat Demo front-end deployed under Lightstreamer/pages/ChatDemo and replace: 
var lsClient = new LightstreamerClient(protocolToUse+"//localhost:"+portToUse,"CHAT");

with: 

var lsClient = new LightstreamerClient(protocolToUse+"//localhost:"+portToUse,"CHAT_REMOTE");

(you don’t need to reconfigure the Data Adapter name, as it is the same in both Adapter Sets).

  1.  Open a browser window and go to: http://localhost:8080/ChatDemo

To recap:

August 8, 2024
Originally published: December 21, 2023


4 min read

Table of Contents