Я получил org.springframework.amqp.AmqpConnectException, когда я пытаюсь провести интеграционный тест с брокером qpid - PullRequest
0 голосов
/ 06 июня 2019

Я пытаюсь настроить свой тестовый класс с помощью @TestConfiguration, и когда я объявляю DirectMessageListenerContainer со значением свойства consumerPerQueue больше 1. Я получил исключение при запуске теста.

Я использую весеннюю загрузку 2.1.5.RELEASE, spring-amqp 2.1.6.RELEASE и qpid 7.1.0

Вот моя конфигурация

@Configuration
public class MyConfiguration  {

    public static final String EXCHANGE_NAME = "x.sample.first";
    public static final String Q_NAME = "q.sample.first";

    @Bean(name = "firstQueue")
    Queue queue() {
        final boolean durable = true;
        final boolean exclusive = false;
        final boolean autoDelete = false;
        return new Queue(Q_NAME, durable, exclusive, autoDelete);
    }

    @Bean("firstExchange")
    DirectExchange exchange() {
        final boolean durable = true;
        final boolean autoDelete = false;
        return new DirectExchange(EXCHANGE_NAME, durable, autoDelete);
    }

    @Bean(name = "firstQueueBinding")
    Binding binding(@Qualifier("firstQueue") Queue queue, @Qualifier("firstExchange") DirectExchange exchange) {
        return BindingBuilder.bind(queue).to(exchange).withQueueName();
    }

    @Bean("firstQueueMessageContainer")
    public DirectMessageListenerContainer messageContainer(ConnectionFactory connectionFactory, MyMessageListener consumer) {

        DirectMessageListenerContainer container = new DirectMessageListenerContainer(connectionFactory);
        container.setConsumersPerQueue(2);
        container.setMessageListener(consumer);
        container.setQueueNames(Q_NAME);
        return container;
    }
}

Мой тест выглядит следующим образом.

@ActiveProfiles("test")
@SpringBootTest
@ExtendWith(SpringExtension.class)
public class MyMessageListenerTest {

    @Test
    public void test() {
        //some test here...
    }

    @TestConfiguration
    static class TestConfig {

        @Bean(name = "qpidBroker", initMethod = "start", destroyMethod = "shutdown")
        public EmbeddedInMemoryQpidBroker broker() {
            return new EmbeddedInMemoryQpidBroker(); //this my wrapper class to provide in memory qpid broker
        }

        @Bean
        @DependsOn("qpidBroker")
        public ConnectionFactory connectionFactory() {

            CachingConnectionFactory connectionFactory = new CachingConnectionFactory();
            connectionFactory.setHost("localhost");
            connectionFactory.setPort(5672);
            connectionFactory.setUsername("guest");
            connectionFactory.setPassword("guest");
            return connectionFactory;
        }

        @Bean("firstQueueMessageContainer")
        public DirectMessageListenerContainer messageContainer(ConnectionFactory connectionFactory, MyMessageListener consumer) {

            DirectMessageListenerContainer container = new DirectMessageListenerContainer(connectionFactory);
            container.setConsumersPerQueue(2); // if I remove this line everything working correctly.
            container.setMessageListener(consumer);
            container.setQueueNames(Q_NAME);
            return container;
        }
    }
}

И я получил ниже исключения.

2019-06-06 15:18:37.108  INFO 8576 --- [           main] com.example.MyMessageListenerTest        : Starting MyMessageListenerTest on AliveX with PID 8576 (started by development in C:\seamless\workspace-spring\spring-rabbit-sample)
2019-06-06 15:18:37.109  INFO 8576 --- [           main] com.example.MyMessageListenerTest        : The following profiles are active: test
2019-06-06 15:18:38.782  INFO 8576 --- [  Broker-Config] o.a.q.server.store.GenericStoreUpgrader  : Broker store has model version 7.0. Number of record(s) 6
2019-06-06 15:18:38.798  INFO 8576 --- [  Broker-Config] q.message.authenticationprovider.create  : [Broker] ATH-1001 : Create "hardcoded"
2019-06-06 15:18:38.806  INFO 8576 --- [  Broker-Config] qpid.message.port.create                 : [Broker] PRT-1001 : Create "AMQP"
[Broker] BRK-1006 : Using configuration : N/A
2019-06-06 15:18:38.818  INFO 8576 --- [  Broker-Config] qpid.message.broker.config               : [Broker] BRK-1006 : Using configuration : N/A
[Broker] BRK-1001 : Startup : Version: 7.1.0 Build: 5cb4ba20207da1390c79ef8b654a395e58dad5a0
2019-06-06 15:18:39.119  INFO 8576 --- [  Broker-Config] qpid.message.broker.startup              : [Broker] BRK-1001 : Startup : Version: 7.1.0 Build: 5cb4ba20207da1390c79ef8b654a395e58dad5a0
[Broker] BRK-1010 : Platform : JVM : Oracle Corporation version: 1.8.0_112-b15 OS : Windows 10 version: 10.0 arch: amd64 cores: 8
2019-06-06 15:18:39.120  INFO 8576 --- [  Broker-Config] qpid.message.broker.platform             : [Broker] BRK-1010 : Platform : JVM : Oracle Corporation version: 1.8.0_112-b15 OS : Windows 10 version: 10.0 arch: amd64 cores: 8
[Broker] BRK-1011 : Maximum Memory : Heap : 3,791,650,816 bytes Direct : 3,791,650,816 bytes
2019-06-06 15:18:39.121  INFO 8576 --- [  Broker-Config] qpid.message.broker.max_memory           : [Broker] BRK-1011 : Maximum Memory : Heap : 3,791,650,816 bytes Direct : 3,791,650,816 bytes
[Broker] BRK-1017 : Process : PID : 8576
2019-06-06 15:18:39.122  INFO 8576 --- [  Broker-Config] qpid.message.broker.process              : [Broker] BRK-1017 : Process : PID : 8576
2019-06-06 15:18:39.129  INFO 8576 --- [  Broker-Config] qpid.message.configstore.created         : [Broker] [vh(/default)/ms(MemoryConfigurationStore)] CFG-1001 : Created
2019-06-06 15:18:39.130  INFO 8576 --- [  Broker-Config] qpid.message.configstore.recovery_start  : [Broker] [vh(/default)/ms(MemoryConfigurationStore)] CFG-1004 : Recovery Start
2019-06-06 15:18:39.137  INFO 8576 --- [  Broker-Config] o.a.q.server.store.GenericStoreUpgrader  : VirtualHost store has model version 7.1. Number of record(s) 5
2019-06-06 15:18:39.142  INFO 8576 --- [  Broker-Config] qpid.message.virtualhost.created         : [Broker] VHT-1001 : Created : default
2019-06-06 15:18:39.164  INFO 8576 --- [  Broker-Config] q.message.configstore.recovery_complete  : [Broker] [vh(/default)/ms(MemoryConfigurationStore)] CFG-1005 : Recovery Complete
2019-06-06 15:18:39.179  INFO 8576 --- [-default-Config] qpid.message.exchange.created            : [Broker] EXH-1001 : Create : Durable Type: fanout Name: amq.fanout
2019-06-06 15:18:39.180  INFO 8576 --- [-default-Config] qpid.message.exchange.created            : [Broker] EXH-1001 : Create : Durable Type: headers Name: amq.match
2019-06-06 15:18:39.180  INFO 8576 --- [-default-Config] qpid.message.exchange.created            : [Broker] EXH-1001 : Create : Durable Type: topic Name: amq.topic
2019-06-06 15:18:39.180  INFO 8576 --- [-default-Config] qpid.message.exchange.created            : [Broker] EXH-1001 : Create : Durable Type: direct Name: amq.direct
[Broker] BRK-1002 : Starting : Listening on TCP port 5672
2019-06-06 15:18:39.187  INFO 8576 --- [  Broker-Config] qpid.message.broker.listening            : [Broker] BRK-1002 : Starting : Listening on TCP port 5672
2019-06-06 15:18:39.216  INFO 8576 --- [-default-Config] q.message.messagestore.recovery_start    : [Broker] [vh(/default)/ms(MemoryMessageStore)] MST-1004 : Recovery Start
2019-06-06 15:18:39.218  INFO 8576 --- [-default-Config] q.message.transactionlog.recovery_start  : [Broker] [vh(/default)/ms(MemoryMessageStore)] TXN-1004 : Recovery Start
2019-06-06 15:18:39.219  INFO 8576 --- [-default-Config] q.m.transactionlog.recovery_complete     : [Broker] [vh(/default)/ms(MemoryMessageStore)] TXN-1006 : Recovery Complete
2019-06-06 15:18:39.220  INFO 8576 --- [-default-Config] qpid.message.messagestore.recovered      : [Broker] [vh(/default)/ms(MemoryMessageStore)] MST-1005 : Recovered 0 messages
2019-06-06 15:18:39.220  INFO 8576 --- [-default-Config] q.m.messagestore.recovery_complete       : [Broker] [vh(/default)/ms(MemoryMessageStore)] MST-1006 : Recovery Complete
[Broker] BRK-1004 : Qpid Broker Ready
2019-06-06 15:18:39.224  INFO 8576 --- [  Broker-Config] qpid.message.broker.ready                : [Broker] BRK-1004 : Qpid Broker Ready
2019-06-06 15:18:39.344  INFO 8576 --- [           main] o.s.s.c.ThreadPoolTaskScheduler          : Initializing ExecutorService
2019-06-06 15:18:40.023  INFO 8576 --- [           main] o.s.a.r.c.CachingConnectionFactory       : Attempting to connect to: localhost:5672
2019-06-06 15:18:40.060  INFO 8576 --- [  Broker-Config] qpid.message.connection.open             : [con:0(/127.0.0.1:49260)] CON-1001 : Open : Destination : AMQP(127.0.0.1:5672) : Protocol Version : 0-9-1
2019-06-06 15:18:40.120  INFO 8576 --- [127.0.0.1:49260] qpid.message.connection.open             : [con:0(guest@/127.0.0.1:49260/default)] CON-1001 : Open : Destination : AMQP(127.0.0.1:5672) : Protocol Version : 0-9-1 : Client ID : e1ac1a25-0511-49ae-99d3-95e35b4fc0f9 : Client Version : 5.4.3 : Client Product : RabbitMQ
2019-06-06 15:18:40.124  INFO 8576 --- [           main] o.s.a.r.c.CachingConnectionFactory       : Created new connection: connectionFactory#64b7225f:0/SimpleConnection@288ca5f0 [delegate=amqp://guest@127.0.0.1:5672/, localPort= 49260]
2019-06-06 15:18:40.177  INFO 8576 --- [127.0.0.1:49260] qpid.message.channel.create              : [con:0(guest@/127.0.0.1:49260/default)/ch:1] CHN-1001 : Create
2019-06-06 15:18:40.206  INFO 8576 --- [-default-Config] qpid.message.exchange.created            : [con:0(guest@/127.0.0.1:49260/default)/ch:1] EXH-1001 : Create : Durable Type: direct Name: x.sample.second
2019-06-06 15:18:40.212  INFO 8576 --- [-default-Config] qpid.message.exchange.created            : [con:0(guest@/127.0.0.1:49260/default)/ch:1] EXH-1001 : Create : Durable Type: direct Name: x.sample.first
2019-06-06 15:18:40.263  INFO 8576 --- [-default-Config] qpid.message.queue.created               : [con:0(guest@/127.0.0.1:49260/default)/ch:1] [vh(/default)/qu(q.sample.second)] QUE-1001 : Create : ID: 91584d34-9030-4a85-963b-dc45fbb97bb8 Durable
2019-06-06 15:18:40.275  INFO 8576 --- [-default-Config] qpid.message.queue.created               : [con:0(guest@/127.0.0.1:49260/default)/ch:1] [vh(/default)/qu(q.sample.first)] QUE-1001 : Create : ID: 040a1dc8-de33-4aa9-9c9a-f4b67a3094be Durable
2019-06-06 15:18:40.285  INFO 8576 --- [-default-Config] qpid.message.binding.created             : [con:0(guest@/127.0.0.1:49260/default)/ch:1] [vh(/default)/ex(direct/x.sample.second)] BND-1001 : Create : {bindingKey=q.sample.second, destination=q.sample.second, arguments={}}
2019-06-06 15:18:40.290  INFO 8576 --- [-default-Config] qpid.message.binding.created             : [con:0(guest@/127.0.0.1:49260/default)/ch:1] [vh(/default)/ex(direct/x.sample.first)] BND-1001 : Create : {bindingKey=q.sample.first, destination=q.sample.first, arguments={}}
2019-06-06 15:18:40.306  INFO 8576 --- [127.0.0.1:49260] qpid.message.channel.prefetch_size       : [con:0(guest@/127.0.0.1:49260/default)/ch:1] CHN-1004 : Prefetch Size (bytes) 0 : Count 250
2019-06-06 15:18:40.321  INFO 8576 --- [-default-Config] qpid.message.subscription.create         : [con:0(guest@/127.0.0.1:49260/default)/ch:1] [sub:0(vh(/default)/qu(q.sample.second)] SUB-1001 : Create
2019-06-06 15:18:40.327  INFO 8576 --- [127.0.0.1:49260] qpid.message.channel.create              : [con:0(guest@/127.0.0.1:49260/default)/ch:2] CHN-1001 : Create
2019-06-06 15:18:40.332  INFO 8576 --- [127.0.0.1:49260] qpid.message.channel.prefetch_size       : [con:0(guest@/127.0.0.1:49260/default)/ch:2] CHN-1004 : Prefetch Size (bytes) 0 : Count 250
2019-06-06 15:18:40.334  INFO 8576 --- [-default-Config] qpid.message.subscription.create         : [con:0(guest@/127.0.0.1:49260/default)/ch:2] [sub:1(vh(/default)/qu(q.sample.first)] SUB-1001 : Create
2019-06-06 15:18:40.341  INFO 8576 --- [127.0.0.1:49260] qpid.message.channel.create              : [con:0(guest@/127.0.0.1:49260/default)/ch:3] CHN-1001 : Create
2019-06-06 15:18:40.344  INFO 8576 --- [           main] o.s.a.r.l.DirectMessageListenerContainer : Container initialized for queues: [q.sample.first]
2019-06-06 15:18:40.346  INFO 8576 --- [127.0.0.1:49260] qpid.message.channel.prefetch_size       : [con:0(guest@/127.0.0.1:49260/default)/ch:3] CHN-1004 : Prefetch Size (bytes) 0 : Count 250
2019-06-06 15:18:40.350  INFO 8576 --- [-default-Config] qpid.message.subscription.create         : [con:0(guest@/127.0.0.1:49260/default)/ch:3] [sub:2(vh(/default)/qu(q.sample.first)] SUB-1001 : Create
2019-06-06 15:18:40.351  INFO 8576 --- [sageContainer-1] o.s.a.r.l.DirectMessageListenerContainer : SimpleConsumer [queue=q.sample.first, consumerTag=sgen_1 identity=124f5893] started
2019-06-06 15:18:40.353  INFO 8576 --- [127.0.0.1:49260] qpid.message.channel.create              : [con:0(guest@/127.0.0.1:49260/default)/ch:4] CHN-1001 : Create
2019-06-06 15:18:40.355  INFO 8576 --- [127.0.0.1:49260] qpid.message.channel.prefetch_size       : [con:0(guest@/127.0.0.1:49260/default)/ch:4] CHN-1004 : Prefetch Size (bytes) 0 : Count 250
2019-06-06 15:18:40.359  INFO 8576 --- [-default-Config] qpid.message.subscription.create         : [con:0(guest@/127.0.0.1:49260/default)/ch:4] [sub:3(vh(/default)/qu(q.sample.first)] SUB-1001 : Create
2019-06-06 15:18:40.360  INFO 8576 --- [sageContainer-1] o.s.a.r.l.DirectMessageListenerContainer : SimpleConsumer [queue=q.sample.first, consumerTag=sgen_1 identity=18b733e3] started
2019-06-06 15:18:40.363  INFO 8576 --- [           main] com.example.MyMessageListenerTest        : Started MyMessageListenerTest in 3.502 seconds (JVM running for 4.314)
Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 4.027 s - in com.example.MyMessageListenerTest
2019-06-06 15:18:40.561  INFO 8576 --- [-default-Config] qpid.message.subscription.close          : [con:0(guest@/127.0.0.1:49260/default)/ch:1] [sub:0(vh(/default)/qu(q.sample.second)] SUB-1002 : Close
2019-06-06 15:18:40.566  INFO 8576 --- [       Thread-5] o.s.a.r.l.SimpleMessageListenerContainer : Waiting for workers to finish.
2019-06-06 15:18:40.568  INFO 8576 --- [127.0.0.1:49260] qpid.message.channel.close_forced        : [IO Pool] [con:0(guest@/127.0.0.1:49260/default)/ch:1] CHN-1003 : Close : 320 - Connection closed by external action
2019-06-06 15:18:40.568  INFO 8576 --- [-default-Config] qpid.message.subscription.close          : [IO Pool] [sub:1(vh(/default)/qu(q.sample.first)] SUB-1002 : Close
2019-06-06 15:18:40.569  INFO 8576 --- [127.0.0.1:49260] qpid.message.channel.close_forced        : [IO Pool] [con:0(guest@/127.0.0.1:49260/default)/ch:2] CHN-1003 : Close : 320 - Connection closed by external action
2019-06-06 15:18:40.569  INFO 8576 --- [-default-Config] qpid.message.subscription.close          : [IO Pool] [sub:2(vh(/default)/qu(q.sample.first)] SUB-1002 : Close
2019-06-06 15:18:40.570  INFO 8576 --- [127.0.0.1:49260] qpid.message.channel.close_forced        : [IO Pool] [con:0(guest@/127.0.0.1:49260/default)/ch:3] CHN-1003 : Close : 320 - Connection closed by external action
2019-06-06 15:18:40.570  INFO 8576 --- [-default-Config] qpid.message.subscription.close          : [IO Pool] [sub:3(vh(/default)/qu(q.sample.first)] SUB-1002 : Close
2019-06-06 15:18:40.571  INFO 8576 --- [127.0.0.1:49260] qpid.message.channel.close_forced        : [IO Pool] [con:0(guest@/127.0.0.1:49260/default)/ch:4] CHN-1003 : Close : 320 - Connection closed by external action
2019-06-06 15:18:40.574 ERROR 8576 --- [ 127.0.0.1:5672] o.s.a.r.c.CachingConnectionFactory       : Channel shutdown: connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=Connection closed by external action, class-id=0, method-id=0)
2019-06-06 15:18:40.574 ERROR 8576 --- [ 127.0.0.1:5672] o.s.a.r.c.CachingConnectionFactory       : Channel shutdown: connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=Connection closed by external action, class-id=0, method-id=0)
2019-06-06 15:18:40.574 ERROR 8576 --- [ 127.0.0.1:5672] o.s.a.r.c.CachingConnectionFactory       : Channel shutdown: connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=Connection closed by external action, class-id=0, method-id=0)
2019-06-06 15:18:40.575 ERROR 8576 --- [ 127.0.0.1:5672] o.s.a.r.c.CachingConnectionFactory       : Channel shutdown: connection error; protocol method: #method<connection.close>(reply-code=320, reply-text=Connection closed by external action, class-id=0, method-id=0)
2019-06-06 15:18:40.579  INFO 8576 --- [  Broker-Config] qpid.message.broker.shutting_down        : [Shutdown] BRK-1003 : Shutting down : TCP port 5672
2019-06-06 15:18:40.582  INFO 8576 --- [  Broker-Config] qpid.message.connection.close            : [con:0(guest@/127.0.0.1:49260/default)] CON-1002 : Close : 320 - Connection closed by external action
2019-06-06 15:18:40.586  INFO 8576 --- [-default-Config] qpid.message.virtualhost.closed          : [Shutdown] VHT-1002 : Closed : default
2019-06-06 15:18:40.588  INFO 8576 --- [  Broker-Config] qpid.message.configstore.close           : [Shutdown] [vh(/default)/ms(MemoryConfigurationStore)] CFG-1003 : Closed
2019-06-06 15:18:41.226  INFO 8576 --- [  Broker-Config] qpid.message.broker.stopped              : [Shutdown] BRK-1005 : Stopped
2019-06-06 15:18:41.325  INFO 8576 --- [       Thread-5] o.s.a.r.l.SimpleMessageListenerContainer : Successfully waited for workers to finish.
2019-06-06 15:18:41.326  INFO 8576 --- [       Thread-5] o.s.a.r.l.SimpleMessageListenerContainer : Waiting for workers to finish.
2019-06-06 15:18:41.327  INFO 8576 --- [       Thread-5] o.s.a.r.l.SimpleMessageListenerContainer : Successfully waited for workers to finish.
2019-06-06 15:18:41.327  INFO 8576 --- [       Thread-5] o.s.a.r.c.CachingConnectionFactory       : Attempting to connect to: localhost:5672
2019-06-06 15:18:43.346  WARN 8576 --- [       Thread-5] o.s.c.support.DefaultLifecycleProcessor  : Failed to stop bean 'firstQueueMessageContainer'

org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused: connect
    at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:62) ~[spring-rabbit-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:509) ~[spring-rabbit-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:700) ~[spring-rabbit-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createBareChannel(CachingConnectionFactory.java:651) ~[spring-rabbit-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.access$800(CachingConnectionFactory.java:102) ~[spring-rabbit-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at org.springframework.amqp.rabbit.connection.CachingConnectionFactory$CachedChannelInvocationHandler.invoke(CachingConnectionFactory.java:1138) ~[spring-rabbit-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at com.sun.proxy.$Proxy97.basicCancel(Unknown Source) ~[na:na]
    at org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer.cancelConsumer(DirectMessageListenerContainer.java:819) ~[spring-rabbit-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at java.lang.Iterable.forEach(Iterable.java:75) ~[na:1.8.0_112]
    at org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer.actualShutDown(DirectMessageListenerContainer.java:798) ~[spring-rabbit-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer.doShutdown(DirectMessageListenerContainer.java:756) ~[spring-rabbit-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.shutdown(AbstractMessageListenerContainer.java:1237) ~[spring-rabbit-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doStop(AbstractMessageListenerContainer.java:1353) ~[spring-rabbit-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer.doStop(DirectMessageListenerContainer.java:377) ~[spring-rabbit-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.stop(AbstractMessageListenerContainer.java:1326) ~[spring-rabbit-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.stop(AbstractMessageListenerContainer.java:1342) ~[spring-rabbit-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor.doStop(DefaultLifecycleProcessor.java:238) [spring-context-5.1.7.RELEASE.jar:5.1.7.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor.access$300(DefaultLifecycleProcessor.java:53) [spring-context-5.1.7.RELEASE.jar:5.1.7.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.stop(DefaultLifecycleProcessor.java:377) [spring-context-5.1.7.RELEASE.jar:5.1.7.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor.stopBeans(DefaultLifecycleProcessor.java:210) [spring-context-5.1.7.RELEASE.jar:5.1.7.RELEASE]
    at org.springframework.context.support.DefaultLifecycleProcessor.onClose(DefaultLifecycleProcessor.java:128) [spring-context-5.1.7.RELEASE.jar:5.1.7.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1018) [spring-context-5.1.7.RELEASE.jar:5.1.7.RELEASE]
    at org.springframework.context.support.AbstractApplicationContext$1.run(AbstractApplicationContext.java:945) [spring-context-5.1.7.RELEASE.jar:5.1.7.RELEASE]
Caused by: java.net.ConnectException: Connection refused: connect
    at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method) ~[na:1.8.0_112]
    at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85) ~[na:1.8.0_112]
    at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_112]
    at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_112]
    at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_112]
    at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172) ~[na:1.8.0_112]
    at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_112]
    at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_112]
    at com.rabbitmq.client.impl.SocketFrameHandlerFactory.create(SocketFrameHandlerFactory.java:60) ~[amqp-client-5.4.3.jar:5.4.3]
    at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1102) ~[amqp-client-5.4.3.jar:5.4.3]
    at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1054) ~[amqp-client-5.4.3.jar:5.4.3]
    at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1218) ~[amqp-client-5.4.3.jar:5.4.3]
    at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:471) ~[spring-rabbit-2.1.6.RELEASE.jar:2.1.6.RELEASE]
    ... 21 common frames omitted

2019-06-06 15:18:43.348  INFO 8576 --- [       Thread-5] o.s.a.r.l.DirectMessageListenerContainer : Shutdown ignored - container is not active already
2019-06-06 15:18:43.349  INFO 8576 --- [       Thread-5] o.s.a.r.l.SimpleMessageListenerContainer : Shutdown ignored - container is not active already
2019-06-06 15:18:43.349  INFO 8576 --- [       Thread-5] o.s.a.r.l.SimpleMessageListenerContainer : Shutdown ignored - container is not active already
2019-06-06 15:18:43.349 ERROR 8576 --- [       Thread-5] o.a.q.s.c.updater.TaskExecutorImpl       : Task executor Broker-Config is not in ACTIVE state, unable to execute : Task['close' on 'SystemConfig[id=00000000-0000-0000-0000-000000000000, name=System, type=Memory]'] 
2019-06-06 15:18:43.351  INFO 8576 --- [       Thread-5] o.s.b.f.support.DisposableBeanAdapter    : Destroy method 'shutdown' on bean with name 'qpidBroker' threw an exception: java.lang.IllegalStateException: Task executor Broker-Config is not in ACTIVE state

Results:

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0

Что я делаю не так?

1 Ответ

0 голосов
/ 06 июня 2019

Из журналов выше я не уверен, что есть проблема как таковая. Похоже, что тест «завершается», но затем вы видите ошибки, потому что брокер закрылся до того, как клиент выключился, поэтому, когда клиент пытается завершить работу, он получает ошибки, пытаясь связаться с брокером:

2019-06-06 15:18:40.359  INFO 8576 --- [-default-Config] qpid.message.subscription.create         : [con:0(guest@/127.0.0.1:49260/default)/ch:4] [sub:3(vh(/default)/qu(q.sample.first)] SUB-1001 : Create
2019-06-06 15:18:40.360  INFO 8576 --- [sageContainer-1] o.s.a.r.l.DirectMessageListenerContainer : SimpleConsumer [queue=q.sample.first, consumerTag=sgen_1 identity=18b733e3] started
2019-06-06 15:18:40.363  INFO 8576 --- [           main] com.example.MyMessageListenerTest        : Started MyMessageListenerTest in 3.502 seconds (JVM running for 4.314)

До сих пор все хорошо

Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 4.027 s - in com.example.MyMessageListenerTest

Указывает, что тест завершен

2019-06-06 15:18:40.561  INFO 8576 --- [-default-Config] qpid.message.subscription.close          : [con:0(guest@/127.0.0.1:49260/default)/ch:1] [sub:0(vh(/default)/qu(q.sample.second)] SUB-1002 : Close
2019-06-06 15:18:40.566  INFO 8576 --- [       Thread-5] o.s.a.r.l.SimpleMessageListenerContainer : Waiting for workers to finish.
2019-06-06 15:18:40.568  INFO 8576 --- [127.0.0.1:49260] qpid.message.channel.close_forced        : [IO Pool] [con:0(guest@/127.0.0.1:49260/default)/ch:1] CHN-1003 : Close : 320 - Connection closed by external action

Эти сообщения выше указывают на то, что сервер закрывает открытые соединения (возможно, из-за закрытия брокера).

Затем вы получите исключения, указывающие на то, что клиент не может подключиться к серверу, но если вы посмотрите на методы, в которых эти исключения генерируются, то, похоже, в логике выключения клиента.

...