question

Upvotes
Accepted
3 0 0 3

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
icon clock
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 ,

Thank you for your participation in the forum. Is the reply below satisfactory in resolving your query?

If so please can you click the 'Accept' text next to the appropriate reply? This will guide all community members who have a similar question.


Thanks,

AHS

Hi @Shadab Hussain , done, thanks for remainder

Upvotes
Accepted
25.3k 87 12 25

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.

icon clock
10 |1500

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

@Askhat.Serikov

This is a private comment only visible to OP and moderators.

It is currently possible to manually manage tokens using EMA using a workaround - but the RT-SDK dev team do not support this as it may well break when we release the upcoming enhancements to the Authentication system - hopefully end of Q1 for EMA.

@Askhat.Serikov

Hi, whilst it may be possible to manually manipulate the token - and one of my colleagues did demonstrate this - RTO Token to be shared with EMA - Forum | Refinitiv Developer Community (not sure if you will be able to see the solution as it was deleted).
The RT-SDK team advised against it and do not support it. That is why the above post was deleted and not shared with end customers.

The solution/workaround my colleague posted above was a combination of XML file and code - I don't thing he tried using purely programmatic config - once the dev team told us not to use the workaround.

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)?

Upvotes
3 0 0 3

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));
icon clock
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

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

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