question

Askhat.Serikov avatar image
3 0 0 2

Configure programmatic config, but specify token manually

Hello,
I am trying to config ema programmatically, previously I was using EmaConfig.xml and in the specifying:

final var config = EmaFactory.createOmmConsumerConfig();
config.consumerName(NAME);
config.addAdminMsg(EmaFactory.Domain.createLoginReq()
    .clear()
    .name(token)
    .nameType(USER_AUTH_TOKEN)
    .applicationId("AppId").message());
return EmaFactory.createOmmConsumer(config, loginCallback, errorCallback);

Now I am trying to create programmatic config:

final var elektronHosts = getHosts(token);
final var programmaticConfig = createProgrammaticConfig(elektronHosts, true);
final OmmConsumerConfig config = EmaFactory.createOmmConsumerConfig()
    .config(programmaticConfig)
    .consumerName("Consumer_1");

config.addAdminMsg(EmaFactory.Domain.createLoginReq()
    .clear()
    .name(token)
    .nameType(USER_AUTH_TOKEN)
    .applicationId("AppId").message());
return EmaFactory.createOmmConsumer(config, loginCallback, errorCallback);

But I am getting following error:

Received EMA invalid usage. Text is loggerMsg
    ClientName: ChannelCallbackClient
    Severity: Error
    Text:    Failed to add RsslChannel(s) to RsslReactor. Channel name(s) 
Instance Name Consumer_1_1
RsslReactor @100ab035
RsslChannel null
Error Id -6
Internal sysError 0
Error Location Reactor.copyOAuthCredentialForSessionManagement
Error Text Failed to copy OAuth credential for enabling the session management; OAuth client ID does not exist.
loggerMsgEnd

This is programmatic config:

private Map createProgrammaticConfig(List<ElektronHost> endpoints, boolean isWebSocket) {
  Map configDb = EmaFactory.createMap();
  Map elementMap = EmaFactory.createMap();
  ElementList elementList = EmaFactory.createElementList();
  ElementList innerElementList = EmaFactory.createElementList();
  elementList.add(EmaFactory.createElementEntry().ascii("DefaultConsumer", "Consumer_1"));
  innerElementList.add(EmaFactory.createElementEntry().ascii("ChannelSet", getChannelSetValue(endpoints.size())));
  innerElementList.add(EmaFactory.createElementEntry().ascii("Dictionary", "Dictionary_1"));

  //For support regular tracing it should be also enabled.
  innerElementList.add(EmaFactory.createElementEntry().intValue("XmlTraceToStdout", 1));

  //For support RTT monitoring it should be enabled
  innerElementList.add(EmaFactory.createElementEntry().uintValue("EnableRtt", 1));

  elementMap.add(EmaFactory.createMapEntry().keyAscii("Consumer_1", MapEntry.MapAction.ADD, innerElementList));
  innerElementList.clear();

  elementList.add(EmaFactory.createElementEntry().map("ConsumerList", elementMap));
  elementMap.clear();

  configDb.add(EmaFactory.createMapEntry().keyAscii("ConsumerGroup", MapEntry.MapAction.ADD, elementList));
  elementList.clear();

  for (int i = 0; i < endpoints.size(); i++) {
    innerElementList.add(EmaFactory.createElementEntry().ascii("ChannelType", "ChannelType::RSSL_ENCRYPTED"));

    if (isWebSocket) {
      innerElementList.add(EmaFactory.createElementEntry().ascii("EncryptedProtocolType", "EncryptedProtocolType::RSSL_SOCKET"));
      innerElementList.add(EmaFactory.createElementEntry().ascii("WsProtocols", "tr_json2, rssl.json.v2"));
    }

    innerElementList.add(EmaFactory.createElementEntry().ascii("Host", endpoints.get(i).getEndpoint()));
    innerElementList.add(EmaFactory.createElementEntry().ascii("Port", String.valueOf(endpoints.get(i).getPort())));
    innerElementList.add(EmaFactory.createElementEntry().intValue("EnableSessionManagement", 1));

    elementMap.add(EmaFactory.createMapEntry().keyAscii("Channel_" + (i + 1), MapEntry.MapAction.ADD, innerElementList));
    innerElementList.clear();
  }

  elementList.add(EmaFactory.createElementEntry().map("ChannelList", elementMap));
  elementMap.clear();

  configDb.add(EmaFactory.createMapEntry().keyAscii("ChannelGroup", MapEntry.MapAction.ADD, elementList));
  elementList.clear();


  innerElementList.add(EmaFactory.createElementEntry().ascii("DictionaryType", "DictionaryType::ChannelDictionary"));

  elementMap.add(EmaFactory.createMapEntry().keyAscii("Dictionary_1", MapEntry.MapAction.ADD, innerElementList));
  innerElementList.clear();

  elementList.add(EmaFactory.createElementEntry().map("DictionaryList", elementMap));
  elementMap.clear();

  configDb.add(EmaFactory.createMapEntry().keyAscii("DictionaryGroup", MapEntry.MapAction.ADD, elementList));
  elementList.clear();
  return configDb;
}

private String getChannelSetValue(int size) {
  final StringBuilder channelBuilder = new StringBuilder();
  IntStream.range(1, size)
      .forEach(i -> channelBuilder.append("Channel_").append(i).append(", "));
  channelBuilder.append("Channel_").append(size);
  return channelBuilder.toString();
}



I feel like I am missing something in my programmatic configuration.
What would be the correct way to create programmatic config, while managing the token myself without the ema to manage it for me?

elektronema-apiconfiguration
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

umer.nalla avatar image
23.5k 84 10 22

Hi @Askhat.Serikov

We do not currently support allowing you to manage the token manually in EMA.

If you do wish to manage the token manually, it could be possible to do so using raw ETA (non ValueAdd layer) - but I have never tried this.

If you were planning to manually manage the token because you need to share it across multiple processes/applications - please ask your Refintitiv account team to provide you with additional MachineIDs so that each process can use a unique MachineID.

1 comment
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Hi @umer.nalla, thank you for your response, I am able to manage token manually when I use EmaConfig.xml, together with

config.addAdminMsg(EmaFactory.Domain.createLoginReq()
    .clear()
    .name(token)
    .nameType(USER_AUTH_TOKEN)
    .applicationId("AppId").message());

Is the inability to manage token manually only present in programmatical config (because I can manually manage token wtih xml config)?

Askhat.Serikov avatar image
3 0 0 2

Seems like I have figured it out. Sorry mistake on my part, should have set EnableSessionManagement to false during configuration.

innerElementList.add(EmaFactory.createElementEntry().intValue("EnableSessionManagement", 0));
2 comments
10 |1500

Up to 2 attachments (including images) can be used with a maximum of 512.0 KiB each and 1.0 MiB total.

Hi @Askhat.Serikov

Thanks for the update - however, as mentioned above, this is not supported by the RT-SDK team and may break in future versions (according to the RT-SDK dev team).


I understand, thank you @umer.nalla