Using PubSub API using protobuf + grpc (generated client) always fails

60 views
Skip to first unread message

Ankur Chauhan

unread,
Dec 17, 2015, 4:04:52 AM12/17/15
to Google APIs
I am attempting to use the google cloud pubsub service by using the service definitions at https://github.com/google/googleapis/blob/master/google/pubsub/v1/pubsub.proto

I am able to generate the client code and have the following code to get a topic:

            ManagedChannelImpl channelImpl = NettyChannelBuilder
                    .forAddress("pubsub.googleapis.com", 443)
                    .negotiationType(NegotiationType.TLS)
                    .build();
    
            ClientAuthInterceptor interceptor = new ClientAuthInterceptor(
                    GoogleCredentials.getApplicationDefault().createScoped(SCOPES),
                    ForkJoinPool.commonPool());
            Channel channel = ClientInterceptors.intercept(channelImpl, interceptor);
            PublisherBlockingClient publisher = newBlockingStub(channel);
            Topic topicInstance;
            try {
                topicInstance = publisher.getTopic(GetTopicRequest.newBuilder().setTopic(topic).build());
                if (topicInstance != null) {
                    logger.info("Found existing topic: {}", topicInstance.getName());
                    return publisher;
                }
            } catch (Exception ex) {
                logger.info("Unable to find topic: {}", topic);
            }

This always fails with a 404. The network traffic (in DEBUG logging) seems to confirm that the client is hitting the wrong endpoint (for a publish request):

    DEBUG 2015-12-17 00:58:07,962 [grpc-default-worker-ELG-0] i.g.n.NettyClientTransport: 
    ----------------OUTBOUND--------------------
    HEADERS: streamId=5, headers=DefaultHttp2Headers[:authority: pubsub.googleapis.com:443, :path: /google.pubsub.v1.Publisher/Publish, :method: POST, :scheme: https, authorization: Bearer ya29.TQIWiptEf4KsAKObPIaLaJRcq49SQ2vAutO4eIC-kgM4XwvX9p-9sFBR4eNfzE_yLiBs1A, content-type: application/grpc, te: trailers, user-agent: grpc-java-netty/0.9.0], streamDependency=0, weight=16, exclusive=false, padding=0, endStream=false
    ------------------------------------
    DEBUG 2015-12-17 00:58:07,975 [grpc-default-worker-ELG-0] i.g.n.NettyClientTransport: 
    ----------------OUTBOUND--------------------
    DATA: streamId=5, padding=0, endStream=true, length=725, bytes=00000002d00a136465765f616368617568616e2d6576656e747312b8050af9047b22486f7374223a226c6f63616c686f73743a3434303830222c22436f6e6e65...
    ------------------------------------
    DEBUG 2015-12-17 00:58:11,492 [grpc-default-worker-ELG-0] i.g.n.NettyClientTransport: 
    ----------------INBOUND--------------------
    HEADERS: streamId=5, headers=DefaultHttp2Headers[:status: 404, date: Thu, 17 Dec 2015 08:58:08 GMT, content-type: text/html; charset=UTF-8, server: ESF, content-length: 1595, x-xss-protection: 1; mode=block, x-frame-options: SAMEORIGIN, x-content-type-options: nosniff, alternate-protocol: 443:quic,p=1, alt-svc: quic=":443"; ma=604800; v="30,29,28,27,26,25"], padding=0, endStream=false
    ------------------------------------
    DEBUG 2015-12-17 00:58:26,357 [grpc-default-worker-ELG-0] i.g.n.NettyClientTransport: 
    ----------------INBOUND--------------------
    DATA: streamId=5, padding=0, endStream=true, length=1595, bytes=3c21444f43545950452068746d6c3e0a3c68746d6c206c616e673d656e3e0a20203c6d65746120636861727365743d7574662d383e0a20203c6d657461206e61...
    ------------------------------------
    DEBUG 2015-12-17 00:58:26,357 [grpc-default-worker-ELG-0] i.g.n.NettyClientTransport: 
    ----------------INBOUND--------------------
    PING: ack=false, length=8, bytes=0000000000000002
    ------------------------------------
    DEBUG 2015-12-17 00:58:26,358 [grpc-default-worker-ELG-0] i.g.n.NettyClientTransport: 
    ----------------OUTBOUND--------------------
    PING: ack=true, length=8, bytes=00000000000000

What am I doing wrong here? Is the pubsub over HTTP 2 (using the protobuf) supported?
Reply all
Reply to author
Forward
0 new messages