com.google.pubsub.v1.TopicName Java Examples
The following examples show how to use
com.google.pubsub.v1.TopicName.
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: UsePubSubEmulatorSnippet.java From google-cloud-java with Apache License 2.0 | 5 votes |
public static void main(String... args) throws IOException { // [START pubsub_use_emulator] String hostport = System.getenv("PUBSUB_EMULATOR_HOST"); ManagedChannel channel = ManagedChannelBuilder.forTarget(hostport).usePlaintext().build(); try { TransportChannelProvider channelProvider = FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel)); CredentialsProvider credentialsProvider = NoCredentialsProvider.create(); // Set the channel and credentials provider when creating a `TopicAdminClient`. // Similarly for SubscriptionAdminClient TopicAdminClient topicClient = TopicAdminClient.create( TopicAdminSettings.newBuilder() .setTransportChannelProvider(channelProvider) .setCredentialsProvider(credentialsProvider) .build()); TopicName topicName = TopicName.of("my-project-id", "my-topic-id"); // Set the channel and credentials provider when creating a `Publisher`. // Similarly for Subscriber Publisher publisher = Publisher.newBuilder(topicName) .setChannelProvider(channelProvider) .setCredentialsProvider(credentialsProvider) .build(); } finally { channel.shutdown(); } // [END pubsub_use_emulator] }