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 for NOTIFY/LISTEN #650

Open
LifeIsStrange opened this issue Sep 15, 2021 · 2 comments
Open

Support for NOTIFY/LISTEN #650

LifeIsStrange opened this issue Sep 15, 2021 · 2 comments
Labels
type: enhancement A general enhancement

Comments

@LifeIsStrange
Copy link

LifeIsStrange commented Sep 15, 2021

Hi,
I was wondering whether

@Query("LISTEN request_event_notification", nativeQuery = true)
fun getNewRequestStream(): Flux<RequestModel> 

is supported?

// 1
Using the PGconnection manually it is a two step process:
connection.createStatement("LISTEN request_event_notification").execute()
					.flatMap(PostgresqlResult::getRowsUpdated).subscribe();
// 2
connection.getNotifications().map(Notification::getParameter);

So I was wondering whether spring data r2dbc would support it directly in Repositories, and correctly serialize the json/text from postgres into the corresponding type (RequestModel)

corresponding SQL:

CREATE OR REPLACE FUNCTION notify_event() RETURNS TRIGGER AS
$$
DECLARE
    payload JSON;
BEGIN
    payload = row_to_json(NEW);
    PERFORM pg_notify('request_event_notification', payload::text);
    RETURN NULL;
END;
$$ LANGUAGE plpgsql;

DROP TRIGGER IF EXISTS notify_request_event ON request;

CREATE TRIGGER notify_request_event
    AFTER INSERT OR UPDATE OR DELETE
    ON request
    FOR EACH ROW
EXECUTE PROCEDURE notify_event();
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Sep 15, 2021
@LifeIsStrange
Copy link
Author

I'm wondering whether the support for OUT parameters is needed for this #645
I have no expertise in stored procedures so I don't really know

@mp911de
Copy link
Member

mp911de commented Sep 15, 2021

Subscribing through a query is supported but the result of the query is going to be an update count (no rows). Additionally, connections used by Spring Data R2DBC are not sticky, meaning that if you run the command once and you have a connection pool, then obtaining notifications may target a different connection that isn't listening.

I suggest using connections directly. The payload of notifications is binary and we cannot reason about the serialization format.

I'll keep this ticket open as the idea of supporting listen/notify makes a lot of sense in general.

@mp911de mp911de added type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged labels Sep 15, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

3 participants