Fast Java client for NSQ
Java
Pull request Compare This branch is 63 commits ahead, 9 commits behind nsqio:master.
Latest commit 7266d9a Jan 6, 2017 @brainlag minor code cleanup/fixes
Permalink
Failed to load latest commit information.
src minor code cleanup/fixes Jan 6, 2017
.gitignore update post release Apr 27, 2015
LICENSE add builder pattern to consumer and producer Apr 5, 2015
README.md ship RC2 Feb 1, 2016
pom.xml Update Netty to 4.0.39.Final. Dec 13, 2016

README.md

JavaNSQClient

A (fast?) netty-based Java8 client for NSQ heavily forked of TrendrrNSQClient.

Artifact

<dependency>
  <groupId>com.github.brainlag</groupId>
  <artifactId>nsq-client</artifactId>
  <version>1.0.0.RC2</version>
</dependency>

Consumer

Example usage:

NSQLookup lookup = new DefaultNSQLookup();
lookup.addLookupAddress("localhost", 4161);
NSQConsumer consumer = new NSQConsumer(lookup, "speedtest", "dustin", (message) -> {
        System.out.println("received: " + message);            
        //now mark the message as finished.
        message.finished();

        //or you could requeue it, which indicates a failure and puts it back on the queue.
        //message.requeue();
});

consumer.start();

Producer

Example usage:

NSQProducer producer = new NSQProducer().addAddress("localhost", 4150).start();            
producer.produce("TestTopic", ("this is a message").getBytes());

Backoff

By default Backoff does not kick in and a consumer will eat all your memory and CPU. To enable Backoff you have to set your own thread pool executer with:

consumer.setExecutor(...);