Skip to content
This repository has been archived by the owner on Aug 3, 2019. It is now read-only.

Basic usage

Mark Paluch edited this page Feb 18, 2016 · 4 revisions

Basic Usage

DisqueClient client = DisqueClient.create("disque://host");
DisqueConnection<String, String> connection = client.connect();
DisqueCommands<String, String> sync = connection.sync();
String jobId = sync.addjob("queue", "body", 1, TimeUnit.MINUTES);
  
Job<String, String> job = sync.getjob("queue");
connection.ackjob(job.getId());

Each Disque command is implemented by one or more methods with names identical to the lowercase Disque command name. Complex commands with multiple modifiers that change the result type include the CamelCased modifier as part of the command name.

Disque connections are designed to be long-lived, and if the connection is lost will reconnect until close() is called. Pending commands that have not timed out will be (re)sent after successful reconnection.

All connections inherit a default timeout from their DisqueClient and and will throw a DisqueException when non-blocking commands fail to return a result before the timeout expires. The timeout defaults to 60 seconds and may be changed in the DisqueClient or for each individual connection.

DisqueURI

The DisqueURI contains the host/port and can carry authentication details. On a successful connect you get authenticated. This applies also after re-establishing a connection after connection loss.

A Disque URI can also be created from an URI string. Supported formats are:

  • disque://[password@]host[:port][,host2[:port2]][,hostN[:port2N]]

    Plaintext Disque connection

  • disques://[password@]host[:port][,host2[:port2]][,hostN[:port2N]]

    SSL Disque connection

  • disque-socket://socket-path

    Connecting to a [Unix Domain Socket](Unix Domain Sockets)

Exceptions

In the case of an exception/error response from Disque, you'll receive a RedisException containing the error message. RedisException is a RuntimeException.

Examples

Using Host and Port and set the default timeout to 20 seconds

DisqueClient client = new DisqueClient("localhost", 7711);
client.setDefaultTimeout(20, TimeUnit.SECONDS)

Multiple hosts

DisqueClient client = new DisqueClient("host1:7711,host2:7711,host3:7711");

Using DisqueURI

DisqueURI disqueUri = DisqueURI.Builder.disque("localhost").withPassword("authentication").build();
DisqueClient client = new DisqueClient(disqueUri);

SSL DisqueURI

DisqueURI disqueUri = DisqueURI.Builder.disque("localhost").withSsl(true).withPassword("authentication").build();
DisqueClient client = new DisqueClient(disqueUri);

String DisqueURI

DisqueURI disqueUri = DisqueURI.create("disque://authentication@localhost:7711,localhost:7712");
DisqueClient client = new DisqueClient(disqueUri);