Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

simple restful api example or websockets example #331

Open
ORESoftware opened this issue Jan 28, 2019 · 3 comments
Open

simple restful api example or websockets example #331

ORESoftware opened this issue Jan 28, 2019 · 3 comments

Comments

@ORESoftware
Copy link

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
Copy link
Author

ORESoftware commented Jan 28, 2019

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.

?

@aesteve
Copy link
Contributor

aesteve commented Jan 28, 2019

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.

@ORESoftware
Copy link
Author

@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).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

No branches or pull requests

2 participants