use of io.micronaut.gcp.pubsub.configuration.SubscriberConfigurationProperties in project micronaut-gcp by micronaut-projects.
the class DefaultSubscriberFactory method createSubscriber.
@Override
public Subscriber createSubscriber(SubscriberFactoryConfig config) {
Subscriber subscriber = subscribers.compute(config.getSubscriptionName(), (k, v) -> {
if (v == null) {
Subscriber.Builder builder = Subscriber.newBuilder(config.getSubscriptionName(), config.getReceiver()).setChannelProvider(this.transportChannelProvider).setCredentialsProvider(this.credentialsProvider);
Optional<SubscriberConfigurationProperties> subscriberConfiguration = beanContext.findBean(SubscriberConfigurationProperties.class, Qualifiers.byName(config.getSubscriberConfiguration()));
String executor = subscriberConfiguration.map(s -> s.getExecutor()).orElse(config.getDefaultExecutor());
ExecutorService executorService = beanContext.getBean(ExecutorService.class, Qualifiers.byName(executor));
if (!(executorService instanceof ScheduledExecutorService)) {
throw new IllegalStateException("Invalid Executor type provided, please make sure you have a ScheduledExecutorService configured for Subscriber: " + config.getSubscriptionName().getSubscription());
}
builder.setExecutorProvider(FixedExecutorProvider.create((ScheduledExecutorService) executorService));
if (subscriberConfiguration.isPresent()) {
SubscriberConfigurationProperties properties = subscriberConfiguration.get();
builder.setMaxAckExtensionPeriod(properties.getMaxAckExtensionPeriod());
builder.setParallelPullCount(properties.getParallelPullCount());
builder.setMaxDurationPerAckExtension(properties.getMaxDurationPerAckExtension());
builder.setFlowControlSettings(properties.getFlowControlSettings().build());
}
return builder.build();
}
throw new PubSubListenerException(String.format("Subscription %s is already registered for another" + " method", config.getSubscriptionName().toString()));
});
subscriber.startAsync();
return subscriber;
}
Aggregations