Can someone please provide an example of limiting the number of pulling pubsub threads with the new API so we can start testing?
In the old API it was possible to limit the number of concurrent threads that pulled messages with the following code:
PubSub.MessageConsumer consumer = pubsub.pullAsync(
subscription,
messageProcessor,
PubSub.PullOption.maxQueuedCallbacks(maxQueuedCallbacks),
PubSub.PullOption.executorFactory(executorFactory)
);
where maxQueuedCallbacks was an integer amount of msgs to pull and
executorFactory was provided from this
/**
* Create an ExecutorFactory instance for use with a single
* {@link PubSub.MessageConsumer}.
*
* <p>The number of threads in the executor determines how many messages can be processed at one
* time.</p>
*
* @see PubSub.PullOption#executorFactory(ExecutorFactory)
*/
private static ExecutorFactory<ExecutorService> createExecutor(
final int threads,
final String threadNameFormat) {
final ThreadFactory threadFactory = new ThreadFactoryBuilder()
.setDaemon(true)
.setNameFormat(threadNameFormat)
.build();
final ExecutorService executorService = Executors.newFixedThreadPool(threads, threadFactory);
return new ExecutorFactory<ExecutorService>() {
@Override
public ExecutorService get() {
return executorService;
}
@Override
public void release(final ExecutorService executor) {
executorService.shutdownNow();
}
};
}
Can someone please provide an example of limiting the number of pulling pubsub threads with the new API so we can start testing?
In the old API it was possible to limit the number of concurrent threads that pulled messages with the following code:
where maxQueuedCallbackswas an integer amount of msgs to pull andexecutorFactorywas provided from this