All Projects → BrandwatchLtd → pgq-consumer

BrandwatchLtd / pgq-consumer

Licence: MIT license
PGQ consumer for Java.

Programming Languages

java
68154 projects - #9 most used programming language

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.

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].