EMA endpoint discovery best practices

I have some questions about the discovery process for EMA connections. What we are currently using is just lifted from some sample code from about 2 years ago and looks like

class EndpointDiscoveryClient implements ServiceEndpointDiscoveryClient {
public void onSuccess(ServiceEndpointDiscoveryResp resp, ServiceEndpointDiscoveryEvent event) {
List<ServiceEndpointDiscoveryInfo> serviceEndpointDiscoveryInfos = resp.serviceEndpointInfoList();
for (ServiceEndpointDiscoveryInfo info : serviceEndpointDiscoveryInfos) {
List<String> locationList = info.locationList();
if (locationList.size() == 2 && locationList.get(0).startsWith(location)) {
host = info.endpoint();
port = info.port();
break;
}
}
}
}

Why test for size == 2 instead of size >= 2 ? Will there ever be more than 2 (or just 1)?

Why only use the first one? Are there cases we would fail over to a different host, and if so how do we detect those cases?

We're currently using com.refinitiv.ema:ema:3.7.1.0

Best Answer

  • Jirapongse
    Jirapongse admin
    Answer ✓

    @daniel.lipofsky

    Thank you for reaching out to us.

    Please refer to the Service Discovery example on GitHub.

            for(ServiceEndpointDiscoveryInfo info : serviceEndpointResp.serviceEndpointInfoList())
            {
                if(info.locationList().size() >= 2 && info.locationList().get(0).startsWith(Consumer.location)) // Get an endpoint that provides auto failover for the specified location.
                {
                    endPoint = info.endpoint();
                    port = info.port();
                    break;
                }
                // Try to get backups and keep looking for main case. Keep only the first item met.
                else if(info.locationList().size() > 0 && info.locationList().get(0).startsWith(Consumer.location) &&
    endPoint == null && port == null)

                {
                    endPoint = info.endpoint();
                    port = info.port();
                }
            }

    This is just an example that shows how to use the ServiceEndpointDiscovery. You can change the way to select the endpoint according to your requirements.

    The service endpoint discovery response looks like this:

    "services": [
            {
                "port": 14002,
                "location": [
                    "ap-northeast-1a"
                ],
                "transport": "tcp",
                "provider": "aws",
                "endpoint": "ap-northeast-1-aws-1-med.optimized-pricing-api.refinitiv.net",
                "dataFormat": [
                    "rwf"
                ]
            },
            {
                "port": 14002,
                "location": [
                    "ap-northeast-1a",
                    "ap-northeast-1b"
                ],
                "transport": "tcp",
                "provider": "aws",
                "endpoint": "ap-northeast-1-aws-3-med.optimized-pricing-api.refinitiv.net",
                "dataFormat": [
                    "rwf"
                ]
            },
            {
                "port": 14002,
                "location": [
                    "ap-northeast-1b"
                ],
                "transport": "tcp",
                "provider": "aws",
                "endpoint": "ap-northeast-1-aws-2-med.optimized-pricing-api.refinitiv.net",
                "dataFormat": [
                    "rwf"
                ]
            },

    You can select the endpoint that closes to your location and has two more more locations for fault tolerance.

    Moreover, you can use the ChannelSet configuration in the Consumer.

    1691724484202.png

    For example, the first channel in the ChannelSet connects to the endpoint in the ap-northeast location and the second channel in the ChannelSet connects to the endpoint in the ap-southeast location.

Answers