Search in sources :

Example 1 with SubscriberInterface

use of com.google.cloud.pubsub.v1.SubscriberInterface in project micronaut-gcp by micronaut-projects.

the class DefaultSubscriberFactory method close.

@PreDestroy
@Override
public void close() throws Exception {
    while (!subscribers.entrySet().isEmpty()) {
        Iterator<Map.Entry<ProjectSubscriptionName, Subscriber>> it = subscribers.entrySet().iterator();
        while (it.hasNext()) {
            Map.Entry<ProjectSubscriptionName, Subscriber> entry = it.next();
            SubscriberInterface subscriber = entry.getValue();
            try {
                subscriber.stopAsync().awaitTerminated();
            } catch (Exception e) {
                logger.error("Failed stopping subscriber for " + entry.getKey(), e);
            } finally {
                it.remove();
            }
        }
    }
}
Also used : ProjectSubscriptionName(com.google.pubsub.v1.ProjectSubscriptionName) Subscriber(com.google.cloud.pubsub.v1.Subscriber) SubscriberInterface(com.google.cloud.pubsub.v1.SubscriberInterface) ConcurrentHashMap(java.util.concurrent.ConcurrentHashMap) Map(java.util.Map) PubSubListenerException(io.micronaut.gcp.pubsub.exception.PubSubListenerException) PreDestroy(javax.annotation.PreDestroy)

Aggregations

Subscriber (com.google.cloud.pubsub.v1.Subscriber)1 SubscriberInterface (com.google.cloud.pubsub.v1.SubscriberInterface)1 ProjectSubscriptionName (com.google.pubsub.v1.ProjectSubscriptionName)1 PubSubListenerException (io.micronaut.gcp.pubsub.exception.PubSubListenerException)1 Map (java.util.Map)1 ConcurrentHashMap (java.util.concurrent.ConcurrentHashMap)1 PreDestroy (javax.annotation.PreDestroy)1