Add logger messages
diff --git a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/AMQPSession.java b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/AMQPSession.java
index b2f1f10..4ded349 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/AMQPSession.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/AMQPSession.java
@@ -12,6 +12,8 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
+import java.io.IOException;
+import java.net.URISyntaxException;
import java.util.UUID;
public class AMQPSession {
@@ -39,6 +41,7 @@
}
public void connect() {
+ LOGGER.info("Connect to " + properties.getAMQPUri() + "...");
ConnectionFactory factory = new ConnectionFactory();
exchangeName = UUID.randomUUID().toString();
try {
@@ -51,10 +54,15 @@
factory.setPassword(properties.getAMQPPassword());
}
connection = factory.newConnection();
+ LOGGER.info("Connection established.");
}
bind();
+ } catch (URISyntaxException ex) {
+ LOGGER.error("URI syntax error: " + properties.getAMQPUri());
+ } catch (IOException ex) {
+ LOGGER.error("Connection cannot be opened.");
} catch (Exception ex) {
- LOGGER.warn("#connect: " + ex.toString());
+ LOGGER.warn("#connect: " + ex.getClass().getName());
}
}
@@ -63,51 +71,62 @@
try {
Channel ch = connection.createChannel();
if (StringUtils.isNotEmpty(properties.getAMQPQueue())) {
- String exchangeType = EXCHANGE_TYPE_DIRECT;;
+ LOGGER.info("Queue mode");
+ String exchangeType = EXCHANGE_TYPE_DIRECT;
String routingKey = properties.getAMQPRoutingKey();
if (routingKey.isEmpty()) {
exchangeType = EXCHANGE_TYPE_FANOUT;
routingKey = pluginName;
}
+ LOGGER.debug("Exchange type: " + exchangeType);
+ LOGGER.debug("Declare exchange: " + exchangeName);
ch.exchangeDeclare(exchangeName, exchangeType, true);
+ LOGGER.debug("Declare queue: " + properties.getAMQPQueue());
ch.queueDeclare(properties.getAMQPQueue(), true, false, false, null);
+ LOGGER.debug("Bind exchange and queue with key: " + routingKey);
ch.queueBind(properties.getAMQPQueue(), exchangeName, routingKey);
publishChannel = ch;
+ LOGGER.info("Channel for queue \"" + properties.getAMQPQueue() + "\" opened.");
} else {
+ LOGGER.info("Exchange mode");
exchangeName = properties.getAMQPExchange();
if (StringUtils.isNotEmpty(exchangeName)) {
+ LOGGER.debug("Declare exchange: " + exchangeName);
ch.exchangeDeclarePassive(exchangeName);
publishChannel = ch;
+ LOGGER.info("Channel for exchange \"" + exchangeName + "\" opened.");
}
}
} catch (Exception ex) {
- LOGGER.warn("#bind: " + ex.toString());
+ LOGGER.warn("#bind: " + ex.getClass().getName());
disconnect();
}
}
}
public void disconnect() {
+ LOGGER.info("Disconnecting...");
try {
if (connection != null) {
connection.close();
}
} catch (Exception ex) {
- LOGGER.warn("#disconnect: " + ex.toString());
- ex.printStackTrace();
+ LOGGER.warn("#disconnect: " + ex.getClass().getName());
} finally {
connection = null;
publishChannel = null;
}
+ LOGGER.info("Disconnected.");
}
public void sendMessage(String message) {
if (publishChannel != null && publishChannel.isOpen()) {
try {
+ LOGGER.debug("Send message.");
publishChannel.basicPublish(exchangeName, properties.getAMQPRoutingKey(), properties.getBasicProperties(),
message.getBytes(CharEncoding.UTF_8));
} catch (Exception ex) {
- LOGGER.warn("#sendMessage: " + ex.toString());
+ LOGGER.warn("#sendMessage: " + ex.getClass().getName());
}
}
}
diff --git a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/RabbitMQManager.java b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/RabbitMQManager.java
index 8a44d41..e8f335b 100644
--- a/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/RabbitMQManager.java
+++ b/src/main/java/com/googlesource/gerrit/plugins/rabbitmq/RabbitMQManager.java
@@ -34,6 +34,7 @@
@Override
public void run() {
if (!session.isOpen()) {
+ LOGGER.info("#start: try to reconnect");
session.connect();
}
}