use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel in project ballerina by ballerina-lang.
the class InitEndpoint method execute.
@Override
public void execute(Context context) {
try {
Struct clientEndpoint = BLangConnectorSPIUtil.getConnectorEndpointStruct(context);
// Creating client endpoint with channel as native data.
Struct endpointConfig = clientEndpoint.getStructField(EndpointConstants.ENDPOINT_CONFIG);
EndpointConfiguration configuration = EndpointUtils.getEndpointConfiguration(endpointConfig);
ManagedChannel channel;
if (configuration.getSslConfig() == null) {
channel = ManagedChannelBuilder.forAddress(configuration.getHost(), configuration.getPort()).usePlaintext(true).build();
} else {
SslContext sslContext = new SSLHandlerFactory(configuration.getSslConfig()).createHttp2TLSContextForClient();
channel = NettyChannelBuilder.forAddress(generateSocketAddress(configuration.getHost(), configuration.getPort())).flowControlWindow(65 * 1024).maxInboundMessageSize(MAX_MESSAGE_SIZE).sslContext(sslContext).build();
}
clientEndpoint.addNativeData(CHANNEL_KEY, channel);
} catch (Throwable throwable) {
BStruct errorStruct = MessageUtils.getConnectorError(context, throwable);
context.setError(errorStruct);
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel in project dgraph4j by dgraph-io.
the class DgraphClientTest method testClientWithDeadline.
@Test
public void testClientWithDeadline() throws Exception {
ManagedChannel channel = ManagedChannelBuilder.forAddress(TEST_HOSTNAME, TEST_PORT).usePlaintext(true).build();
DgraphGrpc.DgraphBlockingStub blockingStub = DgraphGrpc.newBlockingStub(channel);
dgraphClient = new DgraphClient(Collections.singletonList(blockingStub), 1);
Operation op = Operation.newBuilder().setSchema("name: string @index(exact) @upsert .").build();
// Alters schema without exceeding the given deadline.
dgraphClient.alter(op);
// Creates a blocking stub directly, in order to force a deadline to be exceeded.
Method method = DgraphClient.class.getDeclaredMethod("anyClient");
method.setAccessible(true);
DgraphGrpc.DgraphBlockingStub client = (DgraphGrpc.DgraphBlockingStub) method.invoke(dgraphClient);
Thread.sleep(1001);
try {
client.alter(op);
fail("Deadline should have been exceeded");
} catch (StatusRuntimeException sre) {
// Expected.
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel in project vertx-openshift-it by cescoffier.
the class EdgeVerticle method grpc.
private void grpc(RoutingContext rc) {
ManagedChannel channel = VertxChannelBuilder.forAddress(vertx, "hello", 8082).useSsl(options -> options.setSsl(true).setUseAlpn(true).setTrustAll(true)).build();
GreeterGrpc.GreeterVertxStub stub = GreeterGrpc.newVertxStub(channel);
HelloRequest request = HelloRequest.newBuilder().setName("OpenShift").build();
System.out.println("Sending request...");
stub.sayHello(request, asyncResponse -> {
System.out.println("Got result");
if (asyncResponse.succeeded()) {
System.out.println("Succeeded " + asyncResponse.result().getMessage());
rc.response().end(asyncResponse.result().getMessage());
} else {
rc.fail(asyncResponse.cause());
}
});
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel in project vertx-openshift-it by cescoffier.
the class Http2IT method testGRPC.
@Test
public void testGRPC() throws Exception {
Assertions.assertThat(client).deployments().pods().isPodReadyForPeriod();
String host = securedUrlForRoute(client.routes().withName("hello").get()).getHost();
System.out.println("Host: " + host);
System.out.println("Port: " + 443);
ManagedChannel channel = VertxChannelBuilder.forAddress(vertx, host, 443).useSsl(options -> options.setSsl(true).setUseAlpn(true).setTrustAll(true)).build();
GreeterGrpc.GreeterVertxStub stub = GreeterGrpc.newVertxStub(channel);
HelloRequest request = HelloRequest.newBuilder().setName("OpenShift").build();
AtomicReference<String> result = new AtomicReference<>();
System.out.println("Sending request...");
stub.sayHello(request, asyncResponse -> {
System.out.println("Got result");
if (asyncResponse.succeeded()) {
System.out.println("Succeeded " + asyncResponse.result().getMessage());
result.set(asyncResponse.result().getMessage());
} else {
asyncResponse.cause().printStackTrace();
}
});
await().atMost(5, TimeUnit.MINUTES).untilAtomic(result, is(notNullValue()));
assertThat(result.get()).contains("Hello OpenShift");
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel in project zipkin-gcp by openzipkin.
the class StackdriverStorage method newBuilder.
public static Builder newBuilder() {
ManagedChannel channel = ManagedChannelBuilder.forTarget("cloudtrace.googleapis.com").build();
Builder result = newBuilder(channel);
result.shutdownChannelOnClose = true;
return result;
}
Aggregations