com.google.cloud.pubsub.v1.SubscriptionAdminSettings Java Examples

The following examples show how to use com.google.cloud.pubsub.v1.SubscriptionAdminSettings. 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: GcpPubSubAutoConfiguration.java    From spring-cloud-gcp with Apache License 2.0 6 votes vote down vote up
@Bean
@ConditionalOnMissingBean
public SubscriptionAdminClient subscriptionAdminClient(
		TransportChannelProvider transportChannelProvider) {
	try {
		return SubscriptionAdminClient.create(
				SubscriptionAdminSettings.newBuilder()
						.setCredentialsProvider(this.finalCredentialsProvider)
						.setHeaderProvider(this.headerProvider)
						.setTransportChannelProvider(transportChannelProvider)
						.build());
	}
	catch (IOException ioe) {
		throw new PubSubException("An error occurred while creating SubscriptionAdminClient.", ioe);
	}
}
 
Example #2
Source File: PubsubHelper.java    From flink with Apache License 2.0 5 votes vote down vote up
public SubscriptionAdminClient getSubscriptionAdminClient() throws IOException {
	if (subscriptionAdminClient == null) {
		SubscriptionAdminSettings subscriptionAdminSettings =
			SubscriptionAdminSettings
				.newBuilder()
				.setTransportChannelProvider(channelProvider)
				.setCredentialsProvider(NoCredentialsProvider.create())
				.build();
		subscriptionAdminClient = SubscriptionAdminClient.create(subscriptionAdminSettings);
	}
	return subscriptionAdminClient;
}
 
Example #3
Source File: PubSubManager.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
private static SubscriptionAdminClient buildSubscriptionAdminClient(final PubSubConfig config) {
    final SubscriptionAdminSettings.Builder subscriptionAdminSettingsBuilder = SubscriptionAdminSettings.newBuilder();

    buildCredentialsProvider(config).ifPresent(subscriptionAdminSettingsBuilder::setCredentialsProvider);
    buildTransportChannelProvider(config).ifPresent(subscriptionAdminSettingsBuilder::setTransportChannelProvider);

    try {
        return SubscriptionAdminClient.create(subscriptionAdminSettingsBuilder.build());
    } catch (final IOException e) {
        throw ex.illegalStateUnableToBuildSubscriptionAdminClient(e);
    }
}
 
Example #4
Source File: PubSubAdmin.java    From spring-cloud-gcp with Apache License 2.0 5 votes vote down vote up
/**
 * 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()));
}
 
Example #5
Source File: EmulatorHelper.java    From heroic with Apache License 2.0 5 votes vote down vote up
public static void deleteSubscription(
    String projectId, String subscriptionId, String endpoint
) throws IOException {
    SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create(
        SubscriptionAdminSettings.newBuilder()
            .setTransportChannelProvider(channelProvider(endpoint))
            .setCredentialsProvider(credentialsProvider)
            .build()
    );
    ProjectSubscriptionName subscriptionName = ProjectSubscriptionName.of(projectId, subscriptionId);
    subscriptionAdminClient.deleteSubscription(subscriptionName);
}
 
Example #6
Source File: Connection.java    From heroic with Apache License 2.0 5 votes vote down vote up
Connection(
    ConsumerSchema.Consumer consumer,
    ConsumerReporter reporter,
    AtomicLong errors,
    LongAdder consumed,
    String projectId,
    String topicId,
    String subscriptionId,
    int threads,
    long maxOutstandingElementCount,
    long maxOutstandingRequestBytes,
    int maxInboundMessageSize,
    long keepAlive
) {
    this.consumer = consumer;
    this.reporter = reporter;
    this.errors = errors;
    this.consumed = consumed;
    this.projectId = projectId;
    this.subscriptionId = subscriptionId;
    this.threads = threads;
    this.topicName = ProjectTopicName.of(projectId, topicId);
    this.subscriptionName = ProjectSubscriptionName.of(projectId, subscriptionId);
    this.credentialsProvider = SubscriptionAdminSettings
        .defaultCredentialsProviderBuilder()
        .build();
    this.channelProvider = SubscriptionAdminSettings
        .defaultGrpcTransportProviderBuilder()
        .setMaxInboundMessageSize(maxInboundMessageSize)
        .setKeepAliveTime(Duration.ofSeconds(keepAlive))
        .build();
    this.maxOutstandingElementCount = maxOutstandingElementCount;
    this.maxOutstandingRequestBytes = maxOutstandingRequestBytes;
}
 
Example #7
Source File: Connection.java    From heroic with Apache License 2.0 5 votes vote down vote up
void createSubscription() throws IOException {
    log.info("Creating subscription {} for topic {}", subscriptionName, topicName);
    SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create(
        SubscriptionAdminSettings.newBuilder()
          .setTransportChannelProvider(channelProvider)
          .setCredentialsProvider(credentialsProvider)
          .build()
    );
    try {
        subscriptionAdminClient.createSubscription(
            subscriptionName, topicName, PushConfig.getDefaultInstance(), 0);
    } catch (AlreadyExistsException e) {
        log.info("Subscription already exists");
    }
}
 
Example #8
Source File: PubSubSource.java    From datacollector with Apache License 2.0 5 votes vote down vote up
/**
 * Creates a channel provider shared by each subscriber. It is basically the default ChannelProvider with the
 * exception that it can be configured with a custom endpoint, for example when running against the PubSub Emulator.
 *
 * @return channel provider based on the stage configuration.
 */
