Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating topic on pubsub emulator

I started to use the pubsub emulator to test my basic implementations and ran into an issue while trying to create a new topic.

My emulator listens on localhost:8085 and if i create the topic via the api

PUT http://localhost:8085/v1/projects/testproject/topics/test

everything works fine and the topic gets created. But if i run the following snippet nothing works as intended and no topic gets created:

    TopicName topicName = TopicName.create("testproject", "test");
    ChannelProvider channelProvider =
            TopicAdminSettings.defaultChannelProviderBuilder()
                .setEndpoint("localhost:8085")
                .setCredentialsProvider(
                        FixedCredentialsProvider.create(NoCredentials.getInstance()))
                .build();
    TopicAdminClient topicClient = TopicAdminClient.create(
            TopicAdminSettings.defaultBuilder().setChannelProvider(channelProvider).build());
        topicClient.createTopic(topicName);

while running this the emulator logs

[pubsub] Apr 27, 2017 1:10:47 PM io.gapi.emulators.grpc.GrpcServer$3 operationComplete
[pubsub] INFORMATION: Adding handler(s) to newly registered Channel.
[pubsub] Apr 27, 2017 1:10:47 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
[pubsub] INFORMATION: Detected non-HTTP/2 connection.
[pubsub] Apr 27, 2017 1:10:47 PM io.gapi.emulators.netty.NotFoundHandler handleRequest
[pubsub] INFORMATION: Unknown request URI: /bad-request
[pubsub] Apr 27, 2017 1:10:47 PM io.gapi.emulators.grpc.GrpcServer$3 operationComplete
[pubsub] INFORMATION: Adding handler(s) to newly registered Channel.
[pubsub] Apr 27, 2017 1:10:47 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
[pubsub] INFORMATION: Detected non-HTTP/2 connection.
[pubsub] Apr 27, 2017 1:10:47 PM io.gapi.emulators.netty.NotFoundHandler handleRequest
[pubsub] INFORMATION: Unknown request URI: /bad-request

...    

[pubsub] Apr 27, 2017 1:10:49 PM io.gapi.emulators.grpc.GrpcServer$3 operationComplete
[pubsub] INFORMATION: Adding handler(s) to newly registered Channel.
[pubsub] Apr 27, 2017 1:10:49 PM io.gapi.emulators.netty.HttpVersionRoutingHandler channelRead
[pubsub] INFORMATION: Detected non-HTTP/2 connection.

Am i missing something on my ChannelProvider? Or didn't I configure my TopicAdminClient correctly? I don't see whats wrong since i used this as reference.

Maybe someone can help me out with this.

like image 962
T. Yoo Avatar asked Apr 27 '17 11:04

T. Yoo


People also ask

What is topic in pub sub?

In a pub/sub model, any message published to a topic is immediately received by all of the subscribers to the topic. Pub/sub messaging can be used to enable event-driven architectures, or to decouple applications in order to increase performance, reliability and scalability.

Can Pubsub hold millions of messages?

There is no limit on the number of retained messages.


1 Answers

Channels used to communicate with the emulator need to set the negotiationType property to NegotiationType.PLAINTEXT. That means you need to create a custom ChannelProvider. Something like the following should work:

public class PlainTextChannelProvider implements ChannelProvider {
  @Override
  public boolean shouldAutoClose() {
    return false;
  }

  @Override
  public boolean needsExecutor() {
    return false;
  }

  @Override
  public ManagedChannel getChannel() throws IOException {
    return NettyChannelBuilder.forAddress("localhost", 8085)
      .negotiationType(NegotiationType.PLAINTEXT)
      .build();
  }

  @Override
  public ManagedChannel getChannel(Executor executor) throws IOException {
    return getChannel();
  }
}
like image 56
Kamal Aboul-Hosn Avatar answered Sep 29 '22 11:09

Kamal Aboul-Hosn