Hi, I am interested in using DynamoDB from my Vertx verticle. I've read other posts here but I'm unsure of what I should do to use their async java sdk from vertx without using executeBlocking. I notice they use java.util.concurrent based Futures for the async. Not sure that will help me much since I can't assign a callback handler. Has anybody else ran into something similar or have any suggestions of the best way to make this work in a Vertx-friendly way (non-blocking)?
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/9d8e5a03-ec42-491a-a8ab-7894bbd72496%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
AsyncHandler
is executed inside the thread pool owned by the asynchronous client.public void testMe(RoutingContext rc){ Future<DescribeTableResult> myFuture = Future.future(); myFuture.setHandler(ar -> { if (ar.failed()) { rc.response().end("Unexpected failure"); } else { rc.response().end(ar.result().getTable().toString()); } }); // invoke async method with the handler test(myFuture); say("End of testMe function reached");}
public void test(Future<DescribeTableResult> future){ dynamoDB.describeTableAsync(new DescribeTableRequest().withTableName("FakeTableName"), new AsyncHandler<DescribeTableRequest,DescribeTableResult>() { public void onSuccess(DescribeTableRequest request, DescribeTableResult result) { blockingSimulation(); future.complete(result); say("Future is now complete for describing the table"); } public void onError(Exception exception) { future.failed(); say("Error describing table: " + exception.getMessage()); } }); say("End of test function reached");} private void blockingSimulation() { int i = 0; say("Start blocking simulation"); // simulate blocking action while (i++ < 5000000) { if (i % 5 > 0) { String a = "one"; String b = " two"; String c = a + b + " three"; } if (i % 7 > 0) { String d = "four"; String e = " five"; String f = d + e + " six"; } } say("Stop blocking simulation");}
Timer 1 fired: 0
Timer 1 fired: 0
Timer 1 fired: 0
End of test function reached
End of testMe function reached
Timer 1 fired: 0
Timer 1 fired: 0
Timer 1 fired: 0
Timer 1 fired: 0
Timer 1 fired: 0
Timer 1 fired: 0
Timer 1 fired: 0
Timer 1 fired: 0
Timer 1 fired: 0
Timer 1 fired: 0
Timer 1 fired: 0
Timer 1 fired: 0
Start blocking simulation
Timer 1 fired: 0
Timer 1 fired: 0
Timer 1 fired: 0
Stop blocking simulation
Future is now complete for describing the table
Timer 1 fired: 0
Timer 1 fired: 0
Timer 1 fired: 0
Timer 1 fired: 0
Timer 1 fired: 0
Timer 1 fired: 0
Timer 1 fired: 0
Timer 1 fired: 0
Timer 1 fired: 0
Hi,According to this article https://aws.amazon.com/articles/Java/5496117154196801 their SDK also offers a callback based API. So you could use this and, in the callbacks, go back to Vert.x world with #runOnContext.Regards,
2016-09-24 7:36 GMT+02:00 ms98765 <micah...@gmail.com>:
Hi, I am interested in using DynamoDB from my Vertx verticle. I've read other posts here but I'm unsure of what I should do to use their async java sdk from vertx without using executeBlocking. I notice they use java.util.concurrent based Futures for the async. Not sure that will help me much since I can't assign a callback handler. Has anybody else ran into something similar or have any suggestions of the best way to make this work in a Vertx-friendly way (non-blocking)?
--
You received this message because you are subscribed to the Google Groups "vert.x" group.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+un...@googlegroups.com.
To unsubscribe from this group and stop receiving emails from it, send an email to vertx+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/vertx.
To view this discussion on the web, visit https://groups.google.com/d/msgid/vertx/28547b15-375d-4c6a-8792-f9885834ef7f%40googlegroups.com.