io.quarkus.amazon.sns.runtime.SnsClientProducer Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of quarkus-amazon-sns Show documentation
Show all versions of quarkus-amazon-sns Show documentation
Connect to Amazon SNS pub/sub messaging service
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