nsq-j

Java client for the NSQ realtime distributed messaging platform

Лицензия

Лицензия

Группа

Группа

com.sproutsocial
Идентификатор

Идентификатор

nsq-j
Последняя версия

Последняя версия

1.2
Дата

Дата

Тип

Тип

jar
Описание

Описание

nsq-j
Java client for the NSQ realtime distributed messaging platform
Ссылка на сайт

Ссылка на сайт

https://github.com/sproutsocial/nsq-j
Система контроля версий

Система контроля версий

http://github.com/sproutsocial/nsq-j/tree/master

Скачать nsq-j

Имя Файла Размер
nsq-j-1.2.pom
nsq-j-1.2.jar 61 KB
nsq-j-1.2-sources.jar 29 KB
nsq-j-1.2-javadoc.jar 69 KB
Обзор

Как подключить последнюю версию

<!-- https://jarcasting.com/artifacts/com.sproutsocial/nsq-j/ -->
<dependency>
    <groupId>com.sproutsocial</groupId>
    <artifactId>nsq-j</artifactId>
    <version>1.2</version>
</dependency>
// https://jarcasting.com/artifacts/com.sproutsocial/nsq-j/
implementation 'com.sproutsocial:nsq-j:1.2'
// https://jarcasting.com/artifacts/com.sproutsocial/nsq-j/
implementation ("com.sproutsocial:nsq-j:1.2")
'com.sproutsocial:nsq-j:jar:1.2'
<dependency org="com.sproutsocial" name="nsq-j" rev="1.2">
  <artifact name="nsq-j" type="jar" />
</dependency>
@Grapes(
@Grab(group='com.sproutsocial', module='nsq-j', version='1.2')
)
libraryDependencies += "com.sproutsocial" % "nsq-j" % "1.2"
[com.sproutsocial/nsq-j "1.2"]

Зависимости

compile (6)

Идентификатор библиотеки Тип Версия
org.slf4j : slf4j-api jar 1.7.25
com.google.code.gson : gson jar 2.8.2
net.jcip : jcip-annotations jar 1.0
org.xerial.snappy : snappy-java Необязательный jar 1.1.2.6
ch.qos.logback : logback-core Необязательный jar 1.2.3
ch.qos.logback : logback-classic Необязательный jar 1.2.3

test (4)

Идентификатор библиотеки Тип Версия
junit : junit jar 4.13.1
org.powermock : powermock-module-junit4 jar 1.6.2
org.powermock : powermock-api-mockito jar 1.6.2
com.google.guava : guava jar 24.1.1-jre

Модули Проекта

Данный проект не имеет модулей.

Maven Central

nsq-j

Java client for the NSQ realtime distributed messaging platform

Install

Add a dependency using Maven

<dependency>
  <groupId>com.sproutsocial</groupId>
  <artifactId>nsq-j</artifactId>
  <version>1.2</version>
</dependency>

or Gradle

dependencies {
  compile 'com.sproutsocial:nsq-j:1.2'
}

Publish

Publisher publisher = new Publisher("nsqd-host");

byte[] data = "Hello nsq".getBytes();
publisher.publishBuffered("example_topic", data);

Buffers messages to improve performance (to 16k or 300 milliseconds by default),

publisher.publish("example_topic", data) publishes synchronously and returns after nsqd responds OK

You can batch messages manually and publish them all at once with publish(String topic, List<byte[]> messages)

Subscribe

public class PubExample {

    public static void handleData(byte[] data) {
        System.out.println("Received:" + new String(data));
    }

    public static void main(String[] args) {
        Subscriber subscriber = new Subscriber("lookup-host-1", "lookup-host-2");
        subscriber.subscribe("example_topic", "test_channel", PubExample::handleData);
    }
}

Uses the lookup-hosts to discover any servers publishing example_topic.

If handleData returns normally FIN is sent to nsqd to finish the message, if the handler throws any exception then the message is requeued and processing is delayed using exponential backoff. Delay times and max attempts are configurable.

For complete control handle the Message directly:

    public static void handleMessage(Message msg) {
        try {
            byte[] data = msg.getData();
            // ... complicated work ...
            msg.finish();
        }
        catch (Exception e) {
            msg.requeue();
        }
    }

Publishers and Subscribers are thread safe and should be reused. Your handler methods should be thread safe, make them synchronized if you are unsure.

Client.getDefaultClient().stop() waits for in-flight messages, closes all connections and allows all threads to exit.

Javadocs

com.sproutsocial

Sprout Social

Версии библиотеки

Версия
1.2
1.0
0.9.4
0.9.3
0.9.2
0.9.1
0.9