-
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.
- Loading branch information
1 parent
4406016
commit 0e43bf7
Showing
18 changed files
with
42,331 additions
and
12 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
38 changes: 38 additions & 0 deletions
38
src/main/java/io/weaviate/client/grpc/client/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,38 @@ | ||
package io.weaviate.client.grpc.client; | ||
|
||
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.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()); | ||
} | ||
} | ||
ManagedChannel channel = ManagedChannelBuilder.forTarget(getAddress(config)).usePlaintext().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.