-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
Embrace queue APIs in Spring's JDBC message stores for polling messages #3872
Comments
Yes, we may consider that as a contribution, for example like |
Thanks, I will look into it and try to solve this for my own application first and then try to extract it to a pull request. |
I played around with this on Oracle and Postgres and here are some observations:
What would you consider to be in-scope? I'd suggest to aim for Postgres support only, at least for a first version. I am further wondering if this should rather be implemented as a pollable channel or as a PublishSubscribeChannel. Both is possible, of course, I wonder what would be the more appropriate abstraction. As the standard JDBC driver for Postgres is blocking, though, I would consider the pollable channel, though. |
Thank you, @raphw , for investigation. What you say for PostgreSQL and its blocking polls does not make too much difference for me with what we have so far with a So, probably we come back to square one when we have everything what we can, but provides don't give us enough flexibility to extend for their features. |
Indeed, Oracle AQ is JMS compatible, I don't think that needs explicit support. As for Postgres, the difference to using a The common workaround is to poll the group every X seconds, but with Postgres's notify/listen API, this is not necessary as all listening JVMs will receive information on a new message being sent to the queue. If one replica sends 1000 messages to the queue, with this approach all other replicas will immediately wake up and start processing what is the desired behavior in my case. (I prototyped this now with a custom component and it works like a charm.) |
I'm confused: you said in your previous comment that "Postgres JDBC driver only supports blocking polls", so we are in a situation to re-implement a |
In few words: the difference is that the current solution notifies on a JVM level, the proposed solution notifies on a database level. If JVM A started polling from a group, it would either block forever or would need to poll in intervals. Because if JVM B sent a message, there's no mechanism to push these notifications to the other JVM. LISTEN/NOTIFY on the other hand allows for an immediate reaction on JVM A if JVM B added a message. |
I understand what you are saying and that's why it is called "polling".
Just because there is no a notification hook from the DB to react on. What you describer with the This is your words:
That's why I want to get a clear answer from you: what we are going to implement - the polling channel which is already there, or |
Well, the implementation I am out after is a Java Queue that I can plug into an existing API. In the current implementation of the poll method, this delegates to the code your quoting. I was out after replacing the messageStoreNotEmpty lock with a database based one. But a subscribable channel is of course also possible. I was nore trying to explain why the current API in Soring is not equivalent as you suggested. |
Sure! It really can be a custom |
Yeah, that's what I am currently thinking would be the best solution. If one wanted to map this into a Java Queue, that would still be possible by a subscriber that adds to a regular queue. I will try to make a prototype out of this! |
I have created something that hooks into Spring Integration in a way that works for me. I wanted to start out with something minimal that depicts what I am aiming at without any details: https://github.com/raphw/spring-integration/tree/postgres-notification-listener A listener like this will trigger JVM B immediately if listening for a group message send by JVM A. As things stand, the In a first attempt, I tried to implement the Any suggestions how this might fit into the existing landscape? I read quite some code to figure this out myself, but it's a lot of hierarchies, so I was wondering if someone who is more experienced with the code base could make a better consideration. |
At a glance looks cool! I don't think we need to mix
My point is to avoid a WDYT? |
Yeah, that sounds like a better idea as it allows the subscriber to decide on the polling. One issue I found however was mapping back from groupKey to groupId, if one wanted to provide the latter as an argument to the subscriber. |
Not sure what you mean. The channel must be supplied with that |
If listening to inserts via notify, only database values can be supplied to the NOTIFY call, GROUP_KEY in this case. On LISTEN, this key is available, but not the object which is normally supplied when sending messages. I had hoped to supply offer a listener interface where region and groupId for a message were provided to the listener, but only the stringified key is available. |
I redid the suggestion, maybe that's a better approach. Please have another look! |
Fixes #3872 * Add documentation for `PostgresSubscribableChannel` and related components * Add links, example and what's new section. * Docs clean up
Modern databases support much better queuing APIs than what they offered years ago, so articles like the one included in the Spring integration documentation are rather dated.
For example, Postgres offers
LISTEN
andNOTIFY
or Oracle database change norification. These APIs would allow for a more efficientQueue
usage of the JDBC queues that are offered, if a database offers it.The text was updated successfully, but these errors were encountered: