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.");
}
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);
}
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);
}
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);
}
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");
}
Aggregations