rabbitex

A simplified RabbitMQ API

License

License

Categories

Categories

IDE Development Tools
GroupId

GroupId

me.breidenbach
ArtifactId

ArtifactId

rabbitex
Last Version

Last Version

1.2
Release Date

Release Date

Type

Type

jar
Description

Description

rabbitex
A simplified RabbitMQ API
Project URL

Project URL

https://github.com/RabbitExpress/RabbitEx-Java
Source Code Management

Source Code Management

https://github.com/RabbitExpress/RabbitEx-Java

Download rabbitex

How to add to project

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

Dependencies

compile (3)

Group / Artifact Type Version
com.rabbitmq : amqp-client jar 3.2.0
org.springframework : spring-context jar 3.2.4.RELEASE
com.google.code.gson : gson jar 2.2.4

test (2)

Group / Artifact Type Version
com.googlecode.jmockit : jmockit jar 1.4
junit : junit jar 4.6

Project Modules

There are no modules declared in this project.

Build Status

RabbitEx-Java & Scala

Version 2.0

Now with a scala backbone that can easily be used by scala apps and a Java wrapper with the same interface from 1.0

So you want to get into async messaging, but there's a lot to learn and it takes too long. While AMQP is a great protocol, it can be daunting for a development team unfamiliar with it. Well pick RabbitMQ and RabbitEx(press). This will allow you to get up and running using a very simple Tibco RVesque subject based addressing system. What's more is that it will be coming in multiple languages, so if your shop is full of polyglots, they can all use the same library.

Create a Connection

This is as simple as the following.

RabbitEx rabbitEx = new RabbitConnectionFactory().rabbitConnection(HOSTNAME, PORT);

Slightly more advanced would be using virtual hosts and authentication:

RabbitEx rabbitEx = new RabbitConnectionFactory().rabbitConnection(HOSTNAME, PORT, VIRTUAL_HOST, USERNAME, PASSWORD);

Using virtual hosts you can separate out environments while using the same Rabbit installation,

e.g. VIRTUAL_HOST = "development" or VIRTUAL_HOST = "test"

Note: The virtual host will need to be set up using the management console (default http://localhost:15672)

Publish a Message

In it's simplest form this is as follows:

rabbitEx.publish(EXCHANGE, SUBJECT, MESSAGES, null);

Exchanges are separations within the rabbit environment. This could be services (e.g. payments, email etc.). It is recommended not to use these for environmental separation (e.g. development and test), and instead use virtual hosts.

Subjects are used to separate messages within the exchange, but wildcards can be used (see later)

The 4th parameter, which is null here, can be used to set an "error exchange" and "error subject", which the consumer can use to notify of any errors processing a message.

Consume a Message

Again, very simple

Consumer consumer = rabbitEx.consume(EXCHANGE, SUBJECT, QUEUE, myHandler);
consumer.start();

myHandler is an object of a type that implements MessageHandler, e.g.

public class MyHandler implements MessageHandler {

  @Override
  public Response handleMessage(String message) {
    System.out.println("Message: " + message);
    return Response.ACK;
  }
}

The MessageHandler interface comes with three simple responses. Response.ACK which means everything is ok. Response.REJECT tells the system there was an issue (nack) and to reject the message Response.REQUEUE tells the system there was an issue and to requeue and try again

Either "REJECT" or "REQUEUE" will use (if sent with the publish call) the ERROR_EXCHANGE and ERROR_SUBJECT fields to send the error along with the action taken (REQUEUE or REJECT)

Queues and Wildcards

Subjects use dot '.' delimited phrases to specify a subject. For instance. 'library.books.fiction' A Queue can be bound to a specific subject, and will only receive messages that were sent to that exact subject phrase.

It is however possible to listen to multiple subjects and to do this we use wildcards.

'#' can be used as a wildcard to find anything in the next level up. e.g. 'library.#' would receive anything sent to library, or library.books, or library.magazines, but would not receive library.books.fiction

'*' can be used to get anything (no matter how many dots are used) so 'library.*' would get library, library.books, library.magazines and library.books.fiction

me.breidenbach

RabbitExpress

Versions

Version
1.2