pl.allegro.tech.hermes.consumers.consumer.sender.googlepubsub.GooglePubSubMessageSender Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of hermes-consumers Show documentation
Show all versions of hermes-consumers Show documentation
Fast and reliable message broker built on top of Kafka.
package pl.allegro.tech.hermes.consumers.consumer.sender.googlepubsub;
import com.google.pubsub.v1.PubsubMessage;
import pl.allegro.tech.hermes.consumers.consumer.Message;
import pl.allegro.tech.hermes.consumers.consumer.sender.CompletableFutureAwareMessageSender;
import pl.allegro.tech.hermes.consumers.consumer.sender.MessageSendingResult;
import java.io.IOException;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.ExecutionException;
import static pl.allegro.tech.hermes.consumers.consumer.sender.MessageSendingResult.failedResult;
class GooglePubSubMessageSender implements CompletableFutureAwareMessageSender {
private final GooglePubSubClient googlePubSubClient;
private final GooglePubSubSenderTarget resolvedTarget;
private final GooglePubSubClientsPool clientsPool;
private final GooglePubSubMessageTransformer messageTransformer;
GooglePubSubMessageSender(GooglePubSubSenderTarget resolvedTarget,
GooglePubSubClientsPool clientsPool,
GooglePubSubMessageTransformer messageTransformer) throws IOException {
this.googlePubSubClient = clientsPool.acquire(resolvedTarget);
this.resolvedTarget = resolvedTarget;
this.clientsPool = clientsPool;
this.messageTransformer = messageTransformer;
}
@Override
public void send(Message message, CompletableFuture resultFuture) {
try {
PubsubMessage pubsubMessage = messageTransformer.fromHermesMessage(message);
googlePubSubClient.publish(pubsubMessage, resultFuture);
} catch (IOException | ExecutionException | InterruptedException exception) {
resultFuture.complete(failedResult(exception));
}
}
@Override
public void stop() {
clientsPool.release(resolvedTarget);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy