简体   繁体   中英

Symfony2/Doctrine and PostgreSQL NOTIFY/LISTEN

I am writing a database application on PostgreSQL that has two parts:

  1. GUI - written in Symfony/Doctrine
  2. Processing - written in C/libpq

The processing component will process data from a table after it has been inserted by the GUI. However, how does the processing component know there is a change? My default answer would have been to use the PostgreSQL notify/listen commands, as I'm keen to avoid some kind of polling.

Questions:

  1. Is there some way that the Symfony application could use the postgresql notify command? Doctrine supports Native SQL selects, but I don't believe this is what I need.

  2. Any other ideas?

Thanks in advance.

A native SELECT should be entirely sufficient.

While you usually use the NOTIFY statement, it's also possible to call the pg_notify function for the same effect.

SELECT pg_notify('key','payload');

Your worker can LISTEN key; as normal, and will receive notifications generated this way the same as if NOTIFY was used.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM