How to Run Real-Time SDK Java Application with Maven

Introduction

Apache Maven is a De facto project management and comprehension tool for Java Developers. Maven (and other build automation tools such as Gradle) helps Java developers to build ava application, manage project dependencies (Java Developers do not need to manual manage different versions of jar files anymore), simplify Build and Packaging process, and better collaboration in the team.

This article shows how to setup the Real-Time applications project with with Maven using Refinitiv Real-Time SDK as an example library.

Maven Project

What is Refinitiv Real-Time SDK?

The Refinitiv Real-Time SDK Family (RTSDK C++ and Java Editions, formerly known as Elektron SDK) is a suite of modern and open APIs that aim to simplify development through a strong focus on ease of use and standardized access to a broad set of Refinitiv and proprietary content and services via the proprietary TCP connection named RSSL and proprietary binary message encoding format named OMM Message. The capabilities range from low latency/high performance APIs right through to simple streaming Web APIs.

This SDK is also available on GitHub with instructions to build the libraries.

RTSDK Diagram

The Real-Time SDK stack contains a set of capabilities ranging from low level ‘Transport’ interfaces to very high-level content aware stateful interfaces. The SDK consists of two following APIs

  1. Enterprise Transport API (ETA): Formerly known as UPA, or Ultra Performance API. The ETA API is the open source, high performance, low latency, foundation of the Refinitiv Real-Time SDK. This API provides the highest level of performance, scalability, tune-ability, low memory utilization, and low CPU utilization.
  2. Enterprise Message API (EMA): Formerly known as Elektron Message API, this API is a data-neutral, multi-threaded, ease-of-use API providing access to Refinitiv Real-Time data. As part of the Real-Time SDK, the Enterprise Message API allows applications to consume and provide OMM data at the message level of the API stack.

You can find more detail regarding the EMA Java from the following resources

RTSDK Java with Maven

The Refinitiv Real-Time SDK Java is now available in Maven Central Repository for both EMA and ETA APIs.

EMA Java Dependencies
ETA Java Dependencies

Note:

  • This article is based on EMA Java version 3.6.1 L1 (RTSDK Java Edition 2.0.1 L1).

Maven Standard Directory Layout

By default, the Maven project uses the following directory layout to standardize the folder structure.

  • src/main/java: Application/Library sources
  • src/main/resources: Application/Library resources
  • src/test/java: Test sources
  • src/test/resources: Test resources
  • LICENSE.txt: Project’s license
  • README.txt: Project’s readme
  • pom.xml: Project’s Maven configuration file.

The example of the Maven standard directory layout is available in the RTSDK Java default folder layout (the Maven directly layout is mostly identical to Gradle layout).

RTSDK Java Folder layout

Please see the full directories layout description on Introduction to the Standard Directory Layout page.

Maven POM file

Maven POM or “Project Object Model” is the XML pom.xml file represents Maven project configuration file. It contains all information about a project such as the project's dependencies, as well as configurations of plugins used by Maven to build the project.

<?xml version="1.0" encoding="UTF-8"?><project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">        <modelVersion>4.0.0</modelVersion>  
<groupId>com.refinitiv.ema</groupId
<artifactId>RTSDKJ_Maven</artifactId>
<version>1.0</version>
...
</project>

The brief information of each POM file elements are the following:

  • project: The top-level element in all Maven pom.xml files.
  • groupId: This element indicates the unique identifier of the organization or group that created the project.
  • artifactId: This element indicates the unique base name of the primary artifact being generated by this project.
  • version: This element indicates the version of the artifact generated by the project.

Please see more detail about pom.xml file on the following Maven resources for a full explanation of the POM essentials elements:

Maven pom.xml setting for EMA Java

You can specify the following EMA Java application dependencies in the Maven pom.xml file. The EMA Java is the message-level API built on top of the ETA Java (Transport API), the Maven can automatic pull all dependency artifacts within Maven central for the application.

Please notice that I use the Maven variables <rtsdk.version>3.6.1.0</rtsdk.version> to set the library version in a single place in the pom.xml file.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion>...<properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target><rtsdk.version>3.6.1.0</rtsdk.version></properties><dependencies><!-- RTSDK -->
<!-- For EMA Java Project -->
<dependency><groupId>com.refinitiv.ema</groupId><artifactId>ema</artifactId><version>${rtsdk.version}</version></dependency></dependencies></project>

Maven pom.xml setting for ETA Java

The pom.xml file for the ETA Java application is the following. The Maven can automatic pull ETA, ETA ValueAdd and ETA JSON Converter artifacts within Maven central for the application with the com.refinitiv.eta.valueadd.cache dependency declaration.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion>...<properties><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding><maven.compiler.source>1.8</maven.compiler.source><maven.compiler.target>1.8</maven.compiler.target><rtsdk.version>3.6.1.0</rtsdk.version></properties><dependencies><!-- RTSDK -->
<!-- For ETA Java Project -->
<dependency><groupId>com.refinitiv.eta.ansi</groupId><artifactId>ansipage</artifactId><version>${rtsdk.version}</version></dependency><dependency><groupId>com.refinitiv.eta.valueadd.cache</groupId><artifactId>etaValueAddCache</artifactId><version>${rtsdk.version}</version></dependency></dependencies></project>

Building the project

You can run the Maven mvn package command to compile all applications in the Maven project and build the applications jar file. The class and jar files will be available in the target folder by default.

compile mvn package command

However, this newly built jar file contains only the application class files, so you need to set the Java classpath to all required RTSDK jar files which store somewhere in your Maven repository folder to run this jar file. To avoid this problem, you can use the Maven Assembly Plugin to build the project and RTSDK library into a single-all-dependencies jar file in the project’s target folder.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion>...<build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-assembly-plugin</artifactId><executions><execution><phase>package</phase><goals><goal>single</goal></goals><configuration><archive><manifest><mainClass>com.refinitiv.ema.consumer.Consumer</mainClass></manifest></archive><descriptorRefs><descriptorRef>jar-with-dependencies</descriptorRef></descriptorRefs></configuration></execution></executions></plugin></plugins></build></project>

Once you run the Maven mvn package command, Maven will build a single-all-dependencies jar file named RTSDKJ_Maven-1.0-jar-with-dependencies.jar in the target folder.

compile mvn package command

Please check Running Maven Tools page for more detail about other useful Maven commands.

Demo prerequisite

This example requires the following dependencies software and libraries.

  1. Oracle/Open JDK 8 or Oracle JDK 11.
  2. Apache Maven project management and comprehension tool.
  3. Internet connection.

Note: The RTSDK Java version 2.0.1 L1 (EMA Java 3.6.1) supports Oracle JDK versions 8, 11, and Open JDK version 8. If you are using other versions of RTSDK Java, please check the SDK’s README.md file regarding the supported Java version.

Running the demo applications

If your environment does not have the Maven installed, please follow the Maven installation guide page for more detail. The demo applications project is available on Set Up Refinitiv Real-Time SDK Java Application with Maven GitHub repository. Please unzip or download the example application into a directory of your choosing.

The example applications diagram is the following:

Connection Diagram

Running IProvider and Consumer applications

Firstly, open the project folder in the command prompt and then run the IProvider example with the following command

java -cp .;target/RTSDKJ_Maven-1.0-jar-with-dependencies.jar com.refinitiv.ema.provider.IProvider

Then, open another command prompt to the project folder and run the following command to start the Consumer example (we can use just java -jar command directly as the main class is com.refinitiv.ema.consumer.Consumer)

java -jar ./target/RTSDKJ_Maven-1.0-jar-with-dependencies.jar

IProvider and Consumer applications result

# IProvider example result
Mar 26, 2021 11:55:01 AM com.refinitiv.ema.access.ServerChannelHandler reactorChannelEventCallback
INFO: loggerMsg
ClientName: ServerChannelHandler
Severity: Info
Text: Received ChannelUp event on ClientHandle 1
Instance Name Provider_1_1
Component Version ETA Java Edition|EMA Java Edition
loggerMsgEnd
# Consumer example result
Mar 26, 2021 11:55:02 AM com.refinitiv.ema.access.ChannelCallbackClient reactorChannelEventCallback
INFO: loggerMsg
ClientName: ChannelCallbackClient
Severity: Info
Text: Received ChannelUp event on channel Channel_1
Instance Name Consumer_1_1
Component Version ETA Java Edition|EMA Java Edition
loggerMsgEnd
Item Name: IBM.N
Service Name: DIRECT_FEED
Item State: Open / Ok / None / 'Refresh Completed'
Fid: 3 Name = DSPLY_NAME DataType: Rmtes Value: IBM.N
Fid: 15 Name = CURRENCY DataType: Enum Value: USD
Fid: 21 Name = HST_CLOSE DataType: Real Value: 39.0
Fid: 22 Name = BID DataType: Real Value: 39.9
Fid: 25 Name = ASK DataType: Real Value: 39.94
Fid: 30 Name = BIDSIZE DataType: Real Value: 9.0
Fid: 31 Name = ASKSIZE DataType: Real Value: 19.0
Item Name: IBM.N
Service Name: DIRECT_FEED
Fid: 22 Name = BID DataType: Real Value: 39.91
Fid: 25 Name = ASK DataType: Real Value: 39.94
Fid: 30 Name = BIDSIZE DataType: Real Value: 10.0
Fid: 31 Name = ASKSIZE DataType: Real Value: 19.0
...

Maven setting for non-Maven Jar File

If the project requires the local jar file that not yet part of the public Maven repository, you can use Maven Install Plugin to install a JAR in the local Maven repository with the following command.

mvn install:install-file -Dfile=<path-to-file> -DgroupId=<group-id> -DartifactId=<artifact-id> -Dversion=<version> -Dpackaging=<packaging>

You can find more detail about using non-Maven jar file with RTSDK Java example on How to Set Up Refinitiv Real-Time SDK Java Application with Maven article.

RTSDK Java with Gradle

RTSDK — Java package comes with Gradle build tool supported by default, please find more detail in RTSDK Java Build System page and RTSDK — Java’s README file. You can download the SDK package from [Developer Portal website]https://developers.refinitiv.com/en/api-catalog/refinitiv-real-time-opnsrc/rt-sdk-java/download) and GitHub repository.

Conclusion

The RTSDK Java is now available in Maven central repository which makes Java developers can implement the Real-Time application with the build automation tools such as Apache Maven, Gradle, or even the dependency manager tool like Apache Ivy. This will helps Java developers reduce the complexity of maintaining jar file dependencies, easily share the development environment among peers, and support various build processes that match developers’ workflow.

References

For further details, please check out the following resources:

For any question related to this article or RTSDK page, please use the Developer Community Q&A Forum.

GitHub

Developer Advocate at Refinitiv, an LSEG business. https://developers.refinitiv.com/