private InstantiatingGrpcChannelProvider getChannelProvider() {
  return SubscriptionAdminSettings
      .defaultGrpcTransportProviderBuilder()
      .setMaxInboundMessageSize(MAX_INBOUND_MESSAGE_SIZE)
      .setEndpoint(Strings.isNullOrEmpty(conf.advanced.customEndpoint) ? SubscriptionAdminSettings
          .getDefaultEndpoint() : conf.advanced.customEndpoint)
      .build();
}
 
Example #9
Source File: PubsubHelper.java    From flink with Apache License 2.0 5 votes vote down vote up
public SubscriptionAdminClient getSubscriptionAdminClient() throws IOException {
	if (subscriptionAdminClient == null) {
		SubscriptionAdminSettings subscriptionAdminSettings =
			SubscriptionAdminSettings
				.newBuilder()
				.setTransportChannelProvider(channelProvider)
				.setCredentialsProvider(NoCredentialsProvider.create())
				.build();
		subscriptionAdminClient = SubscriptionAdminClient.create(subscriptionAdminSettings);
	}
	return subscriptionAdminClient;
}
 
Example #10
Source File: PubSubTestBinder.java    From spring-cloud-gcp with Apache License 2.0 4 votes vote down vote up
public PubSubTestBinder(String host) {
	GcpProjectIdProvider projectIdProvider = () -> "porto sentido";

	// Transport channel provider so that test binder talks to emulator.
	ManagedChannel channel = ManagedChannelBuilder
			.forTarget(host)
			.usePlaintext()
			.build();
	TransportChannelProvider transportChannelProvider =
			FixedTransportChannelProvider.create(GrpcTransportChannel.create(channel));

	PubSubChannelProvisioner pubSubChannelProvisioner;

	try {
		SubscriptionAdminClient subscriptionAdminClient = SubscriptionAdminClient.create(
				SubscriptionAdminSettings.newBuilder()
						.setTransportChannelProvider(transportChannelProvider)
						.setCredentialsProvider(NoCredentialsProvider.create())
						.build()
		);

		TopicAdminClient topicAdminClient = TopicAdminClient.create(
				TopicAdminSettings.newBuilder()
						.setTransportChannelProvider(transportChannelProvider)
						.setCredentialsProvider(NoCredentialsProvider.create())
						.build()
		);

		pubSubChannelProvisioner = new PubSubChannelProvisioner(
				new PubSubAdmin(projectIdProvider, topicAdminClient, subscriptionAdminClient)
		);
	}
	catch (IOException ioe) {
		throw new RuntimeException("Couldn't build test binder.", ioe);
	}

	DefaultSubscriberFactory subscriberFactory = new DefaultSubscriberFactory(projectIdProvider);
	subscriberFactory.setChannelProvider(transportChannelProvider);
	subscriberFactory.setCredentialsProvider(NoCredentialsProvider.create());

	DefaultPublisherFactory publisherFactory = new DefaultPublisherFactory(projectIdProvider);
	publisherFactory.setChannelProvider(transportChannelProvider);
	publisherFactory.setCredentialsProvider(NoCredentialsProvider.create());

	PubSubTemplate pubSubTemplate = new PubSubTemplate(publisherFactory, subscriberFactory);

	PubSubMessageChannelBinder binder =
			new PubSubMessageChannelBinder(null, pubSubChannelProvisioner, pubSubTemplate,
					new PubSubExtendedBindingProperties());
	GenericApplicationContext context = new GenericApplicationContext();
	binder.setApplicationContext(context);
	this.setBinder(binder);
}