use of com.google.api.gax.core.ExecutorProvider in project moleculer-java by moleculer-java.
the class GoogleTransporter method getOrCreatePublisher.
protected Publisher getOrCreatePublisher(String channel) throws Exception {
Publisher publisher;
synchronized (publishers) {
publisher = publishers.get(channel);
if (publisher != null) {
return publisher;
}
TopicName topicName = TopicName.of(projectID, channel);
Publisher.Builder builder = Publisher.newBuilder(topicName);
if (batchingSettings != null) {
builder.setBatchingSettings(batchingSettings);
}
if (channelProvider != null) {
builder.setChannelProvider(channelProvider);
}
if (credentialsProvider != null) {
builder.setCredentialsProvider(credentialsProvider);
}
if (executorProvider != null) {
builder.setExecutorProvider(executorProvider);
} else {
builder.setExecutorProvider(new ExecutorProvider() {
@Override
public final boolean shouldAutoClose() {
return false;
}
@Override
public final ScheduledExecutorService getExecutor() {
return scheduler;
}
});
}
if (headerProvider != null) {
builder.setHeaderProvider(headerProvider);
}
if (retrySettings != null) {
builder.setRetrySettings(retrySettings);
}
publisher = builder.build();
publishers.put(channel, publisher);
}
return publisher;
}
use of com.google.api.gax.core.ExecutorProvider in project moleculer-java by moleculer-java.
the class GoogleTransporter method subscribe.
// --- SUBSCRIBE ---
@Override
public Promise subscribe(String channel) {
try {
// Create publisher
getOrCreatePublisher(channel);
// Create subscriber
synchronized (subscribers) {
if (!subscribers.containsKey(channel)) {
Subscriber.Builder builder = Subscriber.newBuilder(SubscriptionName.of(projectID, channel), (message, consumer) -> {
// Message received
byte[] bytes = message.getData().toByteArray();
received(channel, bytes);
consumer.ack();
});
builder.setChannelProvider(channelProvider);
builder.setCredentialsProvider(credentialsProvider);
if (executorProvider != null) {
builder.setExecutorProvider(executorProvider);
} else {
builder.setExecutorProvider(new ExecutorProvider() {
@Override
public final boolean shouldAutoClose() {
return false;
}
@Override
public final ScheduledExecutorService getExecutor() {
return scheduler;
}
});
}
if (headerProvider != null) {
builder.setHeaderProvider(headerProvider);
}
if (maxAckExtensionPeriod != null) {
builder.setMaxAckExtensionPeriod(maxAckExtensionPeriod);
}
if (parallelPullCount > 0) {
builder.setParallelPullCount(parallelPullCount);
}
if (executorProvider != null) {
builder.setSystemExecutorProvider(executorProvider);
} else {
builder.setSystemExecutorProvider(new ExecutorProvider() {
@Override
public final boolean shouldAutoClose() {
return false;
}
@Override
public final ScheduledExecutorService getExecutor() {
return scheduler;
}
});
}
Subscriber subscriber = builder.build();
subscriber.startAsync();
subscribers.put(channel, subscriber);
}
}
} catch (Exception cause) {
return Promise.reject(cause);
}
return Promise.resolve();
}
Aggregations