read me terminé
This commit is contained in:
@@ -1,36 +0,0 @@
|
||||
package fr.istic.chat;
|
||||
|
||||
import com.rabbitmq.client.Channel;
|
||||
import com.rabbitmq.client.Connection;
|
||||
import com.rabbitmq.client.ConnectionFactory;
|
||||
import com.rabbitmq.client.DeliverCallback;
|
||||
|
||||
public class chat {
|
||||
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();
|
||||
|
||||
|
||||
String message = "";
|
||||
|
||||
if(false){
|
||||
channel.basicPublish(EXCHANGE_NAME, argv[0], null, message.getBytes("UTF-8"));
|
||||
}
|
||||
|
||||
String queueName = channel.queueDeclare().getQueue();
|
||||
|
||||
DeliverCallback deliverCallback = (consumerTag, delivery) -> {
|
||||
String message2 = new String(delivery.getBody(), "UTF-8");
|
||||
System.out.println(" [x] Received '" + message2 + "'");
|
||||
};
|
||||
channel.basicConsume(queueName, true, deliverCallback, consumerTag -> {
|
||||
});
|
||||
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package fr.istic.chat;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Random;
|
||||
import java.util.Scanner;
|
||||
|
||||
import com.rabbitmq.client.AMQP;
|
||||
@@ -13,13 +14,26 @@ import com.rabbitmq.client.DeliverCallback;
|
||||
/*
|
||||
* & 'C:\Program Files\Java\jre1.8.0_431\bin\java.exe' '-cp' 'C:\Users\Thibaut\AppData\Local\Temp\cp_223j5v7zmzailham0c6y3u9rd.jar' 'fr.istic.chat.clientChat' sujet.test A
|
||||
*/
|
||||
public class clientChat {
|
||||
public class ClientChat {
|
||||
private static final String EXCHANGE_NAME = "chat";
|
||||
|
||||
public static void main(String[] argv) throws Exception {
|
||||
|
||||
String canal = argv[0];
|
||||
String name = argv[1];
|
||||
public static void main(String[] argv) throws Exception {
|
||||
String canal ="";
|
||||
String name = "";
|
||||
switch(argv.length){
|
||||
case 0 :
|
||||
canal = "#";
|
||||
name = getRandomID(6);
|
||||
break;
|
||||
case 1 :
|
||||
canal = argv[0];
|
||||
name = getRandomID(6);
|
||||
break;
|
||||
default:
|
||||
canal = argv[0];
|
||||
name = argv[1];
|
||||
}
|
||||
|
||||
System.out.println("canal : " + canal);
|
||||
System.out.println("name : " + name);
|
||||
|
||||
@@ -65,7 +79,6 @@ public class clientChat {
|
||||
test = message.compareTo("\\exit")!=0;
|
||||
if(test){
|
||||
channel.basicPublish(EXCHANGE_NAME, canal, props, message.getBytes("UTF-8"));
|
||||
//System.out.println("<- ["+name+"](vous) : "+"'" + message + "'");
|
||||
}
|
||||
}
|
||||
channel.close();
|
||||
@@ -73,4 +86,17 @@ public class clientChat {
|
||||
scanner.close();
|
||||
System.out.println("exit");
|
||||
}
|
||||
|
||||
private static String getRandomID(int length){
|
||||
String characters = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
|
||||
Random random = new Random();
|
||||
String str = "";
|
||||
|
||||
for (int i = 0; i < length; i++) {
|
||||
int index = random.nextInt(characters.length());
|
||||
str += characters.charAt(index);
|
||||
}
|
||||
|
||||
return str;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -5,7 +5,7 @@ import com.rabbitmq.client.Connection;
|
||||
import com.rabbitmq.client.ConnectionFactory;
|
||||
import com.rabbitmq.client.DeliverCallback;
|
||||
|
||||
public class espion {
|
||||
public class Espion {
|
||||
private static final String EXCHANGE_NAME = "chat";
|
||||
|
||||
public static void main(String[] argv) throws Exception {
|
||||
|
||||
Reference in New Issue
Block a user