46 lines
1.4 KiB
Java
46 lines
1.4 KiB
Java
/*
|
|
* Copyright (c) 2017 univento.eu - All rights reserved
|
|
* You are not allowed to use, distribute or modify this code
|
|
*/
|
|
|
|
package eu.univento.commons.messaging;
|
|
|
|
import eu.univento.commons.Commons;
|
|
import eu.univento.commons.configuration.ConfigurationHandler;
|
|
|
|
import java.util.concurrent.CompletableFuture;
|
|
|
|
/**
|
|
* @author joethei
|
|
* @version 1.0
|
|
*/
|
|
public class MessagingManager {
|
|
|
|
private RabbitMQ rabbitMQ;
|
|
|
|
public MessagingManager() {
|
|
ConfigurationHandler config = Commons.getCommons().getConfigurationHandler();
|
|
rabbitMQ = new RabbitMQ(config.getString("RabbitMQ.Host"), config.getInteger("RabbitMQ.Port"),
|
|
config.getString("RabbitMQ.Username"), config.getString("RabbitMQ.Password"), config.getString("RabbitMQ.VirtualHost"));
|
|
}
|
|
|
|
public CompletableFuture<RabbitMQ> start() {
|
|
CompletableFuture<RabbitMQ> future = new CompletableFuture<>();
|
|
if(rabbitMQ.getClient().isConnected()) future.complete(rabbitMQ);
|
|
|
|
rabbitMQ.getClient().start(res -> {
|
|
if(res.failed()) res.cause().printStackTrace();
|
|
else future.complete(rabbitMQ);
|
|
});
|
|
|
|
return future;
|
|
}
|
|
|
|
public void close() {
|
|
if(rabbitMQ.getClient().isConnected()) {
|
|
rabbitMQ.getClient().stop(voidAsyncResult -> {
|
|
if(voidAsyncResult.failed()) voidAsyncResult.cause().printStackTrace();
|
|
});
|
|
}
|
|
}
|
|
} |