Search in sources :

Example 1 with ClientFactory

use of io.grpc.examples.helloworld.Greeter.ClientFactory in project servicetalk by apple.

the class GrpcUdsTest method udsRoundTrip.

@Test
void udsRoundTrip() throws Exception {
    Assumptions.assumeTrue(ioExecutor.isUnixDomainSocketSupported());
    String greetingPrefix = "Hello ";
    String name = "foo";
    String expectedResponse = greetingPrefix + name;
    try (ServerContext serverContext = forAddress(newSocketAddress()).initializeHttp(builder -> builder.ioExecutor(ioExecutor)).listenAndAwait((GreeterService) (ctx, request) -> succeeded(HelloReply.newBuilder().setMessage(greetingPrefix + request.getName()).build()));
        BlockingGreeterClient client = forResolvedAddress(serverContext.listenAddress()).buildBlocking(new ClientFactory())) {
        assertEquals(expectedResponse, client.sayHello(HelloRequest.newBuilder().setName(name).build()).getMessage());
    }
}
Also used : AddressUtils.newSocketAddress(io.servicetalk.transport.netty.internal.AddressUtils.newSocketAddress) ServerContext(io.servicetalk.transport.api.ServerContext) ClientFactory(io.grpc.examples.helloworld.Greeter.ClientFactory) GreeterService(io.grpc.examples.helloworld.Greeter.GreeterService) HelloRequest(io.grpc.examples.helloworld.HelloRequest) GrpcClients.forResolvedAddress(io.servicetalk.grpc.netty.GrpcClients.forResolvedAddress) AfterAll(org.junit.jupiter.api.AfterAll) Test(org.junit.jupiter.api.Test) ExecutionException(java.util.concurrent.ExecutionException) BlockingGreeterClient(io.grpc.examples.helloworld.Greeter.BlockingGreeterClient) GrpcServers.forAddress(io.servicetalk.grpc.netty.GrpcServers.forAddress) IoExecutor(io.servicetalk.transport.api.IoExecutor) Assumptions(org.junit.jupiter.api.Assumptions) BeforeAll(org.junit.jupiter.api.BeforeAll) NettyIoExecutors.createIoExecutor(io.servicetalk.transport.netty.NettyIoExecutors.createIoExecutor) Single.succeeded(io.servicetalk.concurrent.api.Single.succeeded) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) HelloReply(io.grpc.examples.helloworld.HelloReply) Nullable(javax.annotation.Nullable) ServerContext(io.servicetalk.transport.api.ServerContext) ClientFactory(io.grpc.examples.helloworld.Greeter.ClientFactory) BlockingGreeterClient(io.grpc.examples.helloworld.Greeter.BlockingGreeterClient) Test(org.junit.jupiter.api.Test)

Example 2 with ClientFactory

use of io.grpc.examples.helloworld.Greeter.ClientFactory in project servicetalk by apple.

the class BlockingHelloWorldClient method main.

public static void main(String[] args) throws Exception {
    try (BlockingGreeterClient client = GrpcClients.forAddress("localhost", 8080).buildBlocking(new ClientFactory())) {
        HelloReply reply = client.sayHello(HelloRequest.newBuilder().setName("World").build());
        System.out.println(reply);
    }
}
Also used : ClientFactory(io.grpc.examples.helloworld.Greeter.ClientFactory) BlockingGreeterClient(io.grpc.examples.helloworld.Greeter.BlockingGreeterClient) HelloReply(io.grpc.examples.helloworld.HelloReply)

Aggregations

BlockingGreeterClient (io.grpc.examples.helloworld.Greeter.BlockingGreeterClient)2 ClientFactory (io.grpc.examples.helloworld.Greeter.ClientFactory)2 HelloReply (io.grpc.examples.helloworld.HelloReply)2 GreeterService (io.grpc.examples.helloworld.Greeter.GreeterService)1 HelloRequest (io.grpc.examples.helloworld.HelloRequest)1 Single.succeeded (io.servicetalk.concurrent.api.Single.succeeded)1 GrpcClients.forResolvedAddress (io.servicetalk.grpc.netty.GrpcClients.forResolvedAddress)1 GrpcServers.forAddress (io.servicetalk.grpc.netty.GrpcServers.forAddress)1 IoExecutor (io.servicetalk.transport.api.IoExecutor)1 ServerContext (io.servicetalk.transport.api.ServerContext)1 NettyIoExecutors.createIoExecutor (io.servicetalk.transport.netty.NettyIoExecutors.createIoExecutor)1 AddressUtils.newSocketAddress (io.servicetalk.transport.netty.internal.AddressUtils.newSocketAddress)1 ExecutionException (java.util.concurrent.ExecutionException)1 Nullable (javax.annotation.Nullable)1 AfterAll (org.junit.jupiter.api.AfterAll)1 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)1 Assumptions (org.junit.jupiter.api.Assumptions)1 BeforeAll (org.junit.jupiter.api.BeforeAll)1 Test (org.junit.jupiter.api.Test)1