Connecting to multiple Tarantool instances
June 8, 2023 ยท View on GitHub
Connecting to multiple Tarantool instances
This section shows examples of how to connect to multiple Cartridge routers.
We recommend to use load balancer in production applications rather than leaving this task to the connector.
Warning
In the case of using multiple instances ofTarantoolClientwe strongly recommend to apply a shuffle function to the list of addresses. By default,TarantoolClientuses the round-robin approach for selecting the next available connection to distribute the load between Tarantool servers. When several instances ofTarantoolClientare used simultaneously, with the default connection selection strategy and without shuffling of the server addresses the first request from every instance will be sent to the same server.
Note
You do not have to worry about shuffling addresses if you are using a singleTarantoolClientconnected to multiple instances, or if you are using a custom connection selection strategy that takes into account the problem of simultaneous requests.
Setting addresses manually
Example of TarantoolClient set up with connecting to multiple routers
https://github.com/tarantool/cartridge-java/blob/d13e8693dcda041831f0a8de24092c98ebfff576/src/test/java/io/tarantool/driver/integration/ReconnectIT.java#L348-L359
https://github.com/tarantool/cartridge-java/blob/d13e8693dcda041831f0a8de24092c98ebfff576/src/test/java/io/tarantool/driver/integration/ReconnectIT.java#L373-L382
Setting addresses with address provider
Example of TarantoolClient set up with address provider
You may use the provided code as a reference for your own implementation
https://github.com/tarantool/cartridge-java/blob/d13e8693dcda041831f0a8de24092c98ebfff576/src/test/java/io/tarantool/driver/integration/ProxyTarantoolClientWithAddressProviderExampleIT.java#L81-L89
Example of TarantoolClusterAddressProvider setup
https://github.com/tarantool/cartridge-java/blob/d13e8693dcda041831f0a8de24092c98ebfff576/src/test/java/io/tarantool/driver/integration/ProxyTarantoolClientWithAddressProviderExampleIT.java#L44-L74
Do not forget to set tarantool function witch will return addresses
The function must be global, so that it can be called from the connector
https://github.com/tarantool/cartridge-java/blob/09ec7084780c66e5457a8cd9e508376f40a266b7/src/test/resources/cartridge/app/roles/custom.lua#L3-L30