This is an automated email from the ASF dual-hosted git repository.

tabish pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/qpid-protonj2.git


The following commit(s) were added to refs/heads/main by this push:
     new 5561d3a  PROTON-2381 Update examples to allow control of connection 
options
5561d3a is described below

commit 5561d3a4dbf6b484895ffc0e69ef470d878a61f8
Author: Timothy Bish <[email protected]>
AuthorDate: Thu May 6 14:46:11 2021 -0400

    PROTON-2381 Update examples to allow control of connection options
    
    Provide means of controlling the host and port of the connection as well
    as providing authentication details in order to allow connection to
    peers on different machines or that don't allow anonymous connections.
---
 protonj2-client-examples/README.md                 |  8 ++++++--
 .../qpid/protonj2/client/examples/HelloWorld.java  | 19 ++++++++++++-------
 .../client/examples/LargeMessageReceiver.java      | 18 ++++++++++++------
 .../client/examples/LargeMessageSender.java        | 18 ++++++++++++------
 .../qpid/protonj2/client/examples/Receive.java     | 22 ++++++++++++++--------
 .../qpid/protonj2/client/examples/Request.java     | 18 ++++++++++++------
 .../qpid/protonj2/client/examples/Respond.java     | 15 ++++++++++-----
 .../apache/qpid/protonj2/client/examples/Send.java | 22 ++++++++++++++--------
 .../client/examples/StreamingFileReceiver.java     | 17 +++++++++++------
 .../client/examples/StreamingFileSender.java       | 17 +++++++++++------
 .../client/examples/TransactedReceiver.java        | 15 ++++++++++-----
 .../protonj2/client/examples/TransactedSender.java | 15 ++++++++++-----
 .../examples/reconnect/ReconnectReceiver.java      | 20 +++++++++++---------
 .../client/examples/reconnect/ReconnectSender.java | 18 ++++++++++--------
 14 files changed, 155 insertions(+), 87 deletions(-)

diff --git a/protonj2-client-examples/README.md 
b/protonj2-client-examples/README.md
index ea875ce..2528e4a 100644
--- a/protonj2-client-examples/README.md
+++ b/protonj2-client-examples/README.md
@@ -12,8 +12,8 @@ Now you can run the examples using commands of the format:
 
     Windows: java -cp "target\classes\;target\dependency\*" 
org.apache.qpid.protonj2.client.examples.HelloWorld
 
-NOTE: The examples expect to use a Queue named "queue". You may need to create
-this before running the examples, depending on the broker/peer you are using.
+NOTE: The examples expect to use a variety of addresses that are specific to 
one (or a pair of examples).
+You may need to create these before running the examples, depending on the 
broker/peer you are using.
 
 NOTE: By default the examples can only connect anonymously. A username and
 password with which the connection can authenticate with the server may be set
@@ -23,6 +23,10 @@ through system properties named USER and PASSWORD 
respectively. E.g:
 
     Windows: java -DUSER=guest -DPASSWORD=guest -cp 
"target\classes\;target\dependency\*" 
org.apache.qpid.protonj2.client.examples.HelloWorld
 
+By default the examples attempt to connect to a peer on the same machine 
however if the remote you are
+attempting to test against is located on a different host or uses a 
non-standard AMQP port then the HOST
+and PORT system properties can be provided to control where the examples will 
attempt their connections.
+
 NOTE: The earlier build command will cause Maven to resolve the client artifact
 dependencies against its local and remote repositories. If you wish to use a
 locally-built client, ensure to "mvn install" it in your local repo first.
diff --git 
a/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/HelloWorld.java
 
b/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/HelloWorld.java
index 7e54a3e..73c411a 100644
--- 
a/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/HelloWorld.java
+++ 
b/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/HelloWorld.java
@@ -22,6 +22,7 @@ package org.apache.qpid.protonj2.client.examples;
 
 import org.apache.qpid.protonj2.client.Client;
 import org.apache.qpid.protonj2.client.Connection;
+import org.apache.qpid.protonj2.client.ConnectionOptions;
 import org.apache.qpid.protonj2.client.Delivery;
 import org.apache.qpid.protonj2.client.Message;
 import org.apache.qpid.protonj2.client.Receiver;
