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?