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

Support change notification #3102

Open
mikehearn opened this issue Sep 4, 2024 · 1 comment
Open

Support change notification #3102

mikehearn opened this issue Sep 4, 2024 · 1 comment
Labels
type: enhancement New feature or request

Comments

@mikehearn
Copy link

Feature description

Some databases can inform clients when the results of a query have changed. Oracle is an example of one such database, but there are others. Currently utilizing this feature requires manually working with JDBC and giving up the benefits of Micronaut Data.

https://docs.oracle.com/en/database/oracle/oracle-database/19/jjdbc/continuos-query-notification.html#GUID-8A2BF5CA-CB76-4D88-B467-4A2AE63D89D4

It would be nice to have an integrated support for this. Behind the scenes using the feature is very simple:

  1. Create a "registration" object using OracleConnection.registerDatabaseChangeNotification(properties) being careful to let the user set the OracleConnection.DCN_CLIENT_INIT_CONNECTION property to true as otherwise the DB will try and dial back the client over TCP when there's a notification - efficient, but not compatible with firewall or NATd networks as found in e.g. containers.
  2. Add one or more listener/callback objects to the registration.
  3. Set the registration object on the OracleStatement or OraclePreparedStatement object.
  4. Do some queries.
  5. You can now close the connections and so on, and the driver will call you back on its own thread when the rows that the queries read have changed.

From an integration perspective, it probably makes sense to allow ordinary query methods to be passed an org.reactivestreams.Subscriber or java.util.concurrent.Flow.Subscriber object. It doesn't make sense to add a new magic name variant like findAllAndWatch because you generally want the results of the query you do in any case. Then:

interface MyRepo {
    String findFoo(@Id String id, Subscriber<String> changes)
}

would work fine as then you can just implement the interface and the onNext method to get a stream of values of the FOO column as it changes for that id. The Subscription object passed to Subscriber.onSubscribe can then be used to cancel the registration.

@graemerocher graemerocher added the type: enhancement New feature or request label Sep 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

3 participants
@graemerocher @mikehearn and others