software.amazon.awssdk.services.sns.SnsAsyncClient Java Examples

The following examples show how to use software.amazon.awssdk.services.sns.SnsAsyncClient. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: SnsConnector.java    From smallrye-reactive-messaging with Apache License 2.0 6 votes vote down vote up
/**
 * Send message to the SNS Topic.
 *
 * @param message Message to be sent, must not be {@code null}
 * @return the CompletionStage of sending message.
 */
private CompletionStage<Message<?>> send(Message<?> message, String topic, String snsUrl, boolean mock) {
    SnsClientConfig clientConfig = new SnsClientConfig(snsUrl, mock);
    SnsAsyncClient client = SnsClientManager.get().getAsyncClient(clientConfig);

    CreateTopicRequest topicCreationRequest = CreateTopicRequest.builder().name(topic).build();
    return client.createTopic(topicCreationRequest)
            .thenApply(CreateTopicResponse::topicArn)
            .thenCompose(arn -> client.publish(PublishRequest
                    .builder()
                    .topicArn(arn)
                    .message((String) message.getPayload())
                    .build()))
            .thenApply(resp -> {
                log.successfullySend(resp.messageId());
                return message;
            });
}
 
Example #2
Source File: SnsClientFactory.java    From micronaut-aws with Apache License 2.0 5 votes vote down vote up
@Override
@Bean(preDestroy = "close")
@Singleton
@Requires(beans = SdkAsyncHttpClient.class)
public SnsAsyncClient asyncClient(SnsAsyncClientBuilder builder) {
    return super.asyncClient(builder);
}
 
Example #3
Source File: SnsVerticle.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
@Override
public void start(Promise<Void> startFuture) {
    Router router = Router.router(vertx);
    router.route()
            .handler(BodyHandler.create())
            .method(HttpMethod.POST);
    router.head().handler(rc -> rc.response().setStatusCode(204).end());
    router.post(String.format("/sns/%s", topic)).handler(this::receiveSnsMsg);

    SnsClientConfig clientCfg = new SnsClientConfig(snsUrl, mockSns);
    SnsAsyncClient snsClient = SnsClientManager.get().getAsyncClient(clientCfg);
    CreateTopicRequest topicCreationRequest = CreateTopicRequest.builder().name(topic).build();
    CompletableFuture<CreateTopicResponse> topicCreationResponse = snsClient.createTopic(topicCreationRequest);
    topicCreationResponse
            .thenCompose(res -> {
                arn = res.topicArn();
                topicEndpoint = mockSns ? String.format("%s:%d/sns/%s", endpoint, port, topic)
                        : String.format("%s/sns/%s", endpoint, topic);
                log.topicAndEndpointInfo(arn, topicEndpoint);
                return isSubscribed(snsClient, arn);
            })
            .thenCompose(subscribed -> {
                if (!subscribed) {
                    log.subscribingToTopic(topicEndpoint, arn);
                    return snsClient.subscribe(SubscribeRequest
                            .builder()
                            .topicArn(arn)
                            .endpoint(topicEndpoint)
                            .protocol("http")
                            .build()).thenApply(x -> null);
                } else {
                    return CompletableFuture.completedFuture(null);
                }
            }).thenAccept(x -> vertx.createHttpServer()
                    .requestHandler(router)
                    .listen(port, ar -> startFuture.handle(ar.mapEmpty())));
}
 
Example #4
Source File: SnsVerticle.java    From smallrye-reactive-messaging with Apache License 2.0 5 votes vote down vote up
private CompletionStage<Boolean> isSubscribed(SnsAsyncClient sns, String arn) {
    String fullEndpoint = String.format("%s/sns/%s", endpoint, topic);
    CompletableFuture<ListSubscriptionsByTopicResponse> result = sns.listSubscriptionsByTopic(
            ListSubscriptionsByTopicRequest.builder().topicArn(arn).build());
    return result.thenApply(list -> {
        List<Subscription> subscriptions = list.subscriptions();
        return subscriptions.stream().anyMatch(s -> s.endpoint().equalsIgnoreCase(fullEndpoint));
    });
}
 
Example #5
Source File: SnsRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<AwsClientBuilder> createAsyncBuilder(SnsConfig config,
        RuntimeValue<SdkAsyncHttpClient.Builder> transport) {

    SnsAsyncClientBuilder builder = SnsAsyncClient.builder();

    if (transport != null) {
        builder.httpClientBuilder(transport.getValue());
    }
    return new RuntimeValue<>(builder);
}
 
Example #6
Source File: SnsRecorder.java    From quarkus with Apache License 2.0 5 votes vote down vote up
public RuntimeValue<SnsAsyncClient> buildAsyncClient(RuntimeValue<? extends AwsClientBuilder> builder,
        BeanContainer beanContainer,
        ShutdownContext shutdown) {
    SnsClientProducer producer = beanContainer.instance(SnsClientProducer.class);
    producer.setAsyncConfiguredBuilder((SnsAsyncClientBuilder) builder.getValue());
    shutdown.addShutdownTask(producer::destroy);
    return new RuntimeValue<>(producer.asyncClient());
}
 
Example #7
Source File: BasicSnsAsyncClientProvider.java    From beam with Apache License 2.0 5 votes vote down vote up
@Override
public SnsAsyncClient getSnsAsyncClient() {
  SnsAsyncClientBuilder builder =
      SnsAsyncClient.builder()
          .credentialsProvider(awsCredentialsProvider)
          .region(Region.of(region));

  if (serviceEndpoint != null) {
    builder.endpointOverride(serviceEndpoint);
  }

  return builder.build();
}
 
Example #8
Source File: SnsClientFactory.java    From micronaut-aws with Apache License 2.0 4 votes vote down vote up
@Override
protected SnsAsyncClientBuilder createAsyncBuilder() {
    return SnsAsyncClient.builder();
}
 
Example #9
Source File: SnsProcessor.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Override
protected DotName asyncClientName() {
    return DotName.createSimple(SnsAsyncClient.class.getName());
}
 
Example #10
Source File: SnsClientProducer.java    From quarkus with Apache License 2.0 4 votes vote down vote up
@Produces
@ApplicationScoped
public SnsAsyncClient asyncClient() {
    asyncClient = asyncConfiguredBuilder.build();
    return asyncClient;
}
 
Example #11
Source File: SnsAsyncClientProvider.java    From beam with Apache License 2.0 votes vote down vote up
SnsAsyncClient getSnsAsyncClient();