This commit is contained in:
Vu Tuan Minh
2025-03-25 14:23:56 +01:00
parent 30ca0bfd5d
commit 3dc15ce86f
2 changed files with 64 additions and 0 deletions

View File

@@ -0,0 +1,32 @@
package fr.istic.date.topic;
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 = "topic_log";
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, "topic");
String queueName = channel.queueDeclare().getQueue();
//la clé: locale
channel.queueBind(queueName, EXCHANGE_NAME, "date.locale");
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 -> {
});
}
}

View File

@@ -0,0 +1,32 @@
package fr.istic.date.topic;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.ConnectionFactory;
import com.rabbitmq.client.DeliverCallback;
public class RecevoirDateGMT {
private static final String EXCHANGE_NAME = "topic_log";
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, "topic");
String queueName = channel.queueDeclare().getQueue();
//la clé: GMT
channel.queueBind(queueName, EXCHANGE_NAME, "date.gmt");
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 -> {
});
}
}