OpenDXL Client behavior when the connected Broker goes offline?

  • I have an environment with multiple DXL brokers, and I'm not sure what kind of failover protection is already built-in to the OpenDXL Python Client.


    If one of my clients is connected to one of these Brokers, and the broker goes offline without warning (power failure, for example), how can I make sure that my client will reconnect to another broker that is still online?

  • If you have multiple brokers in your DXL fabric, the standard method is to provide a list of them to the OpenDXL Python Client through the config file before runtime. To see an example of what a config file with multiple brokers looks like, view the GitHub documentation for the OpenDXL Python Client Samples Configuration.

    In your Python client code, load the configuration from the file before you connect to a broker. See the example below (where "yourfile.config" would be the location+name of your config file):

    Python
    1. # Create DXL configuration from file
    2. config = DxlClientConfig.create_dxl_config_from_file("yourfile.config")
    3. # Create the client
    4. with DxlClient(config) as client:
    5. # Connect to the fabric
    6. client.connect()


    It is also possible to manually create your DxlClientConfig object and set the list of Broker objects in your code instead of through a config file:

    Python
    1. # Create the client configuration
    2. config = DxlClientConfig(
    3. broker_ca_bundle="c:\\certs\\brokercerts.crt",
    4. cert_file="c:\\certs\\client.crt",
    5. private_key="c:\\certs\\client.key",
    6. brokers=[Broker.parse("ssl://192.168.189.12")])


    For more information on Broker.parse(), see the dxlclient.broker module documentation on Github.

  • That was a huge help, thanks.


    What kind of reconnect behavior can we expect if a client isn't able to immediately connect to another listed broker? For example, if the client has a network outage for several minutes.

  • By default, the the python client will attempt to reconnect by looping connection attempts to brokers on the broker list.


    The reconnect loop will only attempt to connect to a broker after a set amount of time dictated by a backoff timer, to avoid spamming the network with connection attempts in the case of a large number of clients losing connection to their brokers at once.


    The settings to control reconnect behavior can be seen in the OpenDXL Python Client Documentation for the dxlclient.client_config module, or below:


    dxlclient.client_config 

    reconnect_back_off_multiplier Multiples the current reconnect delay by this value on subsequent connect retries. For example, a current delay of 3 seconds with a multiplier of 2 would result in the next retry attempt being in 6 seconds. Defaults to 2
    reconnect_delay The initial delay between retry attempts in seconds. The delay increases (“backs off”) as subsequent connection attempts are made. Defaults to 1 second

    reconnect_delay_max
    The maximum delay between connection retry attempts in seconds Defaults to 60 seconds (1 minute)
    reconnect_delay_random Get the randomness delay percentage (between 0.0 and 1.0). The default value is 0.25
    reconnect_when_disconnected Whether the client will continuously attempt to reconnect to the fabric if it becomes disconnected Defaults to True