milvus-logo
LFAI
< Docs
  • Java
    • v1
      • Connections

MilvusClient

MilvusClient is an abstract interface of the Milvus client. MilvusServiceClient class is the implementation.

package io.milvus.client;
MilvusServiceClient(ConnectParam connectParam)

Methods of MilvusClient for connection:

Method

Description

Parameters

Returns

withTimeout(long timeout, TimeUnit timeoutUnit)

Timeout setting for RPC call.

timeout: The timeout period when invoking a method.

timeoutUnit: The unit for timeout.

MilvusClient

withRetry(RetryParam retryParam)

Sets the parameters for retry.

retryParam: Parameter for retry on failure.

MilvusClient

close(long maxWaitSeconds)

Disconnects from a Milvus server with a configurable timeout value. Call this method before the application terminates.This method throws an InterruptedException exception if it is interrupted.

maxWaitSeconds: The timeout period to wait for the RPC channel to close.

N/A

setLogLevel(LogLevel level)

Set log level in runtime.Note: this method cannot change the log level configured by log4j configurations. It only hides some logs inside the MilvusClient class.

level: A log level

N/A

ConnectParam

Use the ConnectParam.Builder to construct a ConnectParam object for the MilvusClient.

import io.milvus.param.ConnectParam;
ConnectParam.Builder builder = ConnectParam.newBuilder();

Methods of ConnectParam.Builder:

Method

Description

Patameters

withHost(String host)

Sets the host name or address.

host: The name or address of the host.

withPort(int port)

Sets the connection port.
The value must be greater than zero and less than 65536.

port: The connection port.

withUri(String uri)

Sets the uri of remote service.

uri: The uri of remote service.

withToken(String token)

Sets the token of remote service.

token: serving as the key for identification and authentication purposes.

withDatabaseName(String databaseName)

Sets the database name. database name can be null for default database.

databaseName: The database name.

withConnectTimeout(long connectTimeout, TimeUnit timeUnit)

Sets the connection timeout value of client channel. The timeout value must be greater than zero. The default value is 10 seconds.

connectTimeout: The connection timeout period.
timeUnit: The unit of timeout.

withKeepAliveTime(long keepAliveTime, TimeUnit timeUnit)

Sets the keep-alive time value of the client channel. The time value must be greater than zero. The default value is 55 seconds.

keepAliveTime: The keep-alive time period.
timeUnit: The unit of time.

withKeepAliveTimeout(long keepAliveTimeout, TimeUnit timeUnit)

Sets the keep-alive timeout value of client channel. The timeout value must be greater than zero. The default value is 20 seconds.

keepAliveTimeout: The keep-alive timeout value.
timeUnit: The unit of timeout.

keepAliveWithoutCalls(boolean enable)

Enables the keep-alive function for the client channel. The default value is false.

enable: Boolean value to indicate if the keep-alive function is enabled. The keep-alive function is enabled if the value is set to true.

secure(boolean enable)
withSecure(boolean enable)

Enables security for the client channel.

enable: Security is enabled if the value is set to true.

withIdleTimeout(long idleTimeout, TimeUnit timeUnit)

Sets the value of idle timeout of the client channel. The timeout value must be greater than zero. The default value is 24 hours.

idleTimeout: The idle timeout period of the client channel.
timeUnit: The unit of timeout.

withRpcDeadline(long deadline, TimeUnit timeUnit)

Set a deadline for how long you are willing to wait for a reply from the server.
With a deadline setting, the client will wait when encounter fast RPC fail caused by network fluctuations.
The deadline value must be larger than or equal to zero. Default value is 0, deadline is disabled.

deadline: deadline value
timeUnit: deadline unit

withAuthorization(String username, String password)

Sets the username and password for this connection.

username: The username of the current user.
password: The password corresponding to the username.

withClientKeyPath(String clientKeyPath)

Set the client.key path for tls two-way authentication, only takes effect when "secure" is True.

clientKeyPath: The local path of client.key

withClientPemPath(String clientPemPath)

Set the client.pem path for tls two-way authentication, only takes effect when "secure" is True.

clientPemPath: The local path of client.pem

withCaPemPath(String caPemPath)

Set the ca.pem path for tls two-way authentication, only takes effect when "secure" is True.

caPemPath: The local path of ca.pem

withServerPemPath(String serverPemPath)

Set the server.pem path for tls one-way authentication, only takes effect when "secure" is True.

serverPemPath: The local path of server.pem

withServerName(String serverName)

Set target name override for SSL host name checking, only takes effect when "secure" is True.
Note: this value is passed to grpc.ssltargetname_override

serverName: The override name for SSL host.

build()

Constructs a ConnectParam object.

N/A

The ConnectParam.Builder.build() can throw the following exceptions:

  • ParamException: error if the parameter is invalid.

RetryParam

Use the RetryParam.Builder to construct a RetryParam object for the MilvusClient.

import io.milvus.param.RetryParam;
RetryParam.Builder builder = RetryParam.newBuilder();

Methods of RetryParam.Builder:

Method

Description

Patameters

withMaxRetryTimes(int maxRetryTimes)

Sets the max retry times on failure.Default value is 75.

maxRetryTimes: The maxinum times to retry.

withInitialBackOffMs(long initialBackOffMs)

Sets the first time interval between two retries, units: millisecond. Default value is 10ms.

initialBackOffMs: Retry initial interval value in milliseconds.

withMaxBackOffMs(long maxBackOffMs)

Sets the maximum time interval between two retries, units: millisecond. Default value is 3000ms.

maxBackOffMs: Retry maximum interval value in milliseconds.

withBackOffMultiplier(int backOffMultiplier)

Sets multiplier to increase time interval after each retry. Default value is 3.

backOffMultiplier: The multiplier to increase time interval after each retry.

withRetryOnRateLimie(boolean retryOnRateLimie)

Sets whether to retry when the returned error is rate limit. Default value is true.

retryOnRateLimit: Whether to retry when the returned error is rate limit.

build()

Constructs a RetryParam object.

N/A

The RetryParam.Builder.build() can throw the following exceptions:

  • ParamException: error if the parameter is invalid.

Example

  • Without timeout setting for RPC call:
import io.milvus.param.*;
import io.milvus.client.*;

ConnectParam connectParam = ConnectParam.newBuilder()
    .withHost("localhost")
    .withPort(19530)
    .withAuthorization("root", "Milvus")
    .build();
RetryParam retryParam = RetryParam.newBuilder()
        .withMaxRetryTimes(10)
        .build();
MilvusClient client = new MilvusServiceClient(connectParam).withRetry(retryParam);

ShowCollectionsParam param = ShowCollectionsParam.newBuilder().build()
R<ShowCollectionsResponse> response = client.showCollections(param);

client.close(1);
  • With timeout setting for RPC call:
import io.milvus.param.*;
import io.milvus.client.*;
import java.util.concurrent.TimeUnit;

ConnectParam connectParam = ConnectParam.newBuilder()
    .withHost("localhost")
    .withPort(19530)
    .withAuthorization("root", "Milvus")
    .build();
MilvusClient client = new MilvusServiceClient(connectParam);

ShowCollectionsParam param = ShowCollectionsParam.newBuilder().build()
R<ShowCollectionsResponse> response = client.withTimeout(2, TimeUnit.SECONDS).showCollections(param);

client.close(1);
Feedback

Was this page helpful?