topic
This commit is contained in:
52
src/main/java/fr/istic/date/topic/EnvoyerDate.java
Normal file
52
src/main/java/fr/istic/date/topic/EnvoyerDate.java
Normal file
@@ -0,0 +1,52 @@
|
||||
package fr.istic.date.topic;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import com.rabbitmq.client.Channel;
|
||||
import com.rabbitmq.client.Connection;
|
||||
import com.rabbitmq.client.ConnectionFactory;
|
||||
|
||||
|
||||
public class EnvoyerDate {
|
||||
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");
|
||||
try (Connection connection = factory.newConnection();
|
||||
Channel channel = connection.createChannel()) {
|
||||
while(true){
|
||||
|
||||
channel.exchangeDeclare(EXCHANGE_NAME, "topic");
|
||||
|
||||
String message = argv.length < 1 ? getDate()
|
||||
: String.join(" ", argv);
|
||||
|
||||
channel.basicPublish(EXCHANGE_NAME, "date.locale", null, message.getBytes("UTF-8"));
|
||||
System.out.println(" [x] Sent '" + message + "'");
|
||||
|
||||
String messageGMT = argv.length < 1 ? getDateGMT()
|
||||
: String.join(" ", argv);
|
||||
|
||||
channel.basicPublish(EXCHANGE_NAME, "date.gmt", null, messageGMT.getBytes("UTF-8"));
|
||||
System.out.println(" [x] Sent '" + messageGMT + "'");
|
||||
|
||||
try {
|
||||
Thread.sleep(1000); // Attend 1 seconde (1000 millisecondes)
|
||||
} catch (InterruptedException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static String getDate(){
|
||||
return (new Date()).toString();
|
||||
}
|
||||
|
||||
public static String getDateGMT(){
|
||||
return (new Date()).toGMTString();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user