Skip to content

Instantly share code, notes, and snippets.

@coop
Last active August 29, 2015 14:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save coop/3fbe0b663119dd91c974 to your computer and use it in GitHub Desktop.
Save coop/3fbe0b663119dd91c974 to your computer and use it in GitHub Desktop.

PG Notify Example

$ createdb pg_notify
$ ruby publisher.rb
$ ruby subscriber.rb
require "sequel"
require "pg"
DB = Sequel.connect("postgres://localhost/pg_notify")
puts "payload to publish:"
loop do
payload = STDIN.gets
DB.notify(:event_log_head, payload: payload)
end
require "sequel"
require "pg"
DB = Sequel.connect("postgres://localhost/pg_notify")
DB.listen(:event_log_head, loop: true) do |_channel, _pid, payload|
puts payload
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment