Skip to content

Commit

Permalink
Servername comeback et fix pour avoir la ha sur la queue rabbit
Browse files Browse the repository at this point in the history
  • Loading branch information
Yann151924 committed Aug 5, 2019
1 parent efedbc1 commit 699a42b
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ public void onEnable(){
sendConsoleMessage("&8[&eAurionChat&8]&e - Connecting to RabbitMQ");
chatService = new ChatService(config.getUri(), this);
try{
chatService.join();
chatService.join(config.getServername());
}
catch (IOException e){
getLogger().warning(e.getMessage());
Expand Down Expand Up @@ -99,6 +99,7 @@ private void setupListener(AurionChat plugin){
@Override
public void onDisable() {
try{
this.chatService.leave(config.getServername());
this.chatService.close();
}
catch(Exception e){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ public String getUri(){
return config.getString("rabbitmq.uri");
}

public String getServername(){
return config.getString("rabbitmq.servername");
}

public String getFormatChannel(String channelName){
return config.getString("channels."+ channelName + ".format");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,12 @@ public ChatServiceCommun(String uri){
}
}

public void join() throws IOException{
public void join(String queueName) throws IOException{
if(this.consumerTag != null){
channel.basicCancel(consumerTag);
}
channel.exchangeDeclare(EXCHANGE_NAME, "topic");
String queueName = channel.queueDeclare().getQueue();
channel.queueDeclare(queueName, false, false, false, null);
channel.queueBind(queueName, EXCHANGE_NAME, "aurion.chat.*");

DeliverCallback deliverCallback = (consumerTag, delivery) -> {
Expand All @@ -56,8 +56,8 @@ public void join() throws IOException{
channel.basicConsume(queueName, true, deliverCallback, consumerTag -> {});
}

public void leave() throws IOException {
channel.queueUnbind(channel.queueDeclare().getQueue(), EXCHANGE_NAME,"aurion.chat.*");
public void leave(String queueName) throws IOException {
channel.queueDelete(queueName);
}

public void send(String channelName,String message) throws IOException {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
import java.nio.file.Paths;
import java.util.Optional;
import java.util.Properties;
import java.util.concurrent.TimeoutException;

@Plugin(
id = "aurionchat",
Expand Down Expand Up @@ -80,7 +81,7 @@ public void Init(GamePreInitializationEvent event) throws IOException, ObjectMap
sendConsoleMessage("&8[&eAurionChat&8]&e - Listener Loaded.");
chatService = new ChatService(config.rabbitmq.uri, this);
try{
chatService.join();
chatService.join(config.rabbitmq.servername);
}
catch (IOException e){
getLogger().error(e.getMessage());
Expand All @@ -97,8 +98,9 @@ public void onServerStart(GameStartedServerEvent event){
}

@Listener
public void onServerStop(GameStoppingEvent event) throws IOException{
chatService.leave();
public void onServerStop(GameStoppingEvent event) throws IOException, TimeoutException {
chatService.leave(config.rabbitmq.servername);
chatService.close();
}


Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,8 @@ public class Config {
public static class Rabbitmq{
@Setting
public String uri = "amqp://guest:guest@localhost:5672/";
@Setting(comment = "Must Be unique beetwen all of your servers")
public String servername = "ServerName";
}

@Setting public Options options = new Options();
Expand Down

0 comments on commit 699a42b

Please sign in to comment.