receive load balancing
This commit is contained in:
@@ -5,10 +5,8 @@ import com.rabbitmq.client.Connection;
|
|||||||
import com.rabbitmq.client.ConnectionFactory;
|
import com.rabbitmq.client.ConnectionFactory;
|
||||||
import com.rabbitmq.client.DeliverCallback;
|
import com.rabbitmq.client.DeliverCallback;
|
||||||
|
|
||||||
import java.util.Date;
|
|
||||||
|
|
||||||
public class RecevoirDate {
|
public class RecevoirDate {
|
||||||
private static final Date date = null;
|
private static final String EXCHANGE_NAME = "logs";
|
||||||
|
|
||||||
public static void main(String[] argv) throws Exception {
|
public static void main(String[] argv) throws Exception {
|
||||||
ConnectionFactory factory = new ConnectionFactory();
|
ConnectionFactory factory = new ConnectionFactory();
|
||||||
@@ -16,9 +14,9 @@ public class RecevoirDate {
|
|||||||
Connection connection = factory.newConnection();
|
Connection connection = factory.newConnection();
|
||||||
Channel channel = connection.createChannel();
|
Channel channel = connection.createChannel();
|
||||||
|
|
||||||
channel.exchangeDeclare(date.toString(), "fanout");
|
channel.exchangeDeclare(EXCHANGE_NAME, "fanout");
|
||||||
String queueName = channel.queueDeclare().getQueue();
|
String queueName = channel.queueDeclare().getQueue();
|
||||||
channel.queueBind(queueName, date.toString(), "");
|
channel.queueBind(queueName, EXCHANGE_NAME, "");
|
||||||
|
|
||||||
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
|
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
|
||||||
|
|
||||||
|
|||||||
35
src/main/java/fr/istic/date/lb/RecevoirDate.java
Normal file
35
src/main/java/fr/istic/date/lb/RecevoirDate.java
Normal file
@@ -0,0 +1,35 @@
|
|||||||
|
package fr.istic.date.lb;
|
||||||
|
|
||||||
|
import com.rabbitmq.client.Channel;
|
||||||
|
import com.rabbitmq.client.Connection;
|
||||||
|
import com.rabbitmq.client.ConnectionFactory;
|
||||||
|
import com.rabbitmq.client.DeliverCallback;
|
||||||
|
|
||||||
|
public class RecevoirDate {
|
||||||
|
private static final String EXCHANGE_NAME = "logs";
|
||||||
|
private static String queueName = "file_date";
|
||||||
|
|
||||||
|
public static void main(String[] argv) throws Exception {
|
||||||
|
ConnectionFactory factory = new ConnectionFactory();
|
||||||
|
factory.setUri("amqps://cyvthtfj:O8LmaXkX5mVB0oFZN9TobaK8rX9wEhol@whale.rmq.cloudamqp.com/cyvthtfj");
|
||||||
|
Connection connection = factory.newConnection();
|
||||||
|
Channel channel = connection.createChannel();
|
||||||
|
|
||||||
|
/*
|
||||||
|
channel.exchangeDeclare(EXCHANGE_NAME, "fanout");
|
||||||
|
String queueName = channel.queueDeclare().getQueue();
|
||||||
|
channel.queueBind(queueName, EXCHANGE_NAME, "");
|
||||||
|
*/
|
||||||
|
channel.queueDeclare(queueName, false, false, false, null);
|
||||||
|
|
||||||
|
System.out.println(" [*] Waiting for messages. To exit press CTRL+C");
|
||||||
|
|
||||||
|
DeliverCallback deliverCallback = (consumerTag, delivery) -> {
|
||||||
|
String message = new String(delivery.getBody(), "UTF-8");
|
||||||
|
System.out.println(" [x] Received '" + message + "'");
|
||||||
|
};
|
||||||
|
channel.basicConsume(queueName, true, deliverCallback, consumerTag -> {
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user