use of org.springframework.cloud.gcp.pubsub.core.PubSubDeliveryException in project spring-cloud-gcp by spring-cloud.
the class PubSubPublisherTemplate method publish.
@Override
public ListenableFuture<String> publish(final String topic, PubsubMessage pubsubMessage) {
Assert.hasText(topic, "The topic can't be null or empty.");
Assert.notNull(pubsubMessage, "The pubsubMessage can't be null.");
ApiFuture<String> publishFuture = this.publisherFactory.createPublisher(topic).publish(pubsubMessage);
final SettableListenableFuture<String> settableFuture = new SettableListenableFuture<>();
ApiFutures.addCallback(publishFuture, new ApiFutureCallback<String>() {
@Override
public void onFailure(Throwable throwable) {
String errorMessage = "Publishing to " + topic + " topic failed.";
LOGGER.warn(errorMessage, throwable);
PubSubDeliveryException pubSubDeliveryException = new PubSubDeliveryException(pubsubMessage, errorMessage, throwable);
settableFuture.setException(pubSubDeliveryException);
}
@Override
public void onSuccess(String result) {
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Publishing to " + topic + " was successful. Message ID: " + result);
}
settableFuture.set(result);
}
});
return settableFuture;
}
Aggregations