vertx-examples icon indicating copy to clipboard operation
vertx-examples copied to clipboard

simple restful api example or websockets example

Open ORESoftware opened this issue 5 years ago • 3 comments

I would be really nice to be able to clone a simple project that does RESTful API and a simple project that does websockets, devising the project structure o/w leaves lots of questions, better to have some structure determined already?

ORESoftware avatar Jan 28 '19 00:01 ORESoftware

regarding this question: https://stackoverflow.com/questions/23931208/how-vert-x-is-single-threaded

the biggest question in my head for a simple REST API is - for each incoming request - should I do work with a worker verticle or can everything be done in the main verticle? Where do I need to do locking, if anywhere?

For a simple REST server, my guess is you don't want do db calls with a worker verticle and then send the data via the eventBus, because that's too expensive. I assume using io.vertx.ext.web.Router to handle requests in the main verticle is best. But I don't know if the main verticle code is always running in the same thread - my guess is that it is.

?

ORESoftware avatar Jan 28 '19 01:01 ORESoftware

You should only work with a worker verticle if you're dealing with "blocking calls" (i.e. non NIO calls). Actually, this is really well covered in the docs. Please read the section about the event-loop and verticles.

For instance, if you're using the reactive pg driver, the official redis driver, the official mongodb driver, etc. You don't need any worker verticle at all, just a standard one.

If you're dealign with blocking calls sporadically, then go with executeBlocking. If you're having something like a CronJob which takes a long time to compute stuff, then go with a Worker Verticle.

These topics are covered in the documentation.

aesteve avatar Jan 28 '19 07:01 aesteve

@aesteve my biggest question is if we use 1 verticle, if all my code is running in the same thread (that way I can avoid the need to explicitly lock).

ORESoftware avatar Jan 28 '19 19:01 ORESoftware