Search in sources :

Example 16 with DynamoDbAsyncClient

use of software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient in project graylog-plugin-integrations by Graylog2.

the class KinesisConsumer method run.

public void run() {
    LOG.debug("Starting the Kinesis Consumer.");
    AwsCredentialsProvider credentialsProvider = AWSAuthFactory.create(request.region(), request.awsAccessKeyId(), request.awsSecretAccessKey(), request.assumeRoleArn());
    final Region region = Region.of(request.region());
    final DynamoDbAsyncClientBuilder dynamoDbClientBuilder = DynamoDbAsyncClient.builder();
    AWSClientBuilderUtil.initializeBuilder(dynamoDbClientBuilder, request.dynamodbEndpoint(), region, credentialsProvider);
    final DynamoDbAsyncClient dynamoClient = dynamoDbClientBuilder.build();
    final CloudWatchAsyncClientBuilder cloudwatchClientBuilder = CloudWatchAsyncClient.builder();
    AWSClientBuilderUtil.initializeBuilder(cloudwatchClientBuilder, request.cloudwatchEndpoint(), region, credentialsProvider);
    final CloudWatchAsyncClient cloudWatchClient = cloudwatchClientBuilder.build();
    final KinesisAsyncClientBuilder kinesisAsyncClientBuilder = KinesisAsyncClient.builder();
    AWSClientBuilderUtil.initializeBuilder(kinesisAsyncClientBuilder, request.kinesisEndpoint(), region, credentialsProvider);
    final KinesisAsyncClient kinesisAsyncClient = KinesisClientUtil.createKinesisAsyncClient(kinesisAsyncClientBuilder);
    final String workerId = String.format(Locale.ENGLISH, "graylog-node-%s", nodeId.anonymize());
    LOG.debug("Using workerId [{}].", workerId);
    // The application name needs to be unique per input/consumer.
    final String applicationName = String.format(Locale.ENGLISH, "graylog-aws-plugin-%s", kinesisStreamName);
    LOG.debug("Using Kinesis applicationName [{}].", applicationName);
    // The KinesisShardProcessorFactory contains the message processing logic.
    final KinesisShardProcessorFactory kinesisShardProcessorFactory = new KinesisShardProcessorFactory(objectMapper, transport, handleMessageCallback, kinesisStreamName, awsMessageType);
    ConfigsBuilder configsBuilder = new ConfigsBuilder(kinesisStreamName, applicationName, kinesisAsyncClient, dynamoClient, cloudWatchClient, workerId, kinesisShardProcessorFactory);
    final PollingConfig pollingConfig = new PollingConfig(kinesisStreamName, kinesisAsyncClient);
    // Default max records per request is 10k.
    if (recordBatchSize != null) {
        LOG.debug("Using explicit batch size [{}]", recordBatchSize);
        pollingConfig.maxRecords(recordBatchSize);
    }
    this.kinesisScheduler = new Scheduler(configsBuilder.checkpointConfig(), configsBuilder.coordinatorConfig(), configsBuilder.leaseManagementConfig(), configsBuilder.lifecycleConfig(), configsBuilder.metricsConfig(), configsBuilder.processorConfig(), configsBuilder.retrievalConfig().retrievalSpecificConfig(pollingConfig));
    LOG.debug("Starting Kinesis scheduler.");
    kinesisScheduler.run();
    LOG.debug("After Kinesis scheduler stopped.");
}
Also used : KinesisAsyncClient(software.amazon.awssdk.services.kinesis.KinesisAsyncClient) CloudWatchAsyncClient(software.amazon.awssdk.services.cloudwatch.CloudWatchAsyncClient) Scheduler(software.amazon.kinesis.coordinator.Scheduler) PollingConfig(software.amazon.kinesis.retrieval.polling.PollingConfig) ConfigsBuilder(software.amazon.kinesis.common.ConfigsBuilder) CloudWatchAsyncClientBuilder(software.amazon.awssdk.services.cloudwatch.CloudWatchAsyncClientBuilder) AwsCredentialsProvider(software.amazon.awssdk.auth.credentials.AwsCredentialsProvider) DynamoDbAsyncClient(software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient) Region(software.amazon.awssdk.regions.Region) DynamoDbAsyncClientBuilder(software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClientBuilder) KinesisAsyncClientBuilder(software.amazon.awssdk.services.kinesis.KinesisAsyncClientBuilder)

Example 17 with DynamoDbAsyncClient

use of software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient in project aws-sdk by reactiverse.

the class VertxDynamoClientSpec method listTables.

@Test
@Timeout(value = 15, timeUnit = TimeUnit.SECONDS)
@Order(2)
public void listTables(Vertx vertx, VertxTestContext ctx) throws Exception {
    final Context originalContext = vertx.getOrCreateContext();
    final DynamoDbAsyncClient dynamo = dynamo(originalContext);
    single(dynamo.listTables()).subscribe(listResp -> {
        assertContext(vertx, originalContext, ctx);
        ctx.verify(() -> {
            assertTrue(listResp.tableNames().contains(TABLE_NAME));
            ctx.completeNow();
        });
    }, ctx::failNow);
}
Also used : VertxTestContext(io.vertx.junit5.VertxTestContext) Context(io.vertx.core.Context) DynamoDbAsyncClient(software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient) Order(org.junit.jupiter.api.Order) TestMethodOrder(org.junit.jupiter.api.TestMethodOrder) Test(org.junit.jupiter.api.Test) Timeout(io.vertx.junit5.Timeout)

