Spring JmsListener在应用程序运行时启动/停止

问题描述 投票:0回答:1

我在应用程序运行时无法启动JmsListener。我尝试过此answer on the topic,但没有运气。

我在JmsListenerContainerFactory中将autoStartup设置为false,并且消息正在队列中等待。但是,当我在下面的代码中调用控制器时,什么也没有发生。 JmsLister不会开始使用消息。

任何帮助将不胜感激。

控制器代码:

@RestController
public class MessageController {

    private final JmsListenerEndpointRegistry jmsListenerEndpointRegistry;

    public MessageController(JmsListenerEndpointRegistry jmsListenerEndpointRegistry) {
        this.jmsListenerEndpointRegistry = jmsListenerEndpointRegistry;
    }

    @GetMapping("messages/start")
    public ResponseEntity start() {
        if(jmsListenerEndpointRegistry.isRunning())
            return ResponseEntity.badRequest().build(); // second time I request this endpoint it says it is running

        jmsListenerEndpointRegistry.getListenerContainerIds().forEach(id -> {
            MessageListenerContainer listenerContainer = jmsListenerEndpointRegistry.getListenerContainer(id);
            if (listenerContainer != null) {
                listenerContainer.start();
            }
        });
        jmsListenerEndpointRegistry.start();
        return ResponseEntity.ok().build();
    }
}

编辑:这是当我向控制器发送请求时的调试日志:

19:59:41.231 [http-nio-8080-exec-2] DEBUG o.s.web.servlet.DispatcherServlet - GET "/messages/start", parameters={}
19:59:41.238 [http-nio-8080-exec-2] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped to MessageController#start()
19:59:53.764 [http-nio-8080-exec-2] DEBUG o.a.a.transport.WireFormatNegotiator - Sending: WireFormatInfo { version=12, properties={StackTraceEnabled=true, PlatformDetails=Java, CacheEnabled=true, Host=mqserver, TcpNoDelayEnabled=true, SizePrefixDisabled=false, CacheSize=1024, ProviderName=ActiveMQ, TightEncodingEnabled=true, MaxFrameSize=9223372036854775807, MaxInactivityDuration=30000, MaxInactivityDurationInitalDelay=10000, ProviderVersion=5.15.11}, magic=[A,c,t,i,v,e,M,Q]}
19:59:53.773 [ActiveMQ Transport: tcp://mqserver/127.0.0.1:49040@48600] DEBUG o.a.a.transport.InactivityMonitor - Using min of local: WireFormatInfo { version=12, properties={StackTraceEnabled=true, PlatformDetails=Java, CacheEnabled=true, Host=mqserver, TcpNoDelayEnabled=true, SizePrefixDisabled=false, CacheSize=1024, ProviderName=ActiveMQ, TightEncodingEnabled=true, MaxFrameSize=9223372036854775807, MaxInactivityDuration=30000, MaxInactivityDurationInitalDelay=10000, ProviderVersion=5.15.11}, magic=[A,c,t,i,v,e,M,Q]} and remote: WireFormatInfo { version=9, properties={CacheSize=1024, SizePrefixDisabled=false, TcpNoDelayEnabled=true, StackTraceEnabled=true, CacheEnabled=true, MaxFrameSize=9223372036854775807, TightEncodingEnabled=true, MaxInactivityDuration=30000, MaxInactivityDurationInitalDelay=10000}, magic=[A,c,t,i,v,e,M,Q]}
19:59:53.774 [ActiveMQ Transport: tcp://mqserver/127.0.0.1:49040@48600] DEBUG o.a.a.transport.WireFormatNegotiator - Received WireFormat: WireFormatInfo { version=9, properties={CacheSize=1024, SizePrefixDisabled=false, TcpNoDelayEnabled=true, StackTraceEnabled=true, CacheEnabled=true, MaxFrameSize=9223372036854775807, TightEncodingEnabled=true, MaxInactivityDuration=30000, MaxInactivityDurationInitalDelay=10000}, magic=[A,c,t,i,v,e,M,Q]}
19:59:53.774 [ActiveMQ Transport: tcp://mqserver/127.0.0.1:49040@48600] DEBUG o.a.a.transport.WireFormatNegotiator - tcp://mqserver/127.0.0.1:49040@48600 before negotiation: OpenWireFormat{version=12, cacheEnabled=false, stackTraceEnabled=false, tightEncodingEnabled=false, sizePrefixDisabled=false, maxFrameSize=9223372036854775807}
19:59:53.790 [ActiveMQ Transport: tcp://mqserver/127.0.0.1:49040@48600] DEBUG o.a.a.transport.WireFormatNegotiator - tcp://mqserver/127.0.0.1:49040@48600 after negotiation: OpenWireFormat{version=9, cacheEnabled=true, stackTraceEnabled=true, tightEncodingEnabled=true, sizePrefixDisabled=false, maxFrameSize=9223372036854775807}
19:59:53.895 [http-nio-8080-exec-2] DEBUG o.s.j.l.DefaultMessageListenerContainer - Established shared JMS Connection
19:59:53.896 [http-nio-8080-exec-2] DEBUG o.s.j.l.DefaultMessageListenerContainer - Resumed paused task: org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker@4fc72d52
20:00:00.326 [DefaultMessageListenerContainer-1] DEBUG o.a.a.thread.TaskRunnerFactory - Initialized TaskRunnerFactory[ActiveMQ Session Task] using ExecutorService: java.util.concurrent.ThreadPoolExecutor@4364b2e9[Running, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0]

编辑:我正在针对错误的ActiveMq实例进行测试,但是被接受的答案帮助我以一种简单有效的方式来测试和调试“错误”]

我在应用程序运行时无法启动JmsListener。我尝试过这个话题的答案,但是没有运气。我在JmsListenerContainerFactory中将autoStartup设置为false,并且我...

spring spring-boot jms spring-jms
1个回答
1
投票

奇怪;这对我来说很好...

© www.soinside.com 2019 - 2024. All rights reserved.