RabbitMQ连接异常

时间:2016-11-07 10:25:35

标签: java rabbitmq

我尝试使用rabbitMQ,在创建连接时,我得到了下面给出的输出异常,我不知道出了什么问题。 工厂工作正常,主机名,端口,用户名和密码设置正确,但每次连接失败。

In main 
 parametres setted , now creating the connection
The host name and other params are localhost
The host name and other params are admin
The host name and other params are admin
The host name and other params are 5672
 setted all the params


*Exception in thread "main" java.io.IOException
    at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:106)
    at com.rabbitmq.client.impl.AMQChannel.wrap(AMQChannel.java:102)
    at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:347)
    at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:516)
    at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:533)
    at com.TestSend.main(TestSend.java:39)
Caused by: com.rabbitmq.client.ShutdownSignalException: connection error; reason: java.lang.NoClassDefFoundError: org/apache/commons/io/input/ProxyInputStream
    at com.rabbitmq.utility.ValueOrException.getValue(ValueOrException.java:67)
    at com.rabbitmq.utility.BlockingValueOrException.uninterruptibleGetValue(BlockingValueOrException.java:33)
    at com.rabbitmq.client.impl.AMQChannel$BlockingRpcContinuation.getReply(AMQChannel.java:343)
    at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:300)
    ... 3 more
Caused by: java.lang.NoClassDefFoundError: org/apache/commons/io/input/ProxyInputStream
    at java.lang.ClassLoader.defineClass1(Native Method)
    at java.lang.ClassLoader.defineClass(ClassLoader.java:760)
    at java.security.SecureClassLoader.defineClass(SecureClassLoader.java:142)
    at java.net.URLClassLoader.defineClass(URLClassLoader.java:467)
    at java.net.URLClassLoader.access$100(URLClassLoader.java:73)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:368)
    at java.net.URLClassLoader$1.run(URLClassLoader.java:362)
    at java.security.AccessController.doPrivileged(Native Method)
    at java.net.URLClassLoader.findClass(URLClassLoader.java:361)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    at com.rabbitmq.client.impl.AMQImpl.readMethodFrom(AMQImpl.java:3205)
    at com.rabbitmq.client.impl.CommandAssembler.consumeMethodFrame(CommandAssembler.java:93)
    at com.rabbitmq.client.impl.CommandAssembler.handleFrame(CommandAssembler.java:158)
    at com.rabbitmq.client.impl.AMQCommand.handleFrame(AMQCommand.java:87)
    at com.rabbitmq.client.impl.AMQChannel.handleFrame(AMQChannel.java:89)
    at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:500)
Caused by: java.lang.ClassNotFoundException: org.apache.commons.io.input.ProxyInputStream
    at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
    at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
    at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
    ... 18 more*

我写的代码是

 package com;

    import com.rabbitmq.client.Channel;
    import com.rabbitmq.client.Connection;
    import java.io.IOException;
    import java.util.HashMap;
    import java.util.Map;
    import com.rabbitmq.client.ConnectionFactory;

    public class TestSend {

        public static void main(String[] args) throws IOException {

            System.out.println("In main ");

            // Setting up connection
            ConnectionFactory factory;
            factory = new ConnectionFactory();
            String host = "localhost";
            String password = "admin";
            String user = "admin";
            String port = "5672";

            System.out.println(" parametres setted , now creating the connection");

            factory.setHost(host);
            factory.setPassword(password);
            factory.setUsername(user);
            factory.setPort(Integer.parseInt(port));
            factory.setRequestedHeartbeat(30);

            System.out.println("The host name and other params are " + factory.getHost());

            System.out.println("The host name and other params are " + factory.getUsername());
            System.out.println("The host name and other params are " + factory.getPassword());
            System.out.println("The host name and other params are " + factory.getPort());
            System.out.println("Setted all the params");
            Connection connection;


            connection = factory.newConnection();

            System.out.println("Establishing the connection " + host);





            String s = "Hello";

            Channel channel; // This channel sends the file
            channel = connection.createChannel();
            System.out.println("declaring Queue now");
            channel.queueDeclare("nav", true, false, false, null);
            channel.basicPublish("", "nav", null, s.getBytes());

            System.out.println(" seems like everything has been sent to the queue ");
            System.out.println("Closing the connection");
            channel.close();
            connection.close();

        }
    }

1 个答案:

答案 0 :(得分:1)

我刚刚找到了解决方法。 我在项目中添加了common-io-2.5.jar文件,在重新构建之后,它运行了。

罐子来自链接:http://commons.apache.org/proper/commons-io/download_io.cgi