tarantool-queue

Wrapper for Tarantool queue module

License

License

Categories

Categories

Ant Build Tools
GroupId

GroupId

com.nryanov.tarantool
ArtifactId

ArtifactId

tarantool-queue
Last Version

Last Version

0.4
Release Date

Release Date

Type

Type

jar
Description

Description

tarantool-queue
Wrapper for Tarantool queue module
Project URL

Project URL

https://github.com/nryanov/tarantool-queue
Source Code Management

Source Code Management

https://github.com/nryanov/tarantool-queue

Download tarantool-queue

How to add to project

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

Dependencies

compile (6)

Group / Artifact Type Version
com.fasterxml.jackson.core : jackson-databind jar 2.10.1
com.google.auto.service : auto-service jar 1.0-rc6
com.squareup : javapoet jar 1.11.1
com.google.guava : guava jar 28.1-jre
org.tarantool : connector jar 1.9.4
org.slf4j : slf4j-api jar 1.7.30

test (5)

Group / Artifact Type Version
ch.qos.logback : logback-classic jar 1.2.3
org.testcontainers : testcontainers jar 1.12.4
junit : junit jar 4.12
com.google.truth : truth jar 1.0
com.google.testing.compile : compile-testing jar 0.18

Project Modules

There are no modules declared in this project.

TarantoolQueue

Build Status GitHub license Maven Central

It is the wrapper for the TarantoolQueue. This library uses Java annotation processing to generate code for your tasks to be able to easy use your tasks with tarantool's queue.

Features

  • No reflection - only compile-time code generation
  • Supports different queue types: FIFO, FIFO_TTL, LIM_FIFO_TTL (queue module should be at least 1.0.4 version), UTUBE and UTUBE_TTL
  • All methods are strongly typed
  • For some queue types there are convenient methods with additional options

Requirements

  • Java 1.8 or higher
  • Tarantool 1.7.6

Getting Started

Add a dependency to your pom.xml file.

        <dependency>
            <groupId>com.nryanov.tarantool</groupId>
            <artifactId>tarantool-queue</artifactId>
            <version>{version}</version>
        </dependency>

Create a queue

Currently, tarantool-queue module does not support auto bootstraping queues in tarantool, so it is up to you to create initial queues with desired configuration. For example, to create a simple fifo queue in tarantool:

queue = require('queue')
queue.create_tube('fifo_queue', 'fifo', {if_not_exists=true})

Also, keep i mind that it is required to use exactly this name for queue module in tarantool: queue = require('queue')

Create a simple POJO which represents task info:

import org.tarantool.queue.QueueType;
import org.tarantool.queue.annotations.Queue;

@Queue(name = "fifo_queue", type = QueueType.FIFO)
class Task {
 // fields
}

Queue annotation will be used only in compile time to generate convenient wrapper for your task.

QueueType can be FIFO, FIFO_TTL, UTUBE, UTUBE_TTL. The description of each type can be found there: TarantoolQueue. If your tarantool instance has installed queue module with version 1.0.4 or higher than you can also use LIM_FIFO_TTL queue type.

Use

public class Main {
    public static void main(String[] args) {    
        TarantoolClientConfig config = new TarantoolClientConfig();
        config.username = "guest";
        TarantoolClient client = new TarantoolClientImpl("localhost:3301", config);
        
        // also, you can specify custom ObjectMapper 
        TaskManagerFactory managerFactory = new TaskManagerFactory(client);
        TaskQueue taskQueue = managerFactory.taskQueueManager();
        
        Task task = new Task();
        TaskInfo<Task> result = queue.put(task).runSync();
        // ...
        TaskInfo<Task> nextTask = queue.take().runSync();
        // process(nextTask)
        queue.ack(nextTask.id).runSync();
    }
}

Queue interface

public interface QueueManager<T> {
    Operation<T> put(T task);

    Operation<T> release(long taskId);

    Operation<T> ack(long taskId);

    Operation<T> peek(long taskId);

    Operation<T> bury(long taskId);

    Operation<T> take();

    Operation<T> takeWithTimeout(long timeout);

    Operation<T> delete(long taskId);
}

Queues with types FIFO_TTL and UTUBE_TTL support additional method: touch to increase ttl of task.

Queues with types FIFO_TTL, UTUBE, UTUBE_TTL and LIM_FIFO_TTL support additional methods: putWithOptions and releaseWithOptions. Each queue type has it's own builder with specific option list.

Built With

  • Maven - Dependency Management

Versions

Version
0.4