QueueBox library - async queue with routing

Async message queue library using MongoDB as a backend with minimal set of dependencies.

License

License

Categories

Categories

Net
GroupId

GroupId

net.c0f3.labs
ArtifactId

ArtifactId

queue-box
Last Version

Last Version

0.2.1
Release Date

Release Date

Type

Type

jar
Description

Description

QueueBox library - async queue with routing
Async message queue library using MongoDB as a backend with minimal set of dependencies.
Project URL

Project URL

https://github.com/c0f3/queue-box
Source Code Management

Source Code Management

https://github.com/c0f3/queue-box

Download queue-box

How to add to project

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

Dependencies

compile (1)

Group / Artifact Type Version
commons-beanutils : commons-beanutils jar 1.9.4

provided (2)

Group / Artifact Type Version
org.mongodb : mongodb-driver-sync jar 4.1.0
com.fasterxml.jackson.core : jackson-databind jar 2.10.3

test (5)

Group / Artifact Type Version
org.slf4j : slf4j-api jar 1.7.30
ch.qos.logback : logback-classic jar 1.2.3
org.assertj : assertj-core jar 3.15.0
org.junit.jupiter : junit-jupiter-engine jar 5.6.0
org.testcontainers : junit-jupiter jar 1.13.0

Project Modules

There are no modules declared in this project.

QueueBox - async queue engine based on MongoDB

Async java message queue using MongoDB as a backend.

This fork use the latest MongoDB version with the latest Java Driver and contains wrapper that hide MongoDB driver API and allow using plain java objects in queue.

Unit tests based on real MongoDB with testcontainers.

issues and feature requests

Features

  • totally async and non-blocking multithreading (maybe used in clustered software)
  • Message selection and/or count via MongoDB query
  • Distributes across machines via MongoDB
  • Message priority
  • Delayed messages
  • Message routing
  • Running message timeout and redeliver
  • Atomic acknowledge and send together
  • Easy index creation based only on payload
  • work with the latest MongoDB (4.2)
  • you can use any other storage system by implementing interface

Jar

To add the library as a jar simply Build the project and use the queue-box-0.0.1.jar from the created target directory!

Maven

To add the library as a local, per-project dependency use Maven! Simply add a dependency on to your project's pom.xml file such as:

<dependency>
	<groupId>net.c0f3.labs</groupId>
	<artifactId>queue-box</artifactId>
	<version>0.2.1</version>
</dependency>

Usage example

  • starting QueueBox instance
  • creating listener for specific "destination"
  • creating and sending some simple message presented as POJO
public final class Main {
    public static void main(String[] args) throws InterruptedException, IOException {
        final String defaultSource = "just_source";
        final String defaultDestination = "just_destination";

        Properties properties = new Properties();
        properties.load(ExampleWithMain.class.getResourceAsStream("mongodb.properties"));
        MongoRoutedQueueBox<JustPojoRouted> queueBox = new MongoRoutedQueueBox<>(
                properties,
                JustPojoRouted.class
        );
        queueBox.start(); // init internal thread pool ant begin periodic query to db

        final JustPojoRouted pojo = new JustPojoRouted(13, "string message for 13");
        pojo.setSource(defaultSource);
        pojo.setDestination(defaultDestination);

        queueBox.subscribe(new QueueConsumer<JustPojoRouted>() {
            @Override
            public void onPacket(MessageContainer<JustPojoRouted> message) {
                JustPojoRouted recvPojo = message.getMessage();
                System.out.println("received packet:"+recvPojo);
                message.done(); // accepting message
            }

            @Override
            public String getConsumerId() {
                return defaultDestination; // destinations that this consumer accepts
            }
        });

        Future future = queueBox.queue(pojo);

        while (!future.isDone()) {
            Thread.sleep(5);
        }

        System.out.println("send packet: "+pojo);

    }
}

Also you can use just core library without wrapper, as it described in original README.

public final class Main {

    public static void main(final String[] args) throws UnknownHostException {
        final Queue queue = new Queue(new MongoClient().getDB("testing").getCollection("messages"));
        queue.send(new BasicDBObject());
        final BasicDBObject message = queue.get(new BasicDBObject(), 60);
        queue.ack(message);
    }
}

Documentation

Found in the source itself, take a look!

Project Build

For testing install docker.

mvn clean install

We must know our heroes!

This version based on the original version authored by Gaillard from here and impoved by Uromahn

net.c0f3.labs
Watch! Star! Fork!

Versions

Version
0.2.1
0.1.3
0.1.2
0.1.1
0.1.0