Skip to content

BrandwatchLtd/pgq-consumer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

38 Commits
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pgq-consumer Build Status

A PGQ consumer written in Java, using Spring's JdbcTemplate for database access.

What's PGQ?

PGQ is the queueing solution from Skytools, which was written by Skype. It's a neat way of writing database triggers that send events to an event queue in PostgreSQL, which you can then poll with the PGQ API. An implementation of this polling is available in this library.

A good presentation on PGQ is available on SlideShare.

How do I use it?

As mentioned before, this code originated from a Spring application, so it assumes two things:

  1. That you've set up PGQ in your PostgreSQL database
  2. That your application has a DataSource pointing to that database

Once you have those, create a PGQConsumer:

String queueName = "myQueue";                         // What you called your queue in pgq.create_queue()
String consumerName = "myConsumer";                   // A name unique to this application
DataSource dataSource = ...                           // Initialised and pointing at your database
PGQEventHandler eventHandler = new MyEventHandler();  // Your callback for each event
PGQConsumer pgqConsumer = new PGQConsumer(queueName, consumerName, dataSource, eventHandler);

The PGQConsumer is a Runnable, so put it into a pool for continuous execution, and away you go. If you're looking for an example PGQEventHandler then check out PrintingEventHandler.