Download tutorial source code |
Click here to download |
Last update | Dec 2020 |
Compilers | Visual Studio 2015 |
Prerequisites | EMA NI Provider - A barebones EMA NIP application shell Declare the NI_PUB and TEST_NI_PUB services in your LSEG Real-Time Distribution System (see Before you start). |
In this tutorial, we will see how to use EMA to connect a NI Provider application to the LSEG Real-Time Distribution System. We will also describe the multiple actions EMA executes under the hood to simplify programmers’ life. Finally, we will teach you how to properly disconnect your application from the LSEG Real-Time Distribution System.
To this aim we will go through the following sections:
Non-Interactive Providers publish information that is cached and re-distributed by the LSEG Real-Time Distribution System. This enables the implementation of very simple provider applications that do not have to go through the hassle of handling requests from consuming applications. NI Providers just publish the data they have and the LSEG Real-Time Distribution System does all the hard work: catching the data, managing the interactions with the consumer applications, and distributing the requested data.
In this context, the general process of a NI Provider is the following:
In this tutorial, we will see a very simple way to implement a NI Provider that performs steps 1, 2, 3, and 6 with very few EMA calls.
The very first step a NI Provider must perform is to connect to the LSEG Real-Time Distribution System, or more precisely to the ADH (Advanced Data Hub) that is the component that provider applications are connected to. As shown in the diagram above, the ADH is also in charge of caching the data published by NI Providers. This connection can be done either via a point-to-point TCP connection or via a multicast connection. In this tutorial, we will demonstrate how to use the default connection mode, which is the TCP connection.
The ADH is a network component installed in your corporate area network. In order to connect to this ADH, you need its IP address, a port number, and a user name your application will use to perform the login process just after the connection. If you do not have this information, it can usually be provided by the administration team of your company.
The simplest way to connect your EMA NI Provider to the ADH is to instantiate an OmmProvider object with an OmmNiProviderConfig object that holds the ADH IP address, the port number, and the user name.
This is what we have done in the following connect() method that we added to the NIProvider class of this tutorial.
void NiProvider::connect()
{
// Exit the method if already connected
if (_provider != 0)
return;
const char * host = "YOUR_ADH_IP_ADDRESS:14003";
const char * userName = "YOUR_PROVIDER_USER_NAME";
cout << " Connecting Provider to ADH " << host << " as " << userName << endl;
// Connect to the infrastructure using hardcoded parameters
_provider = new OmmProvider(
OmmNiProviderConfig()
.host(host)
.username(userName));
}
As you can see, the ADH IP address, the port number, and the user name are hardcoded. This is something we will improve on in the next tutorials. But, for the sake of simplicity, we keep them hardcoded for now. Obviously, before you build and run this tutorial you will have to change the tutorial source code with your own ADH IP, port number, and user name. Let us say your ADH IP is 10.2.43.49 and your provider user name is nip-user, then the host and userName variables should be set this way:
const char * host = "10.2.43.49:14003";
const char * userName = "nip-user";
Note: The ADH IP address is followed by a colon and the port number the provider should connect to. In this example, the port number is set to 14003, which is the default port number for Non-Interactive Providers. Unless told otherwise by your LSEG Real-Time Distribution System Administrator, this is the port number you should use.
Once the OmmProvider object is created with these parameters, the EMA library connects to the ADH and logs in using the user name you provided. If the connection and login are successful, the NI Provider application can eventually publish data for the consuming applications. We will see how to publish data in the next tutorials.
The OmmProvider object is preserved in the _provider class member for later use.
Within the introduction, we explained the general process of a NI Provider, which is:
The first 3 steps of this process are actually executed under the hood by the EMA library when you create the OmmProvider object. Steps 1 and 2 are more obvious as we provided the ADH IP address, port number, and login user name when creating the OmmProvider object. This is less obvious for step 3 because we do not provide any source directory information such as the service name, or any RDM models supported by our Ni Provider application. Instead, EMA provides default settings for this information on behalf of the user. For example, even if our NI Provider application does not provide any source directory information, it declares a service named NI_PUB, as you will see when we will run and test our application in the Build and run the application section.
In order to logout and disconnect from the ADH, you just have to delete the OmmProvider object created at the time of the connection. This is what we implemented in the disconnect() method that we added to the NiProvider class.
void NiProvider::disconnect()
{
// Exit the method if already disconnected
if (_provider == 0)
return;
cout << " Disconnecting..." << endl;
delete _provider;
_provider = 0; cout << " Provider disconnected" << endl;
}
The main workflow leverages these two new connect() and disconnect() methods to implement the following:
int main(int argc, char* argv[])
{
. . .
NiProvider provider;
provider.connect();
waitFor(60);
provider.disconnect();
waitFor(10);
. . .
}
Build the application and start it. Please refer to the Build and Run section within the first tutorial of this series (A barebones EMA NIP application shell) for detailed instructions.
This is what you should get:
-------------------------------------------------------------------------------
| Non Interactive Provider EMA Tutorial |
| |
| Tutorial 2 - Connecting to the ADH |
-------------------------------------------------------------------------------
Provider created
Connecting Provider to ADH 10.2.43.49:14003 as nip-user
Waiting for 60 seconds...
Disconnecting...
Waiting for 10 seconds...
Exiting the application
Press any key to continue . . .
Q: When I build the tutorial project, I get errors like:
Exception Type='OmmInvalidUsageException',
Text='login failed (timed out after waiting 45000 milliseconds) for 10.2.43.149:14003)'
A: Verify that the ADH of your LSEG Real-Time Distribution System is up and that you properly set the hardcoded host variable of the NiProvider::connect() method.
You can also use the telnet command tool to verify that your NIP application machine can connect to the ADH (telnet <ADH host> <port>). If the telnet succeeds but you still can’t connect, verify that you don’t have any firewall blocking the messages sent/received by the application.
Ultimately, ask your administrator to help you to investigate with monitoring tools like adhmon.