All Downloads are FREE. Search and download functionalities are using the official Maven repository.

io.quarkus.amazon.sns.runtime.SnsClientProducer Maven / Gradle / Ivy

There is a newer version: 3.2.0
Show newest version
package io.quarkus.amazon.sns.runtime;

import jakarta.annotation.PreDestroy;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.enterprise.inject.Instance;
import jakarta.enterprise.inject.Produces;

import io.quarkus.arc.DefaultBean;
import software.amazon.awssdk.services.sns.SnsAsyncClient;
import software.amazon.awssdk.services.sns.SnsAsyncClientBuilder;
import software.amazon.awssdk.services.sns.SnsClient;
import software.amazon.awssdk.services.sns.SnsClientBuilder;

@ApplicationScoped
public class SnsClientProducer {
    private final SnsClient syncClient;
    private final SnsAsyncClient asyncClient;

    SnsClientProducer(Instance syncClientBuilderInstance,
            Instance asyncClientBuilderInstance) {
        this.syncClient = syncClientBuilderInstance.isResolvable() ? syncClientBuilderInstance.get().build() : null;
        this.asyncClient = asyncClientBuilderInstance.isResolvable() ? asyncClientBuilderInstance.get().build() : null;
    }

    @DefaultBean
    @Produces
    @ApplicationScoped
    public SnsClient client() {
        if (syncClient == null) {
            throw new IllegalStateException("The SnsClient is required but has not been detected/configured.");
        }
        return syncClient;
    }

    @DefaultBean
    @Produces
    @ApplicationScoped
    public SnsAsyncClient asyncClient() {
        if (asyncClient == null) {
            throw new IllegalStateException("The SnsAsyncClient is required but has not been detected/configured.");
        }
        return asyncClient;
    }

    @PreDestroy
    public void destroy() {
        if (syncClient != null) {
            syncClient.close();
        }
        if (asyncClient != null) {
            asyncClient.close();
        }
    }
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy