This topic describes how to connect to and disconnect from the Milvus server.
Before performing any operations, make sure you are connected to the Milvus server.
Milvus supports two ports, port 19530
and port 9091
:
- Port
19530
is used for gRPC. When using different Milvus SDKs to connect to the Milvus server, this port is used by default. - Port
9091
is used for the RESTful API. This port is used when connecting to the Milvus server using an HTTP client.
The following examples connect to the Milvus server with the host as localhost
and the port as 19530
or 9091
, and then disconnect from the server. If the connection is refused, try unblocking the corresponding port.
Connecting to the Milvus Server
Build a Milvus connection. Before performing any operations, make sure you are connected to the Milvus server.
milvusClient, err := client.NewGrpcClient(
context.Background(), // ctx
"localhost:19530", // addr
)
if err != nil {
log.Fatal("Failed to connect to the Milvus server:", err.Error())
}
Parameter | Description |
---|---|
ctx |
The context that controls the API call process. |
addr |
The address for building the Milvus connection. |
Disconnecting from the Milvus Server
Disconnect from the Milvus server.
milvusClient.Close()
Limitation
The maximum number of connections is 65,536.