在SimpleMessageListenerContainer
调用后,消费者未在shutdownTimeout
AnnotationConfigApplicationContext.close()
内完成执行时,我的Spring应用程序将挂起。
监听器:
public class LongRunningMessageListener implements MessageListener {
@Override
public void onMessage(Message message) {
System.out.println("Got " + new String(message.getBody()));
try {
Thread.sleep(5000L);
} catch (InterruptedException e) {
System.out.println("Interrupted");
Thread.currentThread().interrupt();
}
System.out.println("Finished execution");
}
}
配置:
@Configuration
public class Config {
@Bean
public MessageListenerContainer messageListenerContainer() {
SimpleMessageListenerContainer messageListenerContainer = new SimpleMessageListenerContainer(connectionFactory());
messageListenerContainer.setQueueNames("myqueue");
messageListenerContainer.setMessageListener(new LongRunningMessageListener());
messageListenerContainer.setShutdownTimeout(1000);
return messageListenerContainer;
}
@Bean
public ConnectionFactory connectionFactory() {
return new CachingConnectionFactory("localhost");
}
}
主:
public static void main(String[] args) throws InterruptedException {
AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(Config.class);
Thread.sleep(1000L);
applicationContext.close();
}
输出:
мая 08, 2015 3:43:21 PM org.springframework.context.annotation.AnnotationConfigApplicationContext prepareRefresh
INFO: Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@1a86f2f1: startup date [Fri May 08 15:43:21 MSK 2015]; root of context hierarchy
мая 08, 2015 3:43:22 PM org.springframework.context.support.DefaultLifecycleProcessor start
INFO: Starting beans in phase 2147483647
мая 08, 2015 3:43:22 PM org.springframework.amqp.rabbit.connection.CachingConnectionFactory createBareConnection
INFO: Created new connection: SimpleConnection@4025f2f5 [delegate=amqp://guest@127.0.0.1:5672/]
Got foo1
мая 08, 2015 3:43:23 PM org.springframework.context.annotation.AnnotationConfigApplicationContext doClose
INFO: Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@1a86f2f1: startup date [Fri May 08 15:43:21 MSK 2015]; root of context hierarchy
мая 08, 2015 3:43:23 PM org.springframework.context.support.DefaultLifecycleProcessor stop
INFO: Stopping beans in phase 2147483647
мая 08, 2015 3:43:23 PM org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer doShutdown
INFO: Waiting for workers to finish.
мая 08, 2015 3:43:24 PM org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer doShutdown
INFO: Workers not finished. Forcing connections to close.
Finished execution
мая 08, 2015 3:43:27 PM org.springframework.amqp.rabbit.connection.CachingConnectionFactory createBareConnection
INFO: Created new connection: SimpleConnection@260da64e [delegate=amqp://guest@127.0.0.1:5672/]
мая 08, 2015 3:43:27 PM org.springframework.amqp.rabbit.connection.CachingConnectionFactory shutdownCompleted
SEVERE: Channel shutdown: channel error; protocol method: #method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - unknown delivery tag 1, class-id=60, method-id=80)
此应用程序无限期地工作。
工作线程:
Live threads: 14
Daemon threads: 10
非守护程序线程:
"pool-1-thread-10" #22 prio=5 os_prio=31 tid=0x00007fd48c93c800 nid=0x5a07 waiting on condition [0x0000000129eb3000]
java.lang.Thread.State: WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x0000000796333168> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.park(LockSupport.java:175)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2039)
at java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:442)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1067)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Locked ownable synchronizers:
- None
"pool-1-thread-9" #21 prio=5 os_prio=31 tid=0x00007fd48b9d8000 nid=0x540b waiting on condition [0x0000000129db0000]
java.lang.Thread.State: TIMED_WAITING (parking)
at sun.misc.Unsafe.park(Native Method)
- parking to wait for <0x000000079633dfb0> (a java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject)
at java.util.concurrent.locks.LockSupport.parkNanos(LockSupport.java:215)
at java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.awaitNanos(AbstractQueuedSynchronizer.java:2078)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:1093)
at java.util.concurrent.ScheduledThreadPoolExecutor$DelayedWorkQueue.take(ScheduledThreadPoolExecutor.java:809)
at java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1067)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1127)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Locked ownable synchronizers:
- None
"AMQP Connection 127.0.0.1:5672" #20 prio=5 os_prio=31 tid=0x00007fd48d186000 nid=0x530b runnable [0x0000000129cad000]
java.lang.Thread.State: RUNNABLE
at java.net.SocketInputStream.socketRead0(Native Method)
at java.net.SocketInputStream.socketRead(SocketInputStream.java:116)
at java.net.SocketInputStream.read(SocketInputStream.java:170)
at java.net.SocketInputStream.read(SocketInputStream.java:141)
at java.io.BufferedInputStream.fill(BufferedInputStream.java:246)
at java.io.BufferedInputStream.read(BufferedInputStream.java:265)
- locked <0x000000079632e8f0> (a java.io.BufferedInputStream)
at java.io.DataInputStream.readUnsignedByte(DataInputStream.java:288)
at com.rabbitmq.client.impl.Frame.readFrom(Frame.java:95)
at com.rabbitmq.client.impl.SocketFrameHandler.readFrame(SocketFrameHandler.java:139)
- locked <0x000000079632e8d0> (a java.io.DataInputStream)
at com.rabbitmq.client.impl.AMQConnection$MainLoop.run(AMQConnection.java:534)
at java.lang.Thread.run(Thread.java:745)
Locked ownable synchronizers:
- None
"DestroyJavaVM" #19 prio=5 os_prio=31 tid=0x00007fd48d002000 nid=0x1303 waiting on condition [0x0000000000000000]
java.lang.Thread.State: RUNNABLE
Locked ownable synchronizers:
- None
如果我增加shutdownTimeout
,一切都很好,但是超时行为看起来像个错误。
Spring版本:
spring-amqp 1.4.5.RELEASE
spring-rabbit 1.4.5.RELEASE
spring-context 4.1.5.RELEASE
更新:
我已经通过Log
调用替换了System.out.println的调用,并将log4j配置为日志记录。模式:%r [%t] %-5p %c{1} - %m%n
输出:
0 [main] DEBUG StandardEnvironment - Adding [systemProperties] PropertySource with lowest search precedence
3 [main] DEBUG StandardEnvironment - Adding [systemEnvironment] PropertySource with lowest search precedence
4 [main] DEBUG StandardEnvironment - Initialized StandardEnvironment with PropertySources [systemProperties,systemEnvironment]
130 [main] INFO AnnotationConfigApplicationContext - Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext@73a8dfcc: startup date [Fri May 08 17:07:06 MSK 2015]; root of context hierarchy
132 [main] DEBUG AnnotationConfigApplicationContext - Bean factory for org.springframework.context.annotation.AnnotationConfigApplicationContext@73a8dfcc: org.springframework.beans.factory.support.DefaultListableBeanFactory@1593948d: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,config]; root of factory hierarchy
178 [main] DEBUG DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor'
179 [main] DEBUG DefaultListableBeanFactory - Creating instance of bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor'
232 [main] DEBUG DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor' to allow for resolving potential circular references
235 [main] DEBUG DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor'
288 [main] DEBUG ConfigurationClassBeanDefinitionReader - Registering bean definition for @Bean method Config.messageListenerContainer()
288 [main] DEBUG ConfigurationClassBeanDefinitionReader - Registering bean definition for @Bean method Config.connectionFactory()
431 [main] DEBUG ConfigurationClassEnhancer - Successfully enhanced Config; enhanced class name is: Config$$EnhancerBySpringCGLIB$$b6627e0a
432 [main] DEBUG ConfigurationClassPostProcessor - Replacing bean definition 'config' existing class name 'Config' with enhanced class name 'Config$$EnhancerBySpringCGLIB$$b6627e0a'
436 [main] DEBUG DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
436 [main] DEBUG DefaultListableBeanFactory - Creating instance of bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
438 [main] DEBUG DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor' to allow for resolving potential circular references
438 [main] DEBUG DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
438 [main] DEBUG DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor'
438 [main] DEBUG DefaultListableBeanFactory - Creating instance of bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor'
439 [main] DEBUG DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor' to allow for resolving potential circular references
439 [main] DEBUG DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor'
439 [main] DEBUG DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor'
439 [main] DEBUG DefaultListableBeanFactory - Creating instance of bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor'
445 [main] DEBUG DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor' to allow for resolving potential circular references
445 [main] DEBUG DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor'
445 [main] DEBUG DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor'
445 [main] DEBUG DefaultListableBeanFactory - Creating instance of bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor'
445 [main] DEBUG DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor' to allow for resolving potential circular references
446 [main] DEBUG DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor'
446 [main] DEBUG DefaultListableBeanFactory - Creating shared instance of singleton bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor'
446 [main] DEBUG DefaultListableBeanFactory - Creating instance of bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor'
446 [main] DEBUG DefaultListableBeanFactory - Eagerly caching bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor' to allow for resolving potential circular references
446 [main] DEBUG DefaultListableBeanFactory - Finished creating instance of bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor'
450 [main] DEBUG AnnotationConfigApplicationContext - Unable to locate MessageSource with name 'messageSource': using default [org.springframework.context.support.DelegatingMessageSource@27d415d9]
454 [main] DEBUG AnnotationConfigApplicationContext - Unable to locate ApplicationEventMulticaster with name 'applicationEventMulticaster': using default [org.springframework.context.event.SimpleApplicationEventMulticaster@b3d7190]
461 [main] DEBUG DefaultListableBeanFactory - Pre-instantiating singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1593948d: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,config,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor,messageListenerContainer,connectionFactory]; root of factory hierarchy
461 [main] DEBUG DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.context.annotation.internalConfigurationAnnotationProcessor'
462 [main] DEBUG DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.context.annotation.internalAutowiredAnnotationProcessor'
462 [main] DEBUG DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.context.annotation.internalRequiredAnnotationProcessor'
462 [main] DEBUG DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.context.annotation.internalCommonAnnotationProcessor'
462 [main] DEBUG DefaultListableBeanFactory - Creating shared instance of singleton bean 'config'
463 [main] DEBUG DefaultListableBeanFactory - Creating instance of bean 'config'
468 [main] DEBUG DefaultListableBeanFactory - Eagerly caching bean 'config' to allow for resolving potential circular references
494 [main] DEBUG DefaultListableBeanFactory - Finished creating instance of bean 'config'
494 [main] DEBUG DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor'
494 [main] DEBUG DefaultListableBeanFactory - Returning cached instance of singleton bean 'org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor'
494 [main] DEBUG DefaultListableBeanFactory - Creating shared instance of singleton bean 'messageListenerContainer'
495 [main] DEBUG DefaultListableBeanFactory - Creating instance of bean 'messageListenerContainer'
497 [main] DEBUG DefaultListableBeanFactory - Returning cached instance of singleton bean 'config'
551 [main] DEBUG DefaultListableBeanFactory - Creating shared instance of singleton bean 'connectionFactory'
551 [main] DEBUG DefaultListableBeanFactory - Creating instance of bean 'connectionFactory'
552 [main] DEBUG DefaultListableBeanFactory - Returning cached instance of singleton bean 'config'
595 [main] DEBUG DefaultListableBeanFactory - Eagerly caching bean 'connectionFactory' to allow for resolving potential circular references
609 [main] DEBUG DefaultListableBeanFactory - Invoking afterPropertiesSet() on bean with name 'connectionFactory'
609 [main] DEBUG DefaultListableBeanFactory - Finished creating instance of bean 'connectionFactory'
638 [main] DEBUG DefaultListableBeanFactory - Eagerly caching bean 'messageListenerContainer' to allow for resolving potential circular references
707 [main] DEBUG DefaultListableBeanFactory - Invoking afterPropertiesSet() on bean with name 'messageListenerContainer'
708 [main] DEBUG SimpleMessageListenerContainer - No global properties bean
708 [main] DEBUG DefaultListableBeanFactory - Finished creating instance of bean 'messageListenerContainer'
708 [main] DEBUG DefaultListableBeanFactory - Returning cached instance of singleton bean 'connectionFactory'
710 [main] DEBUG AnnotationConfigApplicationContext - Unable to locate LifecycleProcessor with name 'lifecycleProcessor': using default [org.springframework.context.support.DefaultLifecycleProcessor@b62fe6d]
710 [main] DEBUG DefaultListableBeanFactory - Returning cached instance of singleton bean 'messageListenerContainer'
710 [main] DEBUG DefaultListableBeanFactory - Returning cached instance of singleton bean 'lifecycleProcessor'
716 [main] INFO DefaultLifecycleProcessor - Starting beans in phase 2147483647
716 [main] DEBUG DefaultLifecycleProcessor - Starting bean 'messageListenerContainer' of type [class org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer]
716 [main] DEBUG SimpleMessageListenerContainer - No global properties bean
716 [main] DEBUG SimpleMessageListenerContainer - Starting Rabbit listener container.
767 [SimpleAsyncTaskExecutor-1] DEBUG BlockingQueueConsumer - Starting consumer Consumer: tags=[{}], channel=null, acknowledgeMode=AUTO local queue size=0
852 [SimpleAsyncTaskExecutor-1] INFO CachingConnectionFactory - Created new connection: SimpleConnection@25c0a36 [delegate=amqp://guest@127.0.0.1:5672/]
869 [SimpleAsyncTaskExecutor-1] DEBUG CachingConnectionFactory - Creating cached Rabbit Channel from AMQChannel(amqp://guest@127.0.0.1:5672/,1)
911 [pool-1-thread-3] DEBUG BlockingQueueConsumer - ConsumeOK : Consumer: tags=[{}], channel=Cached Rabbit Channel: AMQChannel(amqp://guest@127.0.0.1:5672/,1), acknowledgeMode=AUTO local queue size=0
914 [pool-1-thread-4] DEBUG BlockingQueueConsumer - Storing delivery for Consumer: tags=[{}], channel=Cached Rabbit Channel: AMQChannel(amqp://guest@127.0.0.1:5672/,1), acknowledgeMode=AUTO local queue size=0
915 [SimpleAsyncTaskExecutor-1] DEBUG BlockingQueueConsumer - Started on queue 'myqueue' with tag amq.ctag-KkQJOq3Z0r8Uc0JwcKdGxQ: Consumer: tags=[{amq.ctag-KkQJOq3Z0r8Uc0JwcKdGxQ=myqueue}], channel=Cached Rabbit Channel: AMQChannel(amqp://guest@127.0.0.1:5672/,1), acknowledgeMode=AUTO local queue size=1
916 [SimpleAsyncTaskExecutor-1] DEBUG BlockingQueueConsumer - Retrieving delivery for Consumer: tags=[{amq.ctag-KkQJOq3Z0r8Uc0JwcKdGxQ=myqueue}], channel=Cached Rabbit Channel: AMQChannel(amqp://guest@127.0.0.1:5672/,1), acknowledgeMode=AUTO local queue size=1
920 [SimpleAsyncTaskExecutor-1] DEBUG BlockingQueueConsumer - Received message: (Body:'foo5'MessageProperties [headers={}, timestamp=null, messageId=null, userId=null, appId=null, clusterId=null, type=null, correlationId=null, replyTo=null, contentType=text/plain, contentEncoding=UTF-8, contentLength=0, deliveryMode=PERSISTENT, expiration=null, priority=0, redelivered=true, receivedExchange=, receivedRoutingKey=myqueue, deliveryTag=1, messageCount=0])
921 [SimpleAsyncTaskExecutor-1] INFO LongRunningMessageListener - Got foo5
921 [main] DEBUG DefaultLifecycleProcessor - Successfully started bean 'messageListenerContainer'
931 [main] DEBUG PropertySourcesPropertyResolver - Searching for key 'spring.liveBeansView.mbeanDomain' in [systemProperties]
932 [main] DEBUG PropertySourcesPropertyResolver - Searching for key 'spring.liveBeansView.mbeanDomain' in [systemEnvironment]
933 [main] DEBUG PropertySourcesPropertyResolver - Could not find key 'spring.liveBeansView.mbeanDomain' in any property source. Returning [null]
1938 [main] INFO AnnotationConfigApplicationContext - Closing org.springframework.context.annotation.AnnotationConfigApplicationContext@73a8dfcc: startup date [Fri May 08 17:07:06 MSK 2015]; root of context hierarchy
1938 [main] DEBUG DefaultListableBeanFactory - Returning cached instance of singleton bean 'messageListenerContainer'
1938 [main] DEBUG DefaultListableBeanFactory - Returning cached instance of singleton bean 'lifecycleProcessor'
1939 [main] INFO DefaultLifecycleProcessor - Stopping beans in phase 2147483647
1939 [main] DEBUG DefaultLifecycleProcessor - Asking bean 'messageListenerContainer' of type [class org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer] to stop
1939 [main] DEBUG SimpleMessageListenerContainer - Shutting down Rabbit listener container
1941 [main] INFO SimpleMessageListenerContainer - Waiting for workers to finish.
1941 [pool-1-thread-5] DEBUG BlockingQueueConsumer - Received cancellation notice for tag amq.ctag-KkQJOq3Z0r8Uc0JwcKdGxQ; Consumer: tags=[{}], channel=Cached Rabbit Channel: AMQChannel(amqp://guest@127.0.0.1:5672/,1), acknowledgeMode=AUTO local queue size=0
2946 [main] INFO SimpleMessageListenerContainer - Workers not finished. Forcing connections to close.
2946 [main] DEBUG DefaultLifecycleProcessor - Bean 'messageListenerContainer' completed its stop procedure
2946 [main] DEBUG DefaultListableBeanFactory - Destroying singletons in org.springframework.beans.factory.support.DefaultListableBeanFactory@1593948d: defining beans [org.springframework.context.annotation.internalConfigurationAnnotationProcessor,org.springframework.context.annotation.internalAutowiredAnnotationProcessor,org.springframework.context.annotation.internalRequiredAnnotationProcessor,org.springframework.context.annotation.internalCommonAnnotationProcessor,config,org.springframework.context.annotation.ConfigurationClassPostProcessor.importAwareProcessor,org.springframework.context.annotation.ConfigurationClassPostProcessor.enhancedConfigurationProcessor,messageListenerContainer,connectionFactory]; root of factory hierarchy
2946 [main] DEBUG DisposableBeanAdapter - Invoking destroy() on bean with name 'messageListenerContainer'
2946 [main] DEBUG SimpleMessageListenerContainer - Shutting down Rabbit listener container
2946 [main] DEBUG DisposableBeanAdapter - Invoking destroy() on bean with name 'connectionFactory'
5923 [SimpleAsyncTaskExecutor-1] INFO LongRunningMessageListener - Finished execution
5927 [SimpleAsyncTaskExecutor-1] INFO CachingConnectionFactory - Created new connection: SimpleConnection@5d0224dc [delegate=amqp://guest@127.0.0.1:5672/]
5928 [SimpleAsyncTaskExecutor-1] DEBUG BlockingQueueConsumer - Retrieving delivery for Consumer: tags=[{}], channel=Cached Rabbit Channel: AMQChannel(amqp://guest@127.0.0.1:5672/,1), acknowledgeMode=AUTO local queue size=0
5929 [AMQP Connection 127.0.0.1:5672] ERROR CachingConnectionFactory - Channel shutdown: channel error; protocol method: #method<channel.close>(reply-code=406, reply-text=PRECONDITION_FAILED - unknown delivery tag 1, class-id=60, method-id=80)
6932 [SimpleAsyncTaskExecutor-1] DEBUG SimpleMessageListenerContainer - Cancelling Consumer: tags=[{}], channel=Cached Rabbit Channel: AMQChannel(amqp://guest@127.0.0.1:5672/,1), acknowledgeMode=AUTO local queue size=0
6933 [SimpleAsyncTaskExecutor-1] DEBUG BlockingQueueConsumer - Closing Rabbit Channel: Cached Rabbit Channel: AMQChannel(amqp://guest@127.0.0.1:5672/,1)
6933 [SimpleAsyncTaskExecutor-1] DEBUG CachingConnectionFactory - Closing cached Channel: AMQChannel(amqp://guest@127.0.0.1:5672/,1)
答案 0 :(得分:1)
关于你对这个问题的评论(回应@ Artem的解决方法)...
我也试过这个解决方案。它适用于这个简单的情况(Thread.sleep()),但是当监听器正在做的时候不起作用&#34;真正的&#34;例如,长期等待IO的工作。
如果用户代码处于不间断状态(如等待套接字I / O),框架无法执行任何操作。你需要以某种方式关闭套接字。