@@ -30,16 +31,20 @@ import org.apache.qpid.protonj2.client.Sender;
 public class HelloWorld {
 
     public static void main(String[] args) throws Exception {
-        String serverHost = "localhost";
-        int serverPort = 5672;
-        String address = "hello-world-example";
+        final String serverHost = System.getProperty("HOST", "localhost");
+        final int serverPort = Integer.getInteger("PORT", 5672);
+        final String address = System.getProperty("ADDRESS", 
"hello-world-example");
 
-        Client client = Client.create();
+        final Client client = Client.create();
 
-        try (Connection connection = client.connect(serverHost, serverPort)) {
-            Receiver receiver = connection.openReceiver(address);
+        final ConnectionOptions options = new ConnectionOptions();
+        options.user(System.getProperty("USER"));
+        options.password(System.getProperty("PASSWORD"));
+
+        try (Connection connection = client.connect(serverHost, serverPort, 
options);
+             Receiver receiver = connection.openReceiver(address);
+             Sender sender = connection.openSender(address)) {
 
-            Sender sender = connection.openSender(address);
             sender.send(Message.create("Hello World"));
 
             Delivery delivery = receiver.receive();
diff --git 
a/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/LargeMessageReceiver.java
 
b/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/LargeMessageReceiver.java
index 06b92ae..2889414 100644
--- 
a/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/LargeMessageReceiver.java
+++ 
b/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/LargeMessageReceiver.java
@@ -25,6 +25,7 @@ import java.util.Arrays;
 
 import org.apache.qpid.protonj2.client.Client;
 import org.apache.qpid.protonj2.client.Connection;
+import org.apache.qpid.protonj2.client.ConnectionOptions;
 import org.apache.qpid.protonj2.client.StreamDelivery;
 import org.apache.qpid.protonj2.client.StreamReceiver;
 import org.apache.qpid.protonj2.client.StreamReceiverMessage;
@@ -32,14 +33,19 @@ import 
org.apache.qpid.protonj2.client.StreamReceiverMessage;
 public class LargeMessageReceiver {
 
     public static void main(String[] args) throws Exception {
-        String serverHost = "localhost";
-        int serverPort = 5672;
-        String address = "large-message-example";
+        final String serverHost = System.getProperty("HOST", "localhost");
+        final int serverPort = Integer.getInteger("PORT", 5672);
+        final String address = System.getProperty("ADDRESS", 
"large-message-example");
 
-        Client client = Client.create();
+        final Client client = Client.create();
+
+        final ConnectionOptions options = new ConnectionOptions();
+        options.user(System.getProperty("USER"));
+        options.password(System.getProperty("PASSWORD"));
+
+        try (Connection connection = client.connect(serverHost, serverPort, 
options);
+             StreamReceiver receiver = connection.openStreamReceiver(address)) 
{
 
-        try (Connection connection = client.connect(serverHost, serverPort)) {
-            StreamReceiver receiver = connection.openStreamReceiver(address);
             StreamDelivery delivery = receiver.receive();
             StreamReceiverMessage message = delivery.message();
             InputStream inputStream = message.body();
diff --git 
a/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/LargeMessageSender.java
 
b/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/LargeMessageSender.java
index 89f2f7a..cba720e 100644
--- 
a/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/LargeMessageSender.java
+++ 
b/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/LargeMessageSender.java
@@ -25,6 +25,7 @@ import java.util.Arrays;
 
 import org.apache.qpid.protonj2.client.Client;
 import org.apache.qpid.protonj2.client.Connection;
+import org.apache.qpid.protonj2.client.ConnectionOptions;
 import org.apache.qpid.protonj2.client.OutputStreamOptions;
 import org.apache.qpid.protonj2.client.StreamSender;
 import org.apache.qpid.protonj2.client.StreamSenderMessage;
@@ -32,14 +33,19 @@ import org.apache.qpid.protonj2.client.StreamSenderMessage;
 public class LargeMessageSender {
 
     public static void main(String[] args) throws Exception {
-        String serverHost = "localhost";
-        int serverPort = 5672;
-        String address = "large-message-example";
+        final String serverHost = System.getProperty("HOST", "localhost");
+        final int serverPort = Integer.getInteger("PORT", 5672);
+        final String address = System.getProperty("ADDRESS", 
"large-message-example");
 
-        Client client = Client.create();
+        final Client client = Client.create();
+
+        final ConnectionOptions options = new ConnectionOptions();
+        options.user(System.getProperty("USER"));
+        options.password(System.getProperty("PASSWORD"));
+
+        try (Connection connection = client.connect(serverHost, serverPort, 
options);
+             StreamSender sender = connection.openStreamSender(address)) {
 
-        try (Connection connection = client.connect(serverHost, serverPort)) {
-            StreamSender sender = connection.openStreamSender(address);
             StreamSenderMessage message = sender.beginMessage();
 
             final byte[] buffer = new byte[100];
diff --git 
a/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/Receive.java
 
b/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/Receive.java
index c4d24e8..ad1ef8d 100644
--- 
a/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/Receive.java
+++ 
b/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/Receive.java
@@ -18,24 +18,30 @@ package org.apache.qpid.protonj2.client.examples;
 
 import org.apache.qpid.protonj2.client.Client;
 import org.apache.qpid.protonj2.client.Connection;
+import org.apache.qpid.protonj2.client.ConnectionOptions;
 import org.apache.qpid.protonj2.client.Delivery;
 import org.apache.qpid.protonj2.client.Message;
 import org.apache.qpid.protonj2.client.Receiver;
 
 public class Receive {
 
+    private static final int MESSAGE_COUNT = 100;
+
     public static void main(String[] args) throws Exception {
-        String serverHost = "localhost";
-        int serverPort = 5672;
-        String address = "send-receive-example";
-        int count = 100;
+        final String serverHost = System.getProperty("HOST", "localhost");
+        final int serverPort = Integer.getInteger("PORT", 5672);
+        final String address = System.getProperty("ADDRESS", 
"send-receive-example");
+
+        final Client client = Client.create();
 
-        Client client = Client.create();
+        final ConnectionOptions options = new ConnectionOptions();
+        options.user(System.getProperty("USER"));
+        options.password(System.getProperty("PASSWORD"));
 
-        try (Connection connection = client.connect(serverHost, serverPort)) {
-            Receiver receiver = connection.openReceiver(address);
+        try (Connection connection = client.connect(serverHost, serverPort, 
options);
+             Receiver receiver = connection.openReceiver(address)) {
 
-            for (int i = 0; i < count; ++i) {
+            for (int i = 0; i < MESSAGE_COUNT; ++i) {
                 Delivery delivery = receiver.receive();
                 Message<String> message = delivery.message();
 
diff --git 
a/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/Request.java
 
b/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/Request.java
index 3e0dc90..4aabd94 100644
--- 
a/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/Request.java
+++ 
b/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/Request.java
@@ -20,6 +20,7 @@ import java.util.concurrent.TimeUnit;
 
 import org.apache.qpid.protonj2.client.Client;
 import org.apache.qpid.protonj2.client.Connection;
+import org.apache.qpid.protonj2.client.ConnectionOptions;
 import org.apache.qpid.protonj2.client.Delivery;
 import org.apache.qpid.protonj2.client.Message;
 import org.apache.qpid.protonj2.client.Receiver;
@@ -32,14 +33,19 @@ import org.apache.qpid.protonj2.client.SenderOptions;
 public class Request {
 
     public static void main(String[] args) throws Exception {
-        String serverHost = "localhost";
-        int serverPort = 5672;
-        String address = "request-respond-example";
+        final String serverHost = System.getProperty("HOST", "localhost");
+        final int serverPort = Integer.getInteger("PORT", 5672);
+        final String address = System.getProperty("ADDRESS", 
"request-respond-example");
 
-        Client client = Client.create();
+        final Client client = Client.create();
+
+        final ConnectionOptions options = new ConnectionOptions();
+        options.user(System.getProperty("USER"));
+        options.password(System.getProperty("PASSWORD"));
+
+        try (Connection connection = client.connect(serverHost, serverPort, 
options);
+             Receiver dynamicReceiver = connection.openDynamicReceiver()) {
 
-        try (Connection connection = client.connect(serverHost, serverPort)) {
-            Receiver dynamicReceiver = connection.openDynamicReceiver();
             String dynamicAddress = dynamicReceiver.address();
             System.out.println("Waiting for response to requests on address: " 
+ dynamicAddress);
 
diff --git 
a/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/Respond.java
 
b/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/Respond.java
index ee09bfd..bf3d795 100644
--- 
a/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/Respond.java
+++ 
b/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/Respond.java
@@ -20,6 +20,7 @@ import java.util.concurrent.TimeUnit;
 
 import org.apache.qpid.protonj2.client.Client;
 import org.apache.qpid.protonj2.client.Connection;
+import org.apache.qpid.protonj2.client.ConnectionOptions;
 import org.apache.qpid.protonj2.client.Delivery;
 import org.apache.qpid.protonj2.client.Message;
 import org.apache.qpid.protonj2.client.Receiver;
@@ -32,13 +33,17 @@ import org.apache.qpid.protonj2.client.Sender;
 public class Respond {
 
     public static void main(String[] args) throws Exception {
-        String serverHost = "localhost";
-        int serverPort = 5672;
-        String address = "request-respond-example";
+        final String serverHost = System.getProperty("HOST", "localhost");
+        final int serverPort = Integer.getInteger("PORT", 5672);
+        final String address = System.getProperty("ADDRESS", 
"request-respond-example");
 
-        Client client = Client.create();
+        final Client client = Client.create();
 
-        try (Connection connection = client.connect(serverHost, serverPort)) {
+        final ConnectionOptions options = new ConnectionOptions();
+        options.user(System.getProperty("USER"));
+        options.password(System.getProperty("PASSWORD"));
+
+        try (Connection connection = client.connect(serverHost, serverPort, 
options)) {
             ReceiverOptions receiverOptions = new ReceiverOptions();
             receiverOptions.sourceOptions().capabilities("queue");
 
diff --git 
a/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/Send.java
 
b/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/Send.java
index 5f1f72a..fdacb2f 100644
--- 
a/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/Send.java
+++ 
b/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/Send.java
@@ -18,24 +18,30 @@ package org.apache.qpid.protonj2.client.examples;
 
 import org.apache.qpid.protonj2.client.Client;
 import org.apache.qpid.protonj2.client.Connection;
+import org.apache.qpid.protonj2.client.ConnectionOptions;
 import org.apache.qpid.protonj2.client.Message;
 import org.apache.qpid.protonj2.client.Sender;
 import org.apache.qpid.protonj2.client.Tracker;
 
 public class Send {
 
+    private static final int MESSAGE_COUNT = 100;
+
     public static void main(String[] argv) throws Exception {
-        String serverHost = "localhost";
-        int serverPort = 5672;
-        String address = "send-receive-example";
-        int count = 100;
+        final String serverHost = System.getProperty("HOST", "localhost");
+        final int serverPort = Integer.getInteger("PORT", 5672);
+        final String address = System.getProperty("ADDRESS", 
"send-receive-example");
+
+        final Client client = Client.create();
 
-        Client client = Client.create();
+        final ConnectionOptions options = new ConnectionOptions();
+        options.user(System.getProperty("USER"));
+        options.password(System.getProperty("PASSWORD"));
 
-        try (Connection connection = client.connect(serverHost, serverPort)) {
-            Sender sender = connection.openSender(address);
+        try (Connection connection = client.connect(serverHost, serverPort, 
options);
+             Sender sender = connection.openSender(address)) {
 
-            for (int i = 0; i < count; ++i) {
+            for (int i = 0; i < MESSAGE_COUNT; ++i) {
                 Message<String> message = Message.create(String.format("Hello 
World! [%s]", i));
                 Tracker tracker = sender.send(message);
                 tracker.awaitSettlement();
diff --git 
a/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/StreamingFileReceiver.java
 
b/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/StreamingFileReceiver.java
index 4c5586e..bbe9acd 100644
--- 
a/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/StreamingFileReceiver.java
+++ 
b/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/StreamingFileReceiver.java
@@ -21,6 +21,7 @@ import java.io.FileOutputStream;
 
 import org.apache.qpid.protonj2.client.Client;
 import org.apache.qpid.protonj2.client.Connection;
+import org.apache.qpid.protonj2.client.ConnectionOptions;
 import org.apache.qpid.protonj2.client.StreamDelivery;
 import org.apache.qpid.protonj2.client.StreamReceiver;
 import org.apache.qpid.protonj2.client.StreamReceiverMessage;
@@ -42,14 +43,18 @@ public class StreamingFileReceiver {
             System.exit(1);
         }
 
-        String fileNameKey = "filename";
-        String serverHost = System.getProperty("server_host", "localhost");
-        int serverPort = Integer.getInteger("server_port", 5672);
-        String address = System.getProperty("address", "file-transfer");
+        final String fileNameKey = "filename";
+        final String serverHost = System.getProperty("HOST", "localhost");
+        final int serverPort = Integer.getInteger("PORT", 5672);
+        final String address = System.getProperty("ADDRESS", "file-transfer");
 
-        Client client = Client.create();
+        final Client client = Client.create();
 
-        try (Connection connection = client.connect(serverHost, serverPort);
+        final ConnectionOptions options = new ConnectionOptions();
+        options.user(System.getProperty("USER"));
+        options.password(System.getProperty("PASSWORD"));
+
+        try (Connection connection = client.connect(serverHost, serverPort, 
options);
              StreamReceiver receiver = connection.openStreamReceiver(address)) 
{
 
             StreamDelivery delivery = receiver.receive();
diff --git 
a/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/StreamingFileSender.java
 
b/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/StreamingFileSender.java
index e4478b5..380b1c8 100644
--- 
a/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/StreamingFileSender.java
+++ 
b/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/StreamingFileSender.java
@@ -23,6 +23,7 @@ import java.io.OutputStream;
 
 import org.apache.qpid.protonj2.client.Client;
 import org.apache.qpid.protonj2.client.Connection;
+import org.apache.qpid.protonj2.client.ConnectionOptions;
 import org.apache.qpid.protonj2.client.StreamSender;
 import org.apache.qpid.protonj2.client.StreamSenderMessage;
 
@@ -43,14 +44,18 @@ public class StreamingFileSender {
             System.exit(1);
         }
 
-        String fileNameKey = "filename";
-        String serverHost = System.getProperty("server_host", "localhost");
-        int serverPort = Integer.getInteger("server_port", 5672);
-        String address = System.getProperty("address", "file-transfer");
+        final String fileNameKey = "filename";
+        final String serverHost = System.getProperty("HOST", "localhost");
+        final int serverPort = Integer.getInteger("PORT", 5672);
+        final String address = System.getProperty("ADDRESS", "file-transfer");
 
-        Client client = Client.create();
+        final Client client = Client.create();
 
-        try (Connection connection = client.connect(serverHost, serverPort);
+        final ConnectionOptions options = new ConnectionOptions();
+        options.user(System.getProperty("USER"));
+        options.password(System.getProperty("PASSWORD"));
+
+        try (Connection connection = client.connect(serverHost, serverPort, 
options);
              StreamSender sender = connection.openStreamSender(address);
              FileInputStream inputStream = new FileInputStream(inputFile)) {
 
diff --git 
a/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/TransactedReceiver.java
 
b/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/TransactedReceiver.java
index f239446..959b1c2 100644
--- 
a/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/TransactedReceiver.java
+++ 
b/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/TransactedReceiver.java
@@ -22,6 +22,7 @@ package org.apache.qpid.protonj2.client.examples;
 
 import org.apache.qpid.protonj2.client.Client;
 import org.apache.qpid.protonj2.client.Connection;
+import org.apache.qpid.protonj2.client.ConnectionOptions;
 import org.apache.qpid.protonj2.client.Delivery;
 import org.apache.qpid.protonj2.client.Message;
 import org.apache.qpid.protonj2.client.Receiver;
@@ -30,13 +31,17 @@ import org.apache.qpid.protonj2.client.Session;
 public class TransactedReceiver {
 
     public static void main(String[] args) throws Exception {
-        String serverHost = "localhost";
-        int serverPort = 5672;
-        String address = "transaction-example";
+        final String serverHost = System.getProperty("HOST", "localhost");
+        final int serverPort = Integer.getInteger("PORT", 5672);
+        final String address = System.getProperty("ADDRESS", 
"transaction-example");
 
-        Client client = Client.create();
+        final Client client = Client.create();
 
-        try (Connection connection = client.connect(serverHost, serverPort)) {
+        final ConnectionOptions options = new ConnectionOptions();
+        options.user(System.getProperty("USER"));
+        options.password(System.getProperty("PASSWORD"));
+
+        try (Connection connection = client.connect(serverHost, serverPort, 
options)) {
             Session session = connection.openSession();
             Receiver receiver = session.openReceiver(address);
 
diff --git 
a/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/TransactedSender.java
 
b/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/TransactedSender.java
index 366619e..48dc395 100644
--- 
a/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/TransactedSender.java
+++ 
b/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/TransactedSender.java
@@ -22,6 +22,7 @@ package org.apache.qpid.protonj2.client.examples;
 
 import org.apache.qpid.protonj2.client.Client;
 import org.apache.qpid.protonj2.client.Connection;
+import org.apache.qpid.protonj2.client.ConnectionOptions;
 import org.apache.qpid.protonj2.client.Message;
 import org.apache.qpid.protonj2.client.Sender;
 import org.apache.qpid.protonj2.client.Session;
@@ -29,13 +30,17 @@ import org.apache.qpid.protonj2.client.Session;
 public class TransactedSender {
 
     public static void main(String[] args) throws Exception {
-        String serverHost = "localhost";
-        int serverPort = 5672;
-        String address = "transaction-example";
+        final String serverHost = System.getProperty("HOST", "localhost");
+        final int serverPort = Integer.getInteger("PORT", 5672);
+        final String address = System.getProperty("ADDRESS", 
"transaction-example");
 
-        Client client = Client.create();
+        final Client client = Client.create();
 
-        try (Connection connection = client.connect(serverHost, serverPort)) {
+        final ConnectionOptions options = new ConnectionOptions();
+        options.user(System.getProperty("USER"));
+        options.password(System.getProperty("PASSWORD"));
+
+        try (Connection connection = client.connect(serverHost, serverPort, 
options)) {
             Session session = connection.openSession();
             Sender sender = connection.openSender(address);
 
diff --git 
a/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/reconnect/ReconnectReceiver.java
 
b/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/reconnect/ReconnectReceiver.java
index 5fe898d..4a755d3 100644
--- 
a/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/reconnect/ReconnectReceiver.java
+++ 
b/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/reconnect/ReconnectReceiver.java
@@ -29,16 +29,18 @@ public class ReconnectReceiver {
 
     private static final int MESSAGE_COUNT = 10;
 
-    private static String serverHost = "localhost";
-    private static int serverPort = 5672;
-    private static String address = "reconnect-receiver-examples";
+    public static void main(String[] args) throws Exception {
+        final String serverHost = System.getProperty("HOST", "localhost");
+        final int serverPort = Integer.getInteger("PORT", 5672);
+        final String address = System.getProperty("ADDRESS", 
"reconnect-examples");
+        final String backupServerHost = System.getProperty("BACKUP_HOST");
+        final int backupServerPort = Integer.getInteger("BACKUP_PORT", 5672);
 
-    private static String backupServerHost = 
System.getProperty("backup_server_host");
-    private static int backupServerPort = 
Integer.getInteger("backup_server_port", 5672);
+        final Client client = Client.create();
 
-    public static void main(String[] args) throws Exception {
-        Client client = Client.create();
-        ConnectionOptions connectionOpts = new ConnectionOptions();
+        final ConnectionOptions connectionOpts = new ConnectionOptions();
+        connectionOpts.user(System.getProperty("USER"));
+        connectionOpts.password(System.getProperty("PASSWORD"));
         connectionOpts.reconnectEnabled(true);
 
         if (backupServerHost != null) {
@@ -51,7 +53,7 @@ public class ReconnectReceiver {
             for (int receivedCount = 0; receivedCount < MESSAGE_COUNT; 
++receivedCount) {
                 Delivery delivery = receiver.receive();
                 Message<String> message = delivery.message();
-                System.out.print(message.body());
+                System.out.println(message.body());
             }
         } catch (Exception exp) {
             System.out.println("Caught exception, exiting.");
diff --git 
a/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/reconnect/ReconnectSender.java
 
b/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/reconnect/ReconnectSender.java
index 8d02ec3..47135d0 100644
--- 
a/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/reconnect/ReconnectSender.java
+++ 
b/protonj2-client-examples/src/main/java/org/apache/qpid/protonj2/client/examples/reconnect/ReconnectSender.java
@@ -28,16 +28,18 @@ public class ReconnectSender {
 
     private static final int MESSAGE_COUNT = 10;
 
-    private static String serverHost = "localhost";
-    private static int serverPort = 5672;
-    private static String address = "reconnect-sender-example";
+    public static void main(String[] args) throws Exception {
+        final String serverHost = System.getProperty("HOST", "localhost");
+        final int serverPort = Integer.getInteger("PORT", 5672);
+        final String address = System.getProperty("ADDRESS", 
"reconnect-examples");
+        final String backupServerHost = System.getProperty("BACKUP_HOST");
+        final int backupServerPort = Integer.getInteger("BACKUP_PORT", 5672);
 
-    private static String backupServerHost = 
System.getProperty("backup_server_host");
-    private static int backupServerPort = 
Integer.getInteger("backup_server_port", 5672);
+        final Client client = Client.create();
 
-    public static void main(String[] args) throws Exception {
-        Client client = Client.create();
-        ConnectionOptions connectionOpts = new ConnectionOptions();
+        final ConnectionOptions connectionOpts = new ConnectionOptions();
+        connectionOpts.user(System.getProperty("USER"));
+        connectionOpts.password(System.getProperty("PASSWORD"));
         connectionOpts.reconnectEnabled(true);
 
         if (backupServerHost != null) {

---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to