Qpid连接被拒绝了

时间:2016-02-25 01:21:10

标签: java spring spring-boot amqp qpid

我在Spring启动应用程序中使用0.32 Qpid JMS客户端。以下是配置和属性文件:

JmsConfiguration.java

@Configuration
public class JmsConfiguration
{
    @Primary
    @Bean
    public Context createContext()
    {
        Properties properties=new Properties();
        System.setProperty("IMMEDIATE_PREFETCH", "true");

        Context context=null;
        try {
            properties.load(this.getClass().getResourceAsStream("jndi.properties"));
            context = new InitialContext(properties);
        } catch (IOException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } catch (NamingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        return context;
    }

    @Primary
    @Bean
    public ConnectionFactory createConnectionFactory(Context context)
    {
        ConnectionFactory connectionFactory=null;
        try {
            connectionFactory = (ConnectionFactory) context.lookup("qpidConnectionFactory");
        } catch (NamingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        } 
        return connectionFactory;
    }

    @Primary
    @Bean
    public Connection jmsConnection(ConnectionFactory connectionFactory) throws Exception
    {           
        Connection connection = connectionFactory.createConnection();
        connection.start();
        return connection;
    }

    @Primary
    @Bean
    public Queue jmsQueue(Context context) throws Exception
    {
        Queue queue = (Queue) context.lookup("myqueue");
        return queue;
    }
}

jndi.properties

java.naming.factory.initial = org.apache.qpid.jndi.PropertiesFileInitialContextFactory
connectionfactory.qpidConnectionFactory = amqp://guest:guest@clientid/?brokerlist='tcp://localhost:5672'
queue.myqueue = queue

现在,当我尝试运行我的应用程序时,它会发出以下错误:

Caused by: org.springframework.beans.factory.BeanCreationException: Could not autowire field: private javax.jms.Connection apigeeAlps.CustomBatchJobs.CustomItemReader.connection; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jmsConnection' defined in class path resource [apigeeAlps/Configuration/JmsConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.jms.Connection]: Factory method 'jmsConnection' threw exception; nested exception is javax.jms.JMSException: Error creating connection: Connection refused
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:573) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.beans.factory.annotation.InjectionMetadata.inject(InjectionMetadata.java:88) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor.postProcessPropertyValues(AutowiredAnnotationBeanPostProcessor.java:331) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    ... 74 common frames omitted
Caused by: org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'jmsConnection' defined in class path resource [apigeeAlps/Configuration/JmsConfiguration.class]: Bean instantiation via factory method failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.jms.Connection]: Factory method 'jmsConnection' threw exception; nested exception is javax.jms.JMSException: Error creating connection: Connection refused
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:599) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1123) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1018) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:510) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:482) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory$1.getObject(AbstractBeanFactory.java:306) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:230) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.findAutowireCandidates(DefaultListableBeanFactory.java:1192) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:1116) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:1014) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:545) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    ... 76 common frames omitted
Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [javax.jms.Connection]: Factory method 'jmsConnection' threw exception; nested exception is javax.jms.JMSException: Error creating connection: Connection refused
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:189) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:588) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    ... 88 common frames omitted
Caused by: javax.jms.JMSException: Error creating connection: Connection refused
    at org.apache.qpid.client.AMQConnectionFactory.createConnection(AMQConnectionFactory.java:128) ~[qpid-client-0.32.jar:0.32]
    at apigeeAlps.Configuration.JmsConfiguration.jmsConnection(JmsConfiguration.java:59) ~[classes/:na]
    at apigeeAlps.Configuration.JmsConfiguration$$EnhancerBySpringCGLIB$$4acb09f.CGLIB$jmsConnection$2(<generated>) ~[classes/:na]
    at apigeeAlps.Configuration.JmsConfiguration$$EnhancerBySpringCGLIB$$4acb09f$$FastClassBySpringCGLIB$$92347ea9.invoke(<generated>) ~[classes/:na]
    at org.springframework.cglib.proxy.MethodProxy.invokeSuper(MethodProxy.java:228) ~[spring-core-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at org.springframework.context.annotation.ConfigurationClassEnhancer$BeanMethodInterceptor.intercept(ConfigurationClassEnhancer.java:355) ~[spring-context-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    at apigeeAlps.Configuration.JmsConfiguration$$EnhancerBySpringCGLIB$$4acb09f.jmsConnection(<generated>) ~[classes/:na]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_65]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_65]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_65]
    at java.lang.reflect.Method.invoke(Method.java:497) ~[na:1.8.0_65]
    at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:162) ~[spring-beans-4.2.4.RELEASE.jar:4.2.4.RELEASE]
    ... 89 common frames omitted
Caused by: org.apache.qpid.AMQConnectionFailureException: Connection refused
    at org.apache.qpid.client.AMQConnection.<init>(AMQConnection.java:520) ~[qpid-client-0.32.jar:0.32]
    at org.apache.qpid.client.AMQConnectionFactory.createConnection(AMQConnectionFactory.java:124) ~[qpid-client-0.32.jar:0.32]
    ... 100 common frames omitted
Caused by: org.apache.qpid.transport.TransportException: Error connecting to broker
    at org.apache.qpid.transport.network.io.IoNetworkTransport.connect(IoNetworkTransport.java:91) ~[qpid-common-0.32.jar:0.32]
    at org.apache.qpid.transport.Connection.connect(Connection.java:244) ~[qpid-common-0.32.jar:0.32]
    at org.apache.qpid.client.AMQConnectionDelegate_0_10.makeBrokerConnection(AMQConnectionDelegate_0_10.java:222) ~[qpid-client-0.32.jar:0.32]
    at org.apache.qpid.client.AMQConnection.makeBrokerConnection(AMQConnection.java:664) ~[qpid-client-0.32.jar:0.32]
    at org.apache.qpid.client.AMQConnection.<init>(AMQConnection.java:444) ~[qpid-client-0.32.jar:0.32]
    ... 101 common frames omitted
Caused by: java.net.ConnectException: Connection refused
    at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_65]
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_65]
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_65]
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_65]
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_65]
    at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_65]
    at org.apache.qpid.transport.network.io.IoNetworkTransport.connect(IoNetworkTransport.java:87) ~[qpid-common-0.32.jar:0.32]
    ... 105 common frames omitted

奇怪的是我两个星期后开发了这个应用程序并且它运行顺利,今天经过这么多个星期我关闭我的mac通常我把它放在睡眠状态,现在当我试图运行这个应用程序它显示这个错误。我真的不知道这是原因还是什么,但我之前从未遇到任何此类错误。

0 个答案:

没有答案