miniature-queue
miniature-queue
is a Message Queue abstraction layer inspired by feign and JDBI. It uses annotation based meta-programming to bind an interface to an Message Queue implementation.
Example
@Queue("chat", queueTypeHint=QueueType.FANOUT_QUEUE)
interface Chat {
@Publish
void publishMessage(String message);
@Handle
void receiveMessage(Function<String, Boolean> action);
}
MessageQueue queue = Queuify.builder().server(createServerObject()).target(MessageQueue.class);
// Set up a listener for new messages.
queue.receiveMessage((x) -> { System.out.println(x); return true; } );
// Sends hello down the line
queue.publishMessage("Hello");
Queue types
Worker Queues
In a worker queue each message is sent to only one listener. The message publisher sends a fire-and-forget message out to the queue for the work to be done.
Fanout (or Publish/Subscribe)
In a fanout queue each message is sent to every listener. The message publisher sends a fire-and-forget message out to the queue for the listners to be informed.
Message Queues supported
- Rabbit MQ via
minature-queue-rabbitmq
package. - Redis via the
miniature-queue-jedis
package. Note: This only supports FAN_OUT queues. - MQLight via the
miniature-queue-mqlight
package. Note: This is a work in progress.
Encoding/Decoding objects
- Java serialization (in core)
- UTF-8 Strings (in core)
- JSON via GSON via
miniature-queue-gson
package. - JSON via Jackson via the
miniature-queue-jackson
package.
Running the tests
Most of the tests for this project are integration tests rather than unit. As such they require the MQ server to be running. In order to make that happen we use Docker. You require either the enviroment variables DOCKER_CERT_PATH
and DOCKER_HOST
set, or to be running Docker on localhost with the standard port.