-
Notifications
You must be signed in to change notification settings - Fork 19
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #231 from weaviate/grpc-batch-api
Add support for gRPC Batch API
- Loading branch information
Showing
34 changed files
with
56,706 additions
and
44 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/main/java/io/weaviate/client/base/grpc/GrpcClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
package io.weaviate.client.base.grpc; | ||
|
||
import io.grpc.ManagedChannel; | ||
import io.grpc.ManagedChannelBuilder; | ||
import io.grpc.Metadata; | ||
import io.grpc.stub.MetadataUtils; | ||
import io.weaviate.client.Config; | ||
import io.weaviate.client.grpc.protocol.v1.WeaviateGrpc; | ||
import java.util.Map; | ||
|
||
public class GrpcClient { | ||
|
||
public static WeaviateGrpc.WeaviateBlockingStub create(Config config) { | ||
Metadata headers = new Metadata(); | ||
if (config.getHeaders() != null) { | ||
for (Map.Entry<String, String> e : config.getHeaders().entrySet()) { | ||
headers.put(Metadata.Key.of(e.getKey(), Metadata.ASCII_STRING_MARSHALLER), e.getValue()); | ||
} | ||
} | ||
ManagedChannelBuilder<?> channelBuilder = ManagedChannelBuilder.forTarget(getAddress(config)); | ||
if (config.getScheme().equals("https")) { | ||
channelBuilder = channelBuilder.useTransportSecurity(); | ||
} else { | ||
channelBuilder.usePlaintext(); | ||
} | ||
ManagedChannel channel = channelBuilder.build(); | ||
WeaviateGrpc.WeaviateBlockingStub blockingStub = WeaviateGrpc.newBlockingStub(channel); | ||
return blockingStub.withInterceptors(MetadataUtils.newAttachHeadersInterceptor(headers)); | ||
} | ||
|
||
private static String getAddress(Config config) { | ||
if (config.getGrpcAddress() != null) { | ||
return config.getGrpcAddress(); | ||
} | ||
String host = config.getHost(); | ||
if (!host.contains(":")) { | ||
if (config.getScheme() != null && config.getScheme().equals("https")) { | ||
return String.format("%s:443", host); | ||
} | ||
return String.format("%s:80", host); | ||
} | ||
return host; | ||
} | ||
} |
Oops, something went wrong.