Search in sources :

Example 1 with PubSubException

use of com.google.cloud.spring.pubsub.core.PubSubException in project spring-cloud-gcp by GoogleCloudPlatform.

the class DefaultPublisherFactory method createPublisher.

/**
 * Creates a {@link Publisher} for a given topic.
 *
 * <p></p>Configuration precedence:
 * <ol>
 *   <li>modifications applied by the factory customizers
 *   <li>{@code spring.cloud.gcp.pubsub.publisher} configuration options
 *   <li>client library defaults
 *</ol>
 *
 * @param topic destination topic
 * @return fully configured publisher
 */
@Override
public Publisher createPublisher(String topic) {
    try {
        Publisher.Builder publisherBuilder = Publisher.newBuilder(PubSubTopicUtils.toTopicName(topic, this.projectId));
        applyPublisherSettings(publisherBuilder);
        applyCustomizers(publisherBuilder, topic);
        return publisherBuilder.build();
    } catch (IOException ioe) {
        throw new PubSubException("An error creating the Google Cloud Pub/Sub publisher " + "occurred.", ioe);
    }
}
Also used : PubSubException(com.google.cloud.spring.pubsub.core.PubSubException) Publisher(com.google.cloud.pubsub.v1.Publisher) IOException(java.io.IOException)

Aggregations

Publisher (com.google.cloud.pubsub.v1.Publisher)1 PubSubException (com.google.cloud.spring.pubsub.core.PubSubException)1 IOException (java.io.IOException)1