I'm trying to connect to RabbitMQ in Java with InteliJ IDEA (Maven 3.3.9), but an error occurs when doing the required step (creating ConnectionFactory
object before connecting to RabbitMQ).
For detailed information: Maven itself installs amqp-client:5.7.2
and org.slf4j-api:1.7.26
.
What am I missing here? I tried to import org.slf4j.impl.StaticLoggerBinder
, but Java itself doesn't know this one.
package TestPackage;
import Configuration.RabbitMQConf;
import com.rabbitmq.client.Connection;
import com.rabbitmq.client.Channel;
import com.rabbitmq.client.ConnectionFactory;
import org.slf4j.LoggerFactory;
import java.io.IOException;
import java.util.concurrent.TimeoutException;
public class TestingClass {
static ConnectionFactory rbmqFactory;
static Connection rbmqConn;
static Channel rbmqChannel;
public static void main(String[] args){
RabbitMQConf rbmqConf = new RabbitMQConf();
rbmqFactory = new ConnectionFactory();
rbmqFactory.setUsername(rbmqConf.username);
rbmqFactory.setPassword(rbmqConf.password);
rbmqFactory.setVirtualHost(rbmqConf.virtualHost);
rbmqFactory.setHost(rbmqConf.host);
rbmqFactory.setPort(rbmqConf.port);
}
}
I tried to run this and got this error:
SLF4J: Failed to load class "org.slf4j.impl.StaticLoggerBinder".
SLF4J: Defaulting to no-operation (NOP) logger implementation
SLF4J: See http://www.slf4j.org/codes.html#StaticLoggerBinder for further details.
here's my pom.xml file :
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>XXXX</groupId>
<artifactId>XXXX</artifactId>
<version>1.0-XXXX</version>
<properties>
<maven.compiler.source>1.7</maven.compiler.source>
<maven.compiler.target>1.7</maven.compiler.target>
</properties>
<dependencies>
<dependency>
<groupId>com.rabbitmq</groupId>
<artifactId>amqp-client</artifactId>
<version>5.7.2</version>
</dependency>
</dependencies>
</project>
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…