com.google.pubsub.v1.PublisherGrpc Java Examples

The following examples show how to use com.google.pubsub.v1.PublisherGrpc. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PublisherServiceTest.java    From kafka-pubsub-emulator with Apache License 2.0 5 votes vote down vote up
@Before
public void setUp() {
  kafkaClientFactory = new MockKafkaClientFactory();
  publisher =
      new PublisherService(
          new ConfigurationManager(TestHelpers.SERVER_CONFIG, new FakePubSubRepository()),
          kafkaClientFactory,
          statisticsManager);
  grpcServerRule.getServiceRegistry().addService(publisher);
  blockingStub = PublisherGrpc.newBlockingStub(grpcServerRule.getChannel());
}
 
Example #2
Source File: PubsubGrpcClient.java    From beam with Apache License 2.0 5 votes vote down vote up
/** Return a stub for making a publish request with a timeout. */
private PublisherBlockingStub publisherStub() throws IOException {
  if (cachedPublisherStub == null) {
    cachedPublisherStub = PublisherGrpc.newBlockingStub(newChannel());
  }
  return cachedPublisherStub.withDeadlineAfter(timeoutSec, TimeUnit.SECONDS);
}
 
Example #3
Source File: Main.java    From cloud-pubsub-samples-java with Apache License 2.0 5 votes vote down vote up
public static void main(final String[] args) throws Exception {

        if (args.length == 0) {
            System.err.println("Please specify your project name.");
            System.exit(1);
        }
        final String project = args[0];
        ManagedChannelImpl channelImpl = NettyChannelBuilder
            .forAddress("pubsub.googleapis.com", 443)
            .negotiationType(NegotiationType.TLS)
            .build();
        GoogleCredentials creds = GoogleCredentials.getApplicationDefault();
        // Down-scope the credential to just the scopes required by the service
        creds = creds.createScoped(Arrays.asList("https://www.googleapis.com/auth/pubsub"));
        // Intercept the channel to bind the credential
        ExecutorService executor = Executors.newSingleThreadExecutor();
        ClientAuthInterceptor interceptor = new ClientAuthInterceptor(creds, executor);
        Channel channel = ClientInterceptors.intercept(channelImpl, interceptor);
        // Create a stub using the channel that has the bound credential
        PublisherGrpc.PublisherBlockingStub publisherStub = PublisherGrpc.newBlockingStub(channel);
        ListTopicsRequest request = ListTopicsRequest.newBuilder()
                .setPageSize(10)
                .setProject("projects/" + project)
                .build();
        ListTopicsResponse resp = publisherStub.listTopics(request);
        System.out.println("Found " + resp.getTopicsCount() + " topics.");
        for (Topic topic : resp.getTopicsList()) {
            System.out.println(topic.getName());
        }
    }
 
Example #4
Source File: PubsubEmulatorServer.java    From kafka-pubsub-emulator with Apache License 2.0 4 votes vote down vote up
/** Add status information to healthcheck for each service. */
private void startHealthcheckServices() {
  healthStatusManager.setStatus(PublisherGrpc.SERVICE_NAME, SERVING);
  healthStatusManager.setStatus(SubscriberGrpc.SERVICE_NAME, SERVING);
  healthStatusManager.setStatus(AdminGrpc.SERVICE_NAME, SERVING);
}
 
Example #5
Source File: GoogleAuthClient.java    From grpc-java with Apache License 2.0 2 votes vote down vote up
/**
 * Construct our gRPC client that connects to the pubsub server using an existing channel.
 *
 * @param channel    channel that has been built already
 * @param callCredentials  the Google call credentials created from a JSON file
 */
GoogleAuthClient(ManagedChannel channel, CallCredentials callCredentials) {
  this.channel = channel;
  blockingStub = PublisherGrpc.newBlockingStub(channel).withCallCredentials(callCredentials);
}