Multiple hostnames in consumerConfig for EMA ?

sagar.s
sagar.s Explorer

OmmConsumerConfig config = EmaFactory.createOmmConsumerConfig();
consumer = EmaFactory.createOmmConsumer(config.host(getHostName() + ":" + getPortNumber()).username(getUserName()));

Is there an option to provide multiple hostnames to the createOmmConsumer(config.host()) for load balancing or fail-safe operation? Can you please provide with any example if its possible?

Best Answer

  • Hello @sagar.s

    OmmConsumerConfig.host(String) is to specify a hostname and
    port that EMA will connect to so it does not accept multiple hosts. However,
    EMA provides another way to configure EMA for multiple hosts by using ChannelSet
    parameter in the Configuration file named EmaConfig.xml as explained in
    EMAJ_ConfigGuide.pdf:

    image

    The example of ChannelSet for multiple Channels in EmaConfig.xml:

    <Consumer>
    <Name value="Consumer_2"/>
    <!-- ChannelSet specifies an ordered list of Channels to which OmmConsumer will attempt to -->
    <!-- connect, one at a time, if the previous one fails to connect -->
    <ChannelSet value="Channel_1, Channel_2"/>
    <Dictionary value="Dictionary_2"/>
    <XmlTraceToStdout value="0"/>
    </Consumer>

    Each Channel can specify a host and port:

    <Channel>
    <Name value="Channel_1"/>
    ...
    <Host value="localhost"/>
    <Port value="14002"/>
    </Channel>
    <Channel>
    <Name value="Channel_2"/>
    ...
    <Host value="192.168.27.48"/>
    <Port value="14002"/>
    </Channel>

    You can try example110__MarketPrice__FileConfig
    which loads Consumer_2 configuration that sets multiple Channels in the ChannelSet parameters. The application loads Consumer_2 from EmaConfig.xml file located in the application's working directory.

    The snipped source code to load Consumer_2 configuration:

    consumer  = EmaFactory.createOmmConsumer(EmaFactory.createOmmConsumerConfig().consumerName("Consumer_2"));

    The example output when EMA tried to connect to
    the first host in Channel_1 but it failed. Then, it tried to connect to
    the second host in Channel_2 and it succeeded:

    image

Answers