1. Ultipa Database Address
Multiple addresses of the servers of a cluster should be separated with comma ',' before being configured as the Ultipa Database Address.
2. Account and Password
Default account and password of the Ultipa Database are both 'root'
3. Configuration
Configuration class UltipaConfiguration
suports settings such as connetion timeout, consistency level, etc. In the case of ssl connetection type, crtFile
and overrideAuthority
should be set.
Item | Range | Description |
---|---|---|
username | \ | The account username |
password | \ | The account password |
url | \ | The server address, either the address of a stand-alone server, or multiple addresses of all servers of a cluster separated with comma ',' |
timeout | >0 | The connection timeout |
consistency | true , false |
The consistency level |
type | ssl , insecure |
The connection type |
crtFile | \ | File path of CA certificate, required when connType is 'ssl' |
overrideAuthority | ultipa |
Over-ride the 'hostname' to match the cert the server uses |
4. Instantiation of UltipaClientDriver
UltipaConfiguration configuration = UltipaConfiguration.config()
.username("root")
.password("root")
.url("192.168.1.1:60061");
UltipaClientDriver driver = new UltipaClientDriver(configuration);
Connection client = new DefaultConnection(driver, "default");
String reply = client.sayHello("Ultipa");
System.out.println(reply);
5. Configuration File
The Ultipa Server can also be connected via a configuration file named 'ultipa.properties', which will be read automatically when creating UltipaClientDriver
and thus no need for UltipaConfiguration
.
Create file 'ultipa.properties' under classpath
of the database project, and fill below configurations:
ultipa.grpc.pool.conn.username=root
ultipa.grpc.pool.conn.password=root
ultipa.grpc.pool.conn.url=192.168.1.1:60061,192.168.1.2:60061,192.168.1.3:60061
ultipa.grpc.pool.conn.query.timeout=15
ultipa.grpc.pool.conn.consistency=false
ultipa.grpc.pool.conn.type=insecure
ultipa.grpc.pool.conn.crtFile=F:\\ultipa.crt
ultipa.grpc.pool.conn.overrideAuthority=ultipa
Instantiate the UltipaClientDriver
with configuration file:
UltipaClientDriver driver = new UltipaClientDriver();
Connection client = new DefaultConnection(driver);
String reply = client.sayHello("Ultipa");
System.out.println(reply);
6. Connection Pool
UltipaClientDriver
uses Apache Common-Pool, and below connection pool information need to be configured when creating UltipaClientDriver
:
UltipaConfiguration configuration = UltipaConfiguration.config()
.username("root")
.password("root")
.hosts("192.168.1.1:60061");
GenericObjectPoolConfig<ManagedChannel> poolConfig
= new GenericObjectPoolConfig<ManagedChannel>();
poolConfig.setMaxIdle(50);
poolConfig.setMinIdle(2);
poolConfig.setMaxTotal(200);
poolConfig.setMaxWaitMillis(-1);
UltipaClientDriver driver = new UltipaClientDriver(configuration, poolConfig);
Connection client = new DefaultConnection(driver, "default");
String reply = client.sayHello("Ultipa");
System.out.println(reply);
The above configuration can also be included in the configuration file 'ultipa.properties' alternatively:
# Maximum number of idle connections
ultipa.grpc.pool.conn.maxIdle=50
# Minimum number of idle connections
ultipa.grpc.pool.conn.minIdle=20
# Maximum number of total connections
ultipa.grpc.pool.conn.maxTotal=2000
# Minimum idle time of an evictable connection, defalut is 1800000 ms (30 min)
ultipa.grpc.pool.conn.minEvictableIdleTimeMillis=1800000
# Test interval for evictable connections (ms), default is -1 (do not scan)
ultipa.grpc.pool.conn.timeBetweenEvictionRunsMillis=3600000
# Test connections when borrow, default is fasle
ultipa.grpc.pool.conn.testOnBorrow=true
# Test connections when return, default is fasle
ultipa.grpc.pool.conn.testOnReturn=false
# Test connections when idle, default is fasle
ultipa.grpc.pool.conn.testWhileIdle=false
# Maximum wait time, default is -1 (infinite wait)
ultipa.grpc.pool.conn.maxWaitMillis=-1
# Last in first out, default is true
ultipa.grpc.pool.conn.lifo=true
# Block new request when connections are exhausted, default is true (block until timeout), false will popup error
ultipa.grpc.pool.conn.blockWhenExhausted=true
# Number of connections to test each time, default is 3
ultipa.grpc.pool.conn.numTestsPerEvictionRun=3