Postgres has LISTEN/NOTIFY that you can use for triggering something like 
this:

http://www.postgresql.org/docs/9.4/static/sql-notify.html
http://www.postgresql.org/docs/9.4/static/sql-listen.html

The Java JDBC drivers support listening, although you have to do it by 
polling:

https://jdbc.postgresql.org/documentation/80/listennotify.html

Are you sure that you want to do this in an event driven way though? Other 
alternatives would be:

- when you add the user, also add their ID to a table of new users. 
Periodically poll this table and handle any new users, marking them as 
handled once you've sent the message to clients.

- use a queue of some sort to manage asynchronous tasks.

The first is simple, and has the advantage that it doesn't require any 
fancy DB features. The second is worth thinking about if you're going to 
have any other kind of triggered tasks, but is probably overkill just for 
this. Both have the advantage that the desire to perform an action (notify 
clients) is explicitly represented somewhere rather than just existing 
implicitly in the state of the running process.


Jony


On Monday, 19 October 2015 16:06:01 UTC+1, Adrian Cooley wrote:
>
> Hi all,
>
> I'm new to Clojure and I've been exploring the possibility of using it to 
> handle a large list of Users stored in a Postgresql Database. I can see 
> that there are some great sql libraries for clojure to query a Postgresql 
> database and this is fine. However, I was wondering if there are any useful 
> Clojure features or libraries that could allow me to 'listen' for changes 
> to a Users Table in the Database. A use case scenario to describe what I 
> want would be as follows: Say someone registers their details on a website 
> and their details are persisted to the Database. I then want some process 
> to pick up that a new user is now in the database and send this user 
> information to a client that has registered to listen for new users. Is 
> something like this possible in Clojure where it can handle listening to 
> state changes and trigger a notification? Thanks in advance to anyone who 
> chimes in with advice,
>
> Regards,
> Adrian.
>

-- 
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your 
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en
--- 
You received this message because you are subscribed to the Google Groups 
"Clojure" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to