/** Constructs an instance of TopicAdminClient with default settings. */ public static final TopicAdminClient create() throws IOException { return create(TopicAdminSettings.newBuilder().build()); }
TopicAdminSettings.newBuilder() .setTransportChannelProvider(channelProvider) .setCredentialsProvider(credentialsProvider)
@Before public void setUp() throws IOException { serviceHelper.reset(); channelProvider = serviceHelper.createChannelProvider(); TopicAdminSettings settings = TopicAdminSettings.newBuilder() .setTransportChannelProvider(channelProvider) .setCredentialsProvider(NoCredentialsProvider.create()) .build(); client = TopicAdminClient.create(settings); }
@Bean @ConditionalOnMissingBean public TopicAdminSettings topicAdminSettings( TransportChannelProvider transportChannelProvider) { try { return TopicAdminSettings.newBuilder() .setCredentialsProvider(this.finalCredentialsProvider) .setHeaderProvider(this.headerProvider) .setTransportChannelProvider(transportChannelProvider) .build(); } catch (IOException ioe) { throw new PubSubException("An error occurred while creating TopicAdminSettings.", ioe); } }
@Provides @Singleton public TopicAdminClient getClient() throws IOException { final TopicAdminSettings.Builder adminSetting = TopicAdminSettings.newBuilder(); final String emulatorHost = System.getenv("PUBSUB_EMULATOR_HOST"); if (emulatorHost != null) { ManagedChannel channel = ManagedChannelBuilder.forTarget(emulatorHost).usePlaintext().build(); TransportChannelProvider channelProvider = FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel)); adminSetting.setTransportChannelProvider(channelProvider); adminSetting.setCredentialsProvider(NoCredentialsProvider.create()); } return TopicAdminClient.create(adminSetting.build()); }
/** * This constructor instantiates TopicAdminClient and SubscriptionAdminClient with all their * defaults and the provided credentials provider. * @param projectIdProvider the project id provider to use * @param credentialsProvider the credentials provider to use * @throws IOException thrown when there are errors in contacting Google Cloud Pub/Sub */ public PubSubAdmin(GcpProjectIdProvider projectIdProvider, CredentialsProvider credentialsProvider) throws IOException { this(projectIdProvider, TopicAdminClient.create( TopicAdminSettings.newBuilder() .setCredentialsProvider(credentialsProvider) .build()), SubscriptionAdminClient.create( SubscriptionAdminSettings.newBuilder() .setCredentialsProvider(credentialsProvider) .build())); }
/** * This constructor instantiates TopicAdminClient and SubscriptionAdminClient with all their * defaults and the provided credentials provider. * @param projectIdProvider the project id provider to use * @param credentialsProvider the credentials provider to use * @throws IOException thrown when there are errors in contacting Google Cloud Pub/Sub */ public PubSubAdmin(GcpProjectIdProvider projectIdProvider, CredentialsProvider credentialsProvider) throws IOException { this(projectIdProvider, TopicAdminClient.create( TopicAdminSettings.newBuilder() .setCredentialsProvider(credentialsProvider) .build()), SubscriptionAdminClient.create( SubscriptionAdminSettings.newBuilder() .setCredentialsProvider(credentialsProvider) .build())); }