Skip to content

Commit

Permalink
Merge branch '3.6.0-SNAPSHOT'
Browse files Browse the repository at this point in the history
  • Loading branch information
vietj committed Nov 29, 2018
2 parents 78b4e29 + 9ef3cae commit e0ede62
Show file tree
Hide file tree
Showing 415 changed files with 1,699 additions and 3,166 deletions.
4 changes: 2 additions & 2 deletions amqp-bridge-examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

<groupId>io.vertx</groupId>
<artifactId>amqp-bridge-examples</artifactId>
<version>3.5.3</version>
<version>3.6.0</version>

<dependencies>
<!-- primary deps -->
Expand Down Expand Up @@ -59,7 +59,7 @@
<repositories>
<repository>
<id>staging</id>
<url>https://oss.sonatype.org/content/repositories/iovertx-3783/</url>
<url>https://oss.sonatype.org/content/repositories/iovertx-3811/</url>
</repository>
</repositories>
</profile>
Expand Down
24 changes: 24 additions & 0 deletions amqp-proton-examples/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
= Vert.x Proton examples

Here you will find examples demonstrating the Vert.x Proton AMQP library in action.

This component facilitates AMQP integrations for Vert.x by providing a thin wrapper around the [Apache Qpid](http://qpid.apache.org) Proton-J AMQP 1.0 protocol engine.
Please consult the Vert.x Proton documentation for more information.

**NOTE: The Client examples require a server with AMQP 1.0 support listening at port 5672 on localhost and offering SASL ANONYMOUS.**

For instance, you could use a server such as Apache ActiveMQ (5.x or Artemis), Apache Qpid (Dispatch router, Broker-J or C++ broker), or the Vert.x Proton server example.

== Client

These examples demonstrate messaging between a client sender, client receiver, and a server. They can be used in conjunction with each other to send and receive messages.

The Receiver example consumes incoming messages from an address, prints their content, and accepts them. The Sender example sends a message to that address every second.

link:src/main/java/io/vertx/example/proton/client/Receiver.java[Receiver] +
link:src/main/java/io/vertx/example/proton/client/Sender.java[Sender] +

== Server

This server example listens for incoming connections on port 5672. It prints any messages received from client senders, and periodically sends generated messages to client receivers.
link:src/main/java/io/vertx/example/proton/server/HelloServer.java[HelloServer] +
47 changes: 47 additions & 0 deletions amqp-proton-examples/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<groupId>io.vertx</groupId>
<artifactId>amqp-proton-examples</artifactId>
<version>3.6.0</version>

<dependencies>
<!-- primary deps -->
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-proton</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
<pluginManagement>
<plugins>
<!-- We specify the Maven compiler plugin as we need to set it to Java 1.8 -->
<plugin>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.1</version>
<configuration>
<source>1.8</source>
<target>1.8</target>
</configuration>
</plugin>
</plugins>
</pluginManagement>
</build>

<profiles>
<profile>
<id>staging</id>
<repositories>
<repository>
<id>staging</id>
<url>https://oss.sonatype.org/content/repositories/iovertx-3750/</url>
</repository>
</repositories>
</profile>
</profiles>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
/*
* Copyright 2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.vertx.example.proton.client;

import io.vertx.proton.ProtonClient;
import io.vertx.proton.ProtonConnection;

import org.apache.qpid.proton.amqp.messaging.AmqpValue;

import io.vertx.core.AbstractVerticle;
import io.vertx.example.util.Runner;

public class Receiver extends AbstractVerticle {

private String address = "examples";

// Convenience method so you can run it in your IDE
public static void main(String[] args) {
Runner.runExample(Receiver.class);
}

@Override
public void start() throws Exception {
ProtonClient client = ProtonClient.create(vertx);

client.connect("localhost", 5672, res -> {
if(!res.succeeded()) {
System.out.println("Connect failed: " + res.cause());
return;
}

ProtonConnection connection = res.result();
connection.open();

connection.createReceiver(address).handler((delivery, msg) -> {
String content = (String) ((AmqpValue) msg.getBody()).getValue();
System.out.println("Received message with content: " + content);

// By default, receivers automatically accept (and settle) the delivery
// when the handler returns, if no other disposition has been applied.
// To change this and always manage dispositions yourself, use the
// setAutoAccept method on the receiver.
}).open();
});
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
/*
* Copyright 2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.vertx.example.proton.client;

import io.vertx.proton.ProtonClient;
import io.vertx.proton.ProtonConnection;
import io.vertx.proton.ProtonSender;

import static io.vertx.proton.ProtonHelper.message;

import java.util.concurrent.atomic.AtomicInteger;

import org.apache.qpid.proton.message.Message;

import io.vertx.core.AbstractVerticle;
import io.vertx.example.util.Runner;

public class Sender extends AbstractVerticle {

private String address = "examples";
private AtomicInteger sent = new AtomicInteger();

// Convenience method so you can run it in your IDE
public static void main(String[] args) {
Runner.runExample(Sender.class);
}

@Override
public void start() throws Exception {
ProtonClient client = ProtonClient.create(vertx);

client.connect("localhost", 5672, res -> {
if(!res.succeeded()) {
System.out.println("Connect failed: " + res.cause());
return;
}

ProtonConnection connection = res.result();
connection.open();

ProtonSender sender = connection.createSender(address);

// Can optionally add an openHandler and/or sendQueueDrainHandler
// to await remote sender open completing and credit to send being
// granted. Here we will just schedule sends to happen if there
// is credit at the time.
sender.open();

// Schedule sending of a message every second
System.out.println("Sender created, scheduling sends.");

vertx.setPeriodic(1000, x -> {
if(!sender.sendQueueFull()) {
final int msgNum = sent.incrementAndGet();
Message message = message("Hello " + msgNum);

sender.send(message, delivery -> {
System.out.println(String.format("Message " + msgNum + " was received by the server: remote state=%s", delivery.getRemoteState()));
});

System.out.println("Sent message: " + msgNum);
} else {
System.out.println("No credit to send, waiting.");
}
});
});
}
}
Loading

0 comments on commit e0ede62

Please sign in to comment.