diff --git a/java-mvn/README.md b/java-mvn/README.md new file mode 100644 index 00000000..ff628e56 --- /dev/null +++ b/java-mvn/README.md @@ -0,0 +1,5 @@ +Running an example using `mvn` and enabling debug logging: + +``` +mvn -e exec:java -Dorg.slf4j.simpleLogger.defaultLogLevel=debug -Dexec.mainClass=RecvWithConnectionRecovery +``` diff --git a/java-mvn/pom.xml b/java-mvn/pom.xml index 6cbdcd97..b91f9500 100644 --- a/java-mvn/pom.xml +++ b/java-mvn/pom.xml @@ -20,7 +20,17 @@ com.rabbitmq amqp-client - LATEST + 5.1.2 + + + org.slf4j + slf4j-api + 1.7.25 + + + org.slf4j + slf4j-simple + 1.7.25 diff --git a/java-mvn/src/main/java/RecvWithConnectionRecovery.java b/java-mvn/src/main/java/RecvWithConnectionRecovery.java new file mode 120000 index 00000000..cfbef9b3 --- /dev/null +++ b/java-mvn/src/main/java/RecvWithConnectionRecovery.java @@ -0,0 +1 @@ +../../../../java/RecvWithConnectionRecovery.java \ No newline at end of file diff --git a/java-mvn/src/main/java/SendWithConnectionRecovery.java b/java-mvn/src/main/java/SendWithConnectionRecovery.java new file mode 120000 index 00000000..93ad6e98 --- /dev/null +++ b/java-mvn/src/main/java/SendWithConnectionRecovery.java @@ -0,0 +1 @@ +../../../../java/SendWithConnectionRecovery.java \ No newline at end of file diff --git a/java/RecvWithConnectionRecovery.java b/java/RecvWithConnectionRecovery.java new file mode 100644 index 00000000..fa884bcd --- /dev/null +++ b/java/RecvWithConnectionRecovery.java @@ -0,0 +1,50 @@ +import com.rabbitmq.client.Address; +import com.rabbitmq.client.Channel; +import com.rabbitmq.client.Connection; +import com.rabbitmq.client.ConnectionFactory; +import com.rabbitmq.client.Consumer; +import com.rabbitmq.client.DefaultConsumer; +import com.rabbitmq.client.Envelope; +import com.rabbitmq.client.AMQP.BasicProperties; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.io.IOException; + +public class RecvWithConnectionRecovery { + + private static final Logger log = LoggerFactory.getLogger(RecvWithConnectionRecovery.class); + private static final String QUEUE_NAME = "hello"; + + public static void main(String[] argv) throws Exception { + final Address[] addresses = new Address[]{ + new Address("localhost", 5672), + new Address("localhost", 5673) + }; + + log.debug("Initializing ConnectionFactory"); + final ConnectionFactory factory = new ConnectionFactory(); + factory.setAutomaticRecoveryEnabled(true); + factory.setTopologyRecoveryEnabled(true); + + log.debug("Creating Connection"); + final Connection connection = factory.newConnection(addresses); + + log.debug("Creating Channel"); + final Channel channel = connection.createChannel(); + + channel.queueDeclare(QUEUE_NAME, false, false, false, null); + log.info(" [*] Waiting for messages. To exit press CTRL+C"); + + Consumer consumer = new DefaultConsumer(channel) { + @Override + public void handleDelivery(String consumerTag, Envelope envelope, BasicProperties properties, byte[] body) + throws IOException { + String message = new String(body, "UTF-8"); + System.out.println(" [x] Received '" + message + "'"); + } + }; + channel.basicConsume(QUEUE_NAME, true, consumer); + } +} diff --git a/java/SendWithConnectionRecovery.java b/java/SendWithConnectionRecovery.java new file mode 100644 index 00000000..cb4e59d4 --- /dev/null +++ b/java/SendWithConnectionRecovery.java @@ -0,0 +1,28 @@ +import com.rabbitmq.client.Address; +import com.rabbitmq.client.Channel; +import com.rabbitmq.client.Connection; +import com.rabbitmq.client.ConnectionFactory; + +public class SendWithConnectionRecovery { + + private final static String QUEUE_NAME = "hello"; + + public static void main(String[] argv) throws Exception { + Address[] addresses = new Address[]{ + new Address("localhost", 5672), + new Address("localhost", 5673) + }; + ConnectionFactory factory = new ConnectionFactory(); + factory.setAutomaticRecoveryEnabled(true); + Connection connection = factory.newConnection(addresses); + Channel channel = connection.createChannel(); + + channel.queueDeclare(QUEUE_NAME, false, false, false, null); + String message = "Hello World!"; + channel.basicPublish("", QUEUE_NAME, null, message.getBytes("UTF-8")); + System.out.println(" [x] Sent '" + message + "'"); + + channel.close(); + connection.close(); + } +} diff --git a/python/.gitignore b/python/.gitignore new file mode 100644 index 00000000..cdb93cd5 --- /dev/null +++ b/python/.gitignore @@ -0,0 +1 @@ +.python-version pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy