Skip to content

Commit 9b202e4

Browse files
authored
Expose gRPC client on high level client (#27)
This commit exposes the low-level gRPC client on the high level client, for two purposes: - Allow access to the underlying gRPC channel. This may be useful for capturing properties about the channel e.g. the channel authority, for metrics. - Allow access to the gRPC client to make requests using the low-level gRPC client in cases where functionality may not yet be exposed by the higher level client.
1 parent 68729a5 commit 9b202e4

File tree

3 files changed

+61
-0
lines changed

3 files changed

+61
-0
lines changed

src/main/java/io/qdrant/client/QdrantClient.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,19 @@ public QdrantClient(QdrantGrpcClient grpcClient) {
137137
this.grpcClient = grpcClient;
138138
}
139139

140+
/**
141+
* Gets the low-level gRPC client. This is exposed to
142+
* <ul>
143+
* <li>Allow access to the underlying gRPC channel</li>
144+
* <li>Allow access to the gRPC client to make requests using the low-level gRPC client in cases
145+
* where functionality may not yet be exposed by the higher level client.</li>
146+
* </ul>
147+
* @return The low-level gRPC client
148+
*/
149+
public QdrantGrpcClient grpcClient() {
150+
return grpcClient;
151+
}
152+
140153
/**
141154
* Gets detailed information about the qdrant cluster.
142155
*

src/main/java/io/qdrant/client/QdrantGrpcClient.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,14 @@ public static Builder newBuilder(String host, int port, boolean useTransportLaye
9595
return new Builder(host, port, useTransportLayerSecurity);
9696
}
9797

98+
/**
99+
* Gets the channel
100+
* @return the channel
101+
*/
102+
public ManagedChannel channel() {
103+
return channel;
104+
}
105+
98106
/**
99107
* Gets the client for qdrant services
100108
* @return a new instance of {@link QdrantFutureStub}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
package io.qdrant.client;
2+
3+
import io.grpc.Grpc;
4+
import io.grpc.InsecureChannelCredentials;
5+
import io.grpc.ManagedChannel;
6+
import org.junit.jupiter.api.AfterEach;
7+
import org.junit.jupiter.api.Assertions;
8+
import org.junit.jupiter.api.BeforeEach;
9+
import org.junit.jupiter.api.Test;
10+
import org.testcontainers.junit.jupiter.Container;
11+
import org.testcontainers.junit.jupiter.Testcontainers;
12+
import org.testcontainers.qdrant.QdrantContainer;
13+
14+
@Testcontainers
15+
class QdrantClientTest {
16+
17+
@Container
18+
private static final QdrantContainer QDRANT_CONTAINER = new QdrantContainer(DockerImage.QDRANT_IMAGE);
19+
private QdrantClient client;
20+
21+
@BeforeEach
22+
public void setup() {
23+
ManagedChannel channel = Grpc.newChannelBuilder(
24+
QDRANT_CONTAINER.getGrpcHostAddress(),
25+
InsecureChannelCredentials.create())
26+
.build();
27+
QdrantGrpcClient grpcClient = QdrantGrpcClient.newBuilder(channel, true).build();
28+
client = new QdrantClient(grpcClient);
29+
}
30+
31+
@AfterEach
32+
public void teardown() {
33+
client.close();
34+
}
35+
36+
@Test
37+
void canAccessChannelOnGrpcClient() {
38+
Assertions.assertTrue(client.grpcClient().channel().authority().startsWith("localhost"));
39+
}
40+
}

0 commit comments

Comments
 (0)