Example 18 with DynamoDbAsyncClient

use of software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient in project aws-doc-sdk-examples by awsdocs.

the class AsyncPagination method AutoPaginationOnCollection.

private static void AutoPaginationOnCollection() throws InterruptedException, ExecutionException {
    // snippet-start:[dynamodb.java2.async_pagination.asyncclient]
    System.out.println("running AutoPagination - iterating on item collection...\n");
    // Creates a default client with credentials and regions loaded from the environment
    final DynamoDbAsyncClient asyncClient = DynamoDbAsyncClient.create();
    ListTablesRequest listTablesRequest = ListTablesRequest.builder().limit(3).build();
    // snippet-end:[dynamodb.java2.async_pagination.asyncclient]
    ListTablesPublisher listTablesPublisher = asyncClient.listTablesPaginator(listTablesRequest);
    SdkPublisher<String> publisher = listTablesPublisher.tableNames();
    // snippet-start:[dynamodb.java2.async_pagination.foreach]
    // Use forEach
    CompletableFuture<Void> future = publisher.subscribe(System.out::println);
    future.get();
    // snippet-end:[dynamodb.java2.async_pagination.foreach]
    // snippet-start:[dynamodb.java2.async_pagination.subscriber]
    // Use subscriber
    publisher.subscribe(new Subscriber<String>() {

        private Subscription subscription;

        @Override
        public void onSubscribe(Subscription s) {
            subscription = s;
            subscription.request(1);
        }

        @Override
        public void onNext(String tableName) {
            System.out.println(tableName);
            subscription.request(1);
        }

        @Override
        public void onError(Throwable t) {
        }

        @Override
        public void onComplete() {
        }
    });
    // As the above code is non-blocking, make sure your application doesn't end immediately
    // For this example, I am using Thread.sleep to wait for all pages to get delivered
    Thread.sleep(3_000);
}
Also used : DynamoDbAsyncClient(software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient) ListTablesRequest(software.amazon.awssdk.services.dynamodb.model.ListTablesRequest) Subscription(org.reactivestreams.Subscription) ListTablesPublisher(software.amazon.awssdk.services.dynamodb.paginators.ListTablesPublisher)

Example 19 with DynamoDbAsyncClient

use of software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient in project aws-doc-sdk-examples by awsdocs.

the class DynamoDBAsyncGetItem method main.

public static void main(String[] args) {
    final String USAGE = "\n" + "Usage:\n" + "    DynamoDBAsyncGetItem <table> <key> <keyVal>\n\n" + "Where:\n" + "    table - the table from which an item is retrieved (i.e., Music3)\n" + "    key -  the key used in the table (i.e., Artist) \n" + "    keyval  - the key value that represents the item to get (i.e., Famous Band)\n" + " Example:\n" + "    Music3 Artist Famous Band\n" + "  **Warning** This program will actually retrieve an item\n" + "            that you specify!\n";
    if (args.length < 3) {
        System.out.println(USAGE);
        System.exit(1);
    }
    String tableName = args[0];
    String key = args[1];
    String keyVal = args[2];
    // Create the DynamoDbAsyncClient object
    Region region = Region.US_WEST_2;
    DynamoDbAsyncClient client = DynamoDbAsyncClient.builder().region(region).build();
    System.out.format("Retrieving item \"%s\" from \"%s\"\n", keyVal, tableName);
    getItem(client, tableName, key, keyVal);
}
Also used : DynamoDbAsyncClient(software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient) Region(software.amazon.awssdk.regions.Region)

Example 20 with DynamoDbAsyncClient

use of software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient in project aws-doc-sdk-examples by awsdocs.

the class DynamoDBAsyncTest method DynamoDBAsyncListTables.

@Test
@Order(3)
public void DynamoDBAsyncListTables() {
    Region region = Region.US_WEST_2;
    DynamoDbAsyncClient client = DynamoDbAsyncClient.builder().region(region).build();
    DynamoDBAsyncListTables.listTables(client);
    System.out.println("Test 3 passed");
}
Also used : DynamoDbAsyncClient(software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient) Region(software.amazon.awssdk.regions.Region)

Aggregations

DynamoDbAsyncClient (software.amazon.awssdk.services.dynamodb.DynamoDbAsyncClient)32 Region (software.amazon.awssdk.regions.Region)9 ExecutorService (java.util.concurrent.ExecutorService)7 Test (org.junit.jupiter.api.Test)6 List (java.util.List)5 ClientConfiguration (com.amazonaws.ClientConfiguration)4 AmazonDynamoDB (com.amazonaws.services.dynamodbv2.AmazonDynamoDB)4 ClientResources (io.lettuce.core.resource.ClientResources)4 URI (java.net.URI)4 Map (java.util.Map)4 ListTablesResponse (software.amazon.awssdk.services.dynamodb.model.ListTablesResponse)4 Context (io.vertx.core.Context)3 Timeout (io.vertx.junit5.Timeout)3 VertxTestContext (io.vertx.junit5.VertxTestContext)3 Clock (java.time.Clock)3 Set (java.util.Set)3 ExecutionException (java.util.concurrent.ExecutionException)3 Order (org.junit.jupiter.api.Order)3 TestMethodOrder (org.junit.jupiter.api.TestMethodOrder)3 ExternalServiceCredentialGenerator (org.whispersystems.textsecuregcm.auth.ExternalServiceCredentialGenerator)3