13

In the Amazon Web Services sdk for java there is the possibility to create two different clients for DynamoDB: sync and async. The two objects can be then passed to the constructor of DynamoDBMapper. So, you should be able to create two different kinds of DynamoDBMapper: sync mapper and async mapper.

My question is: how does the async mapper work? I can't find any method in the async mapper that returns a Future object. So, how could I ever run multiple query asynchronously if I must always wait the return value of any method of the async mapper?

Thanks

5
  • Good Question. I was wondering the same as well. I've created an async client and passed it to the DynamoMapper but I don't think that makes it an async call. The documentation is very unclear about this. Commented Aug 10, 2013 at 20:03
  • 1
    Exactly... At the end I wrote an implementation of Callable<T> that uses the SyncMapper in method "call". Then, I run such implementation inside an Executor's thread that returns a Future<T> object, that can be used for retrieving the results of the query and for synchronization with other query results. That's working fine. Commented Aug 11, 2013 at 15:08
  • What framework are you using for the Executor Thread? I'm writing a Spring MVC controller, that receives POST data and uses the mapper to save the data in dynamo. I'm not sure about creating threads..its a bad practice to create a thread for each POST request you get. Not sure how to proceed..I need an aysnc client with the mapper. Commented Aug 11, 2013 at 21:04
  • Right now, for many reasons, I am using no framework for managing the Executor Thread. But, I did use Spring in other projects with great results. See static.springsource.org/spring/docs/3.2.x/… Commented Aug 14, 2013 at 11:00
  • I exactly had the same question! Commented Dec 13, 2015 at 21:41

2 Answers 2

17

The asynchronous DynamoDB client extends from the synchronous client, and provides new method names for the asynchronous operations that return Futures. Currently the DynamoDBMapper will always use the synchronous methods of whatever AmazonDynamoDB client that you pass in. We'll take this feedback as a feature request for asynchronous support using the mapper.

Sign up to request clarification or add additional context in comments.

5 Comments

Thank you Jason, looking forward to see this feature asap!
Would love this feature!
Absolutely would love to see parity between the low-level and high-level API in terms of async.
Just wondering if there has been any movement on this since Oct 2013? This would be a very helpful feature!
Still nothing? Is there anything open source to fill in the gap?
3

This is now supported by the enhanced DynamoDB client that comes with aws-sdk-java-v2

First, create an async version of the EnhancedClient & Table objects:

DynamoDbEnhancedAsyncClient enhancedClient = DynamoDbEnhancedAsyncClient.create();
DynamoDbAsyncTable<Customer> customerTable =
enhancedClient.table("customers_table", TableSchema.fromBean(Customer.class));

Then, you can perform operations on it asynchronously:

CompletableFuture<Customer> result = customerTable.getItem(r -> r.key(customerKey));

For more details see asynchronous-operations

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.