Skip to content

Commit ca163c3

Browse files
committed
Inital support for rabbitmq
1 parent e96bf07 commit ca163c3

17 files changed

+2100
-2
lines changed

.gitignore

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
.DS_Store
2+
.gradle
3+
.idea
4+
.classpath
5+
.project
6+
.settings
7+
.yardoc
8+
.yardopts
9+
bin
10+
build
11+
target
12+
out
13+
*.iml
14+
*.ipr
15+
*.iws
16+
test-output
17+
Scratch.java
18+
ScratchTest.java
19+
test-results
20+
test-tmp
21+
*.class
22+
src/gen
23+
src/main/resources/vertx-js/*.js
24+
src/test/resources/vertx-js/*.js

README.md

+113-2
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,113 @@
1-
# vertx-rabbitmq-service
2-
Vert.x RabbitMQ Service
1+
# RabbitMQ Service for Vert.x
2+
3+
A Vert.x service allowing applications to seamlessly interact with a RabbitMQ broker (amqp 0.9)
4+
5+
# Getting Started
6+
7+
## Maven
8+
9+
Add the following dependency to your maven project
10+
11+
```xml
12+
<dependencies>
13+
<dependency>
14+
<groupId>io.vertx</groupId>
15+
<artifactId>vertx-rabbitmq-service</artifactId>
16+
<version>$version</version>
17+
</dependency>
18+
</dependencies>
19+
```
20+
21+
## Gradle ##
22+
23+
Add the following dependency to your gradle project
24+
25+
```groovy
26+
dependencies {
27+
compile("io.vertx:vertx-rabbitmq-service:$version")
28+
}
29+
```
30+
31+
## Deploy as a service
32+
33+
The easiest way to get started is to deploy it as a service
34+
35+
```java
36+
Vertx vertx = Vertx.vertx();
37+
vertx.deployVerticle("service:io.vertx:rabbitmq-service");
38+
```
39+
40+
This will make the RabbitMQService available as a [Service Proxy](#service-proxy) to be used throughout your application.
41+
42+
## Service Proxy
43+
44+
Assuming you already have the service deployed, to retrieve the RabbitMQService (from inside a Verticle for example)
45+
46+
```java
47+
public class MyVerticle extends AbstractVerticle {
48+
49+
@Override
50+
public void start() {
51+
RabbitMQService service = RabbitMQService.createEventBusProxy(vertx, "vertx.rabbitmq");
52+
...
53+
}
54+
```
55+
56+
This will create the service proxy allowing you to call the RabbitMQService API methods instead of having to send
57+
messages over the event bus. See [Service Proxy](https://github.com/vert-x3/service-proxy) for more information.
58+
59+
# Operations
60+
61+
The following are some examples of the operations supported by the RabbitMQService API. Consult the javadoc/documentation
62+
for detailed information on all API methods.
63+
64+
## Publish
65+
66+
Publish a message to a queue
67+
68+
```java
69+
JsonObject message = new JsonObject().put("body", "Hello RabbitMQ, from Vert.x !");
70+
service.basicPublish("", "my.queue", message, pubResult -> {
71+
if (pubResult.succeeded() {
72+
System.out.println("Message published !");
73+
} else {
74+
pubResult.cause().printStackTrace();
75+
}
76+
});
77+
```
78+
79+
## Consume
80+
81+
Consume messages from a queue
82+
83+
```java
84+
// Create the event bus handler which messages will be sent to
85+
vertx.eventBus().consumer("my.address", msg -> {
86+
JsonObject json = (JsonObject) msg.body();
87+
System.out.println("Got message: " + json.getString("body"));
88+
});
89+
90+
// Setup the link between rabbitmq consumer and event bus address
91+
service.basicConsume("my.queue", "my.address", consumeResult -> {
92+
if (consumeResult.succeeded()) {
93+
System.out.println("RabbitMQ consumer created !");
94+
} else {
95+
consumeResult.cause().printStackTrace();
96+
}
97+
});
98+
```
99+
100+
## Get
101+
102+
Will get a message from a queue
103+
104+
```java
105+
service.basicGet("my.queue", true, getResult -> {
106+
if (getResult.succeeded()) {
107+
JsonObject msg = getResult.result();
108+
System.out.println("Got message: " + msg.getString("body"));
109+
} else {
110+
getResult.cause().printStackTrace();
111+
}
112+
});
113+
```

pom.xml

+97
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0"
3+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
4+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
5+
6+
<parent>
7+
<groupId>io.vertx</groupId>
8+
<artifactId>vertx-ext-parent</artifactId>
9+
<version>1</version>
10+
</parent>
11+
12+
<modelVersion>4.0.0</modelVersion>
13+
14+
<artifactId>vertx-rabbitmq-service</artifactId>
15+
<version>3.0.0-SNAPSHOT</version>
16+
17+
<properties>
18+
<stack.version>3.0.0-SNAPSHOT</stack.version>
19+
<service.proxy.version>3.0.0-SNAPSHOT</service.proxy.version>
20+
<service.factory.version>3.0.0-SNAPSHOT</service.factory.version>
21+
<rabbitmq.client.version>3.4.3</rabbitmq.client.version>
22+
</properties>
23+
24+
<dependencyManagement>
25+
<dependencies>
26+
<dependency>
27+
<groupId>io.vertx</groupId>
28+
<artifactId>vertx-dependencies</artifactId>
29+
<version>${stack.version}</version>
30+
<type>pom</type>
31+
<scope>import</scope>
32+
</dependency>
33+
</dependencies>
34+
</dependencyManagement>
35+
36+
<dependencies>
37+
<dependency>
38+
<groupId>io.vertx</groupId>
39+
<artifactId>vertx-core</artifactId>
40+
</dependency>
41+
<dependency>
42+
<groupId>io.vertx</groupId>
43+
<artifactId>vertx-service-proxy</artifactId>
44+
</dependency>
45+
<dependency>
46+
<groupId>io.vertx</groupId>
47+
<artifactId>vertx-service-factory</artifactId>
48+
</dependency>
49+
<dependency>
50+
<groupId>io.vertx</groupId>
51+
<artifactId>vertx-codegen</artifactId>
52+
<optional>true</optional>
53+
</dependency>
54+
<dependency>
55+
<groupId>io.vertx</groupId>
56+
<artifactId>vertx-lang-groovy</artifactId>
57+
<optional>true</optional>
58+
</dependency>
59+
<dependency>
60+
<groupId>io.vertx</groupId>
61+
<artifactId>vertx-lang-js</artifactId>
62+
<optional>true</optional>
63+
</dependency>
64+
65+
<dependency>
66+
<groupId>io.vertx</groupId>
67+
<artifactId>vertx-docgen</artifactId>
68+
<optional>true</optional>
69+
</dependency>
70+
<dependency>
71+
<groupId>io.vertx</groupId>
72+
<artifactId>vertx-codetrans</artifactId>
73+
<optional>true</optional>
74+
</dependency>
75+
76+
<dependency>
77+
<groupId>com.rabbitmq</groupId>
78+
<artifactId>amqp-client</artifactId>
79+
<version>${rabbitmq.client.version}</version>
80+
</dependency>
81+
82+
<!-- Testing -->
83+
<dependency>
84+
<groupId>junit</groupId>
85+
<artifactId>junit</artifactId>
86+
<version>4.11</version>
87+
<scope>test</scope>
88+
</dependency>
89+
<dependency>
90+
<groupId>io.vertx</groupId>
91+
<artifactId>vertx-core</artifactId>
92+
<type>test-jar</type>
93+
<scope>test</scope>
94+
</dependency>
95+
96+
</dependencies>
97+
</project>

0 commit comments

Comments
 (0)