On Nov 18, 2016, at 11:14 AM, Psycho Punch <rdg...@gmail.com> wrote:
My project is using Spring MVC for Web components, but I have Vert.x taking care of internal passing of messages among clusters of services. In my Web controller I need to wait for Vert.x (event bus) to send, and process response and I can't just rely on the handler passed to it because the Controller code returns immediately; I need to wait for the event bus. I discovered that there's the Vert.x Sync module for that but I'm having difficulties setting up instrumentation between my IDE, and build system (Gradle), especially since none of my efforts to add javaagent arg for running just unit tests in either has worked. The official documentation from Quasar has a section on instrumentation with Gradle, but it doesn't work for my build.
Are there other ways to achieve synchronization without relying on this extra instrumentation steps?
--
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.
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/92e6aa9f-7ee7-408a-9585-e35da6ca2724%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
On Nov 18, 2016, at 11:56 AM, Psycho Punch <rdg...@gmail.com> wrote:
Hi Julien,
Thanks for that. While I'm still not familiar with Kotlin, I think your example code is easy to understand, and to follow. However, right now, I'm under constraint that I can't use languages other than Java in the project. If there aren't any other choice, I will have to weigh between trying to resolve the issues I'm having with Vert.x sync, or convincing that we add a bit of Kotlin in our project, both of which will take some time (and we don't really have much of that at the moment). I just remember there's a RxJava integration module for Vert.x. Are there features in there that you think can offer some alternatives? I have a very general understanding of RxJava at the moment, but I think it's a more viable solution for my project...
--
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.
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/f86f7d0e-297a-431a-85f2-da2c47156766%40googlegroups.com.
@Service
public class BookVerticle extends AbstractVerticle implements BookService {
//method implementation here
}@Service
public class BookServiceImplementation implements BookService {
@Autowired
private Vertx vertx;
//method implementation here using Vert.x instace
/*something like
vertx.eventBus.send(...)
*/
}Response response = new Response();
vertx.eventBus().send("service.name", "{}", result -> {
//process result
response.update(processedResult);
})
return response;CompletableFuture<Response> future = new CompletableFuture<>();
vertx.eventBus().send("service.name", "{}", result -> {
//process result
future.complete(processedResult);
})
return future.get(); //handle exception here
public int invoke() throws Exception { // Ugly hack to throw exception and probably needs better consideration
final CompletableFuture<Integer> future = new CompletableFuture<>();
vertx.eventBus().<Integer>send("vertx.demo", "Latest", result -> {
if (result.succeeded()) {
future.complete(result.result().body());
} else {
future.completeExceptionally(result.cause());
}
});
return future.get(2, TimeUnit.SECONDS);
}
On Dec 8, 2016, at 8:23 AM, Pradyumna Achar <pradyum...@gmail.com> wrote:Hi Jez,I'm in this same situation (where a Spring-MVC controller needs to block while it gets work done through Vertx's eventbus) and found this discussion to be very informative. Thanks.I have a small clarification to ask in this regard -- is it guaranteed that every thread that Vertx internally uses to run its event loops will be distinct from the thread that instantiated the Vertx instance (via Vertx.vertx())?
(If it is not so, the thread using which Spring creates the bean-that-creates-the-Vertx-instance gets messy, as Vertx could use this thread it as one of its event loop threads as well)[p.s. -- although I'd like to change the whole thing to use Vertx, I haven't found enough time for the rewrites & testing -- gets especially complicated if there are multiple branches of the same codebase being worked on by different teams that'll have to merge into one in a few months]
On Tuesday, 22 November 2016 00:58:20 UTC+5:30, Jez P wrote:I think for what you want to do, the completable future approach is probably most appropriate. Anything else does tightly couple your API to async behaviour (and specifically the Spring expression of the async behaviour) which feels a bit clunky to me. If you want to make everything non-blocking end to end, you're kind of stuck with that approach (though you could write a simple adapter which adapts a CompletableFuture to a deferred result, then internally all your services could return a CompletableFuture, and you could offer a sync wrapper which awaits completion on the calling thread, and an async wrapper which converts the CompletableFuture to a DeferredResult then returns it). That would enable some mixing and matching of async/sync interfaces. Candidly though, it doesn't feel like you need that at present, which means IMO it would be over engineering.Out of interest, in your use-case what's the benefit of using vert.x behind the blocking API? I'd normally say the big kickass win of vert.x is easy outward scalability, but if you're operating a thread pool where you're allowed to block while awaiting the behind-the-scenes processing, that seems a little lessened (though you could build a network of behind-the-scenes non-blocking microservices and just scale the bits that call into that network with more instances perhaps). Not asking you to justify your decisions, just trying to understand what you're getting out of it. I'm a fan of both Spring Boot and vert.x so interested in the use-cases where there is a case for using both :)
On Monday, November 21, 2016 at 3:52:04 AM UTC, Psycho Punch wrote:Hi Jez,
Actually, DeferredResult (async controller) was what I was about to look into next until I read your suggestion on CompletableFuture. The thing with DeferredResult though is that I have to make the service interface explicitly async, which was ok if I didn't really have much choice. For now, based on the project's state, I guess CompletableFuture works just fine.
Thanks for all your help. I really appreciate it.
--
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.
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/d9f9b633-4efd-45a9-a708-12eece6f1d0c%40googlegroups.com.