Search in sources :

Example 21 with ManagedChannel

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);
    }
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) ManagedChannel(io.grpc.ManagedChannel) EndpointConfiguration(org.ballerinalang.net.grpc.config.EndpointConfiguration) SSLHandlerFactory(org.ballerinalang.net.grpc.ssl.SSLHandlerFactory) BStruct(org.ballerinalang.model.values.BStruct) Struct(org.ballerinalang.connector.api.Struct) SslContext(io.netty.handler.ssl.SslContext)

Example 22 with ManagedChannel

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.
    }
}
Also used : StatusRuntimeException(io.grpc.StatusRuntimeException) ManagedChannel(io.grpc.ManagedChannel) Method(java.lang.reflect.Method) Test(org.junit.Test)

Example 23 with ManagedChannel

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());
        }
    });
}
Also used : WebClientOptions(io.vertx.ext.web.client.WebClientOptions) ManagedChannel(io.grpc.ManagedChannel) HttpVersion(io.vertx.core.http.HttpVersion) WebClient(io.vertx.ext.web.client.WebClient) AbstractVerticle(io.vertx.core.AbstractVerticle) HttpServer(io.vertx.core.http.HttpServer) GreeterGrpc(io.grpc.examples.helloworld.GreeterGrpc) HelloRequest(io.grpc.examples.helloworld.HelloRequest) HttpServerOptions(io.vertx.core.http.HttpServerOptions) Router(io.vertx.ext.web.Router) RoutingContext(io.vertx.ext.web.RoutingContext) VertxChannelBuilder(io.vertx.grpc.VertxChannelBuilder) HelloRequest(io.grpc.examples.helloworld.HelloRequest) ManagedChannel(io.grpc.ManagedChannel) GreeterGrpc(io.grpc.examples.helloworld.GreeterGrpc)

Example 24 with ManagedChannel

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");
}
Also used : Awaitility.await(org.awaitility.Awaitility.await) ManagedChannel(io.grpc.ManagedChannel) Matchers.notNullValue(org.hamcrest.Matchers.notNullValue) Assertions.assertThat(org.assertj.core.api.Assertions.assertThat) Vertx(io.vertx.core.Vertx) GreeterGrpc(io.grpc.examples.helloworld.GreeterGrpc) HelloRequest(io.grpc.examples.helloworld.HelloRequest) IOException(java.io.IOException) AtomicReference(java.util.concurrent.atomic.AtomicReference) VertxChannelBuilder(io.vertx.grpc.VertxChannelBuilder) Assertions(io.fabric8.kubernetes.assertions.Assertions) TimeUnit(java.util.concurrent.TimeUnit) Kube.securedUrlForRoute(io.vertx.it.openshift.utils.Kube.securedUrlForRoute) HttpVersion(io.vertx.core.http.HttpVersion) AbstractTestClass(io.vertx.it.openshift.utils.AbstractTestClass) Matchers.is(org.hamcrest.Matchers.is) HttpClientOptions(io.vertx.core.http.HttpClientOptions) org.junit(org.junit) Kube.urlForRoute(io.vertx.it.openshift.utils.Kube.urlForRoute) HelloRequest(io.grpc.examples.helloworld.HelloRequest) ManagedChannel(io.grpc.ManagedChannel) GreeterGrpc(io.grpc.examples.helloworld.GreeterGrpc) AtomicReference(java.util.concurrent.atomic.AtomicReference)

Example 25 with ManagedChannel

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;
}
Also used : ManagedChannelBuilder(io.grpc.ManagedChannelBuilder) ManagedChannel(io.grpc.ManagedChannel)

Aggregations

ManagedChannel (io.grpc.ManagedChannel)163 Test (org.junit.Test)92 CountDownLatch (java.util.concurrent.CountDownLatch)26 ManagedChannel (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.ManagedChannel)26 ArrayList (java.util.ArrayList)20 Metadata (io.grpc.Metadata)18 EquivalentAddressGroup (io.grpc.EquivalentAddressGroup)15 ExecutorService (java.util.concurrent.ExecutorService)13 ByteString (com.google.protobuf.ByteString)12 Status (io.grpc.Status)12 StreamObserver (org.apache.beam.vendor.grpc.v1p43p2.io.grpc.stub.StreamObserver)11 StreamObserver (io.grpc.stub.StreamObserver)10 ConcurrentLinkedQueue (java.util.concurrent.ConcurrentLinkedQueue)10 AtomicReference (java.util.concurrent.atomic.AtomicReference)10 BeamFnApi (org.apache.beam.model.fnexecution.v1.BeamFnApi)10 CallOptions (io.grpc.CallOptions)9 Subchannel (io.grpc.LoadBalancer.Subchannel)9 SubchannelPicker (io.grpc.LoadBalancer.SubchannelPicker)9 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)9 Endpoints (org.apache.beam.model.pipeline.v1.Endpoints)9