JDBC with Webflux - how to dispatch to container thread

谁说我不能喝 提交于 2019-12-03 20:44:00

Do you think this is a viable approach (until we get non-blocking drivers to databases)?

I personally do think this is a valid approach. BUT many others (most of them know much more about reactive programming than I do) doubt this is a good idea.

Your alternatives:

  • write a separate service for your blocking DB calls and call it using WebClient

    Pro: clean separation of blocking and non-blocking code.

    Con: One more service boundary including the network.

  • write a separate service for your blocking DB calls including its own user interface.

    Pro: No inter service communication.

    Con: Reduces the percentage of your application that is actually reactive.

  • if you want to keep the blocking code in this service, this is the correct way to do it.

How to get access to container (netty) thread pool?

If you are just rendering your response you don't need to, because that happens on the netty thread automagically.

If you have actual transformations to do, there is nothing ready-made to do this. I guess one could use some Netty API and implement a Scheduler based on that. But I don't know enough about Netty to help with that.

And to answer the follow-up question I kind of asked myself:

But isn't that a gigantic omission?

The publishOn methods weren't really intended for this. Their use-case is more along use in e.g. Swing applications where you have at the end of a pipeline the requirement to use a certain thread or thread pool.

My personal feeling is Reactor should have something like this, but the developers are currently not convinced that this is a good idea. So I suggest if you think it really makes sense for your application: open a ticket and be prepared to argue your point. Either you succeed or we both learn why it is a bad idea :-)

Anything else?

Glad you asked if you're doing blocking stuff on a thread pool in an otherwise reactive pipeline you should think how to handle the scenario when the thread pool (or the respective resource) is overloaded i.e. it processes events slower than they get produced.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!