question

Upvotes
Accepted
1 0 0 2

How to specify multiple hosts while connecting using ETA reactor api?

I am using reactor api for consuming data from reuters feed. How to specify multiple hosts in connection config?

I am using below code:

connectOptions.connectionList().add(connectInfo);
   connectOptions.connectionList().get(0).connectOptions().majorVersion(Codec.majorVersion());
   connectOptions.connectionList().get(0).connectOptions().minorVersion(Codec.minorVersion());
   connectOptions.connectionList().get(0).connectOptions().connectionType(ConnectionTypes.SOCKET);
   connectOptions.connectionList().get(0).connectOptions().unifiedNetworkInfo().address(srvrHostname);
   connectOptions.connectionList().get(0).connectOptions().unifiedNetworkInfo().serviceName(srvrPortNo);
   connectOptions.connectionList().get(0).connectOptions().guaranteedOutputBuffers(1000);


   // Prepare our connection
//connectOptions.connectionList().add(connectInfo);
   connectOptions.connectionList().get(1).connectOptions().majorVersion(Codec.majorVersion());
   connectOptions.connectionList().get(1).connectOptions().minorVersion(Codec.minorVersion());
   connectOptions.connectionList().get(1).connectOptions().connectionType(ConnectionTypes.SOCKET);
   connectOptions.connectionList().get(1).connectOptions().unifiedNetworkInfo().address(srvrHostname2);
   connectOptions.connectionList().get(1).connectOptions().unifiedNetworkInfo().serviceName(srvrPortNo);
   connectOptions.connectionList().get(1).connectOptions().guaranteedOutputBuffers(1000);

After hit trial, I noticed that by uncommenting the code, I can make connection.

However, when I print host name in channel_Up or channel_ready events, It is always 2nd host i.e.

connectOptions.connectionList().get(1).connectOptions().unifiedNetworkInfo().address(srvrHostname2);


1) Is above correct way to connect using multiple hosts ?

2) I am using reconnect tries as -1, so how reactor api will be failed over to other host in pipeline?

eta-apireactor
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.

Upvotes
Accepted
80k 257 52 75

@rinki.goyal

You can refer to the VAConsumer example code. It demonstrates how to add a backup server.

        if (consumerCmdLineParser.backupHostname() != null && consumerCmdLineParser.backupPort() != null)
        {
            ReactorConnectInfo connectInfo = ReactorFactory.createReactorConnectInfo();
            chnlInfo.connectOptions.connectionList().add(connectInfo);
            chnlInfo.connectOptions.connectionList().get(1).connectOptions().majorVersion(Codec.majorVersion());
            chnlInfo.connectOptions.connectionList().get(1).connectOptions().minorVersion(Codec.minorVersion());
            chnlInfo.connectOptions.connectionList().get(1).connectOptions().connectionType(chnlInfo.connectionArg.connectionType());
            chnlInfo.connectOptions.connectionList().get(1).connectOptions().unifiedNetworkInfo().serviceName(consumerCmdLineParser.backupPort());
            chnlInfo.connectOptions.connectionList().get(1).connectOptions().unifiedNetworkInfo().address(consumerCmdLineParser.backupHostname());
            chnlInfo.connectOptions.connectionList().get(1).connectOptions().userSpecObject(chnlInfo);
            chnlInfo.connectOptions.connectionList().get(1).connectOptions().guaranteedOutputBuffers(1000);

It creates a new instance of ReactorConnectInfo and then adds it to the connection list.

Please let me know which line causes the index out-of-bounds exception.

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.

@Jirapongse please see below comment
Upvotes
1 0 0 2

@Jirapongse

If i uncomment this line , then i wont get Index out of bound exception

  1. //connectOptions.connectionList().add(connectInfo);

IF there are two hosts, then we need below line twice :

connectOptions.connectionList().add(connectInfo);


I have fixed the code to below, however I still dont see in logs connection being made to back up host, Could you please assist here ?

private ReactorConnectInfo backUpConnectInfo = ReactorFactory.createReactorConnectInfo();
private ReactorDispatchOptions dispatchOptions = ReactorFactory.createReactorDispatchOptions();
// Prepare our connection
    connectOptions.connectionList().add(connectInfo);
        connectOptions.connectionList().get(0).connectOptions().majorVersion(Codec.majorVersion());
        connectOptions.connectionList().get(0).connectOptions().minorVersion(Codec.minorVersion());
        connectOptions.connectionList().get(0).connectOptions().connectionType(ConnectionTypes.SOCKET);
        connectOptions.connectionList().get(0).connectOptions().unifiedNetworkInfo().address(srvrHostname);
        connectOptions.connectionList().get(0).connectOptions().unifiedNetworkInfo().serviceName(srvrPortNo);
        connectOptions.connectionList().get(0).connectOptions().guaranteedOutputBuffers(1000);


        // Prepare our back up connection
connectOptions.connectionList().add(backUpConnectInfo);
connectOptions.connectionList().get(1).connectOptions().majorVersion(Codec.majorVersion());
        connectOptions.connectionList().get(1).connectOptions().minorVersion(Codec.minorVersion());
        connectOptions.connectionList().get(1).connectOptions().connectionType(ConnectionTypes.SOCKET);
        connectOptions.connectionList().get(1).connectOptions().unifiedNetworkInfo().address(srvrHostname2);
        connectOptions.connectionList().get(1).connectOptions().unifiedNetworkInfo().serviceName(srvrPortNo);
        connectOptions.connectionList().get(1).connectOptions().guaranteedOutputBuffers(1000);



        connectOptions.reconnectAttemptLimit(-1); // attempt to recover forever
        connectOptions.reconnectMinDelay(1000); // 1 second minimum
        connectOptions.reconnectMaxDelay(60000); // 60 second
 maximu
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.

Upvotes
80k 257 52 75

@rinki.goyal

You can specify many ReactorConnectInfo in the connection list but ETA will connect to one server at a time. For example, if you have two servers in the list, ETA will establish a connection to the first server. It will failover to the second server if it can detect disconnection from the first server.


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.

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.