Fast Java client for NSQ
Switch branches/tags
Nothing to show
Clone or download
Latest commit 4419798 Mar 18, 2015


A fast netty-based java client for NSQ initially developed and maintained by @dustismo for use in various places in the and stacks.

I (@mreiferson) am currently maintaining this repo to facilitate bug fixes and minor updates and am interested in finding a longer-tem maintainer.


Example usage:

NSQLookup lookup = new NSQLookupDynMapImpl();
lookup.addAddr("localhost", 4161);
NSQConsumer consumer = new NSQConsumer(lookup, "speedtest", "dustin", new NSQMessageCallback() {
    public void message(NSQMessage message) {
        System.out.println("received: " + message);            
        //now mark the message as finished.
        //or you could requeue it, which indicates a failure and puts it back on the queue.
    public void error(Exception x) {
        //handle errors
        log.warn("Caught", x);


Example usage:

NSQProducer producer = new NSQProducer().addAddress("localhost", 4150, 1);            
for (int i=0; i < 50000; i++) {
    producer.produce("speedtest", ("this is a message" + i).getBytes());

The producer also has a Batch collector that will collect messages until some threshold is reached (currently maxbytes or maxmessages) then send as a MPUB request. This gives much greater throughput then producing messages one at a time.

                new BatchCallback() {
                    public void batchSuccess(String topic, int num) {
                    public void batchError(Exception ex, String topic, List<byte[]> messages) {
            null, //use default maxbytes 
            null //use default max seconds

for (int i=0; i < iterations; i++) {
    producer.produceBatch("speedtest", ("this is a message" + i).getBytes());


Note: the trendrr-oss dependancy can easily be swapped out by implementing the com.trendrr.nsq.NSQLookup interface using a different json parser