2017-04-03 13 views
2

DefaultMessageListenerContainerが無期限にブロック(ルーピング)されているように見えるため、Tomcat(8)を正常にシャットダウンしようとすると問題が発生します。Spring統合でTomcatがシャットダウンするJava DSL

私は解決策を探していましたが、私が見つけたのと同じものはうまく機能しませんでした。これには、(これに限定されない):

CachingConnectionFactory

ActiveMQConnectionFactory簡単ラッピングMessages.queue()代わりにMessages.direct()

  • を用いた容器
  • ののTaskExecutorを設定するconfigureListenerContainer()を使用
    • サーブレット3.0の例:

      compile 'org.springframework.integration:spring-integration-core:4.3.6.RELEASE' 
      compile 'org.springframework.integration:spring-integration-jms:4.3.6.RELEASE' 
      compile 'org.springframework.integration:spring-integration-java-dsl:1.2.1.RELEASE' 
      

      イニシャライザ:

      public class ExampleWebApp implements WebApplicationInitializer { 
          @Override 
          public void onStartup(final ServletContext servletContext) throws ServletException { 
           final AnnotationConfigWebApplicationContext springContext = new AnnotationConfigWebApplicationContext(); 
           springContext.register(ExampleConfig.class); 
      
           servletContext.addListener(new ContextLoaderListener(springContext)); 
      
           final ServletRegistration.Dynamic registration = servletContext.addServlet("example", new HttpRequestHandlerServlet()); 
           registration.setLoadOnStartup(1); 
           registration.addMapping("/status"); 
          } 
      } 
      

      構成:

      @Configuration 
      @EnableIntegration 
      public class ExampleConfig { 
          @Bean 
          public ConnectionFactory connectionFactory() { 
           final ActiveMQConnectionFactory mqConnectionFactory = new ActiveMQConnectionFactory(); 
           mqConnectionFactory.setBrokerURL("tcp://host:port"); 
           mqConnectionFactory.setUserName("----"); 
           mqConnectionFactory.setPassword("----"); 
      
           return mqConnectionFactory; 
          } 
      
          @Bean 
          public Queue testQueue() { 
           return new ActiveMQQueue("test.queue"); 
          } 
      
          @Bean 
          public MessageChannel testReceiveChannel() { 
           return MessageChannels.direct().get(); 
          } 
      
          @Bean 
          public IntegrationFlow pushMessageInboundFlow() { 
           return IntegrationFlows 
             .from(Jms.messageDrivenChannelAdapter(connectionFactory()) 
               .destination(testQueue())) 
             .log() 
             .transform(new JsonToObjectTransformer(TestMessageObject.class)) 
             .channel(testReceiveChannel()) 
             .get(); 
          } 
      
          /** Example message object */ 
          public static class TestMessageObject { 
           private String text; 
      
           public String getText() { 
            return text; 
           } 
      
           public void setText(final String text) { 
            this.text = text; 
           } 
          } 
      } 
      

      私は(例えば、「のIntelliJで "停止" を押すと、それは既存の終了決して試してみて、catalina.shスクリプトを経由して、これを停止した場合。これまでのところ、私は仕上げにシャットダウンを取得することができた唯一の方法は、「手動」である小さなヘルパークラスを経由して、シャットダウン時にJmsMessageAdaptersを破壊:

      public class JmsMessageListenerContainerLifecycleManager { 
          private static final Logger LOG = LoggerFactory.getLogger(JmsMessageListenerContainerLifecycleManager.class); 
      
          @Autowired 
          private List<IntegrationFlow> mIntegrationFlows; 
      
          @PreDestroy 
          public void shutdownJmsAdapters() throws Exception { 
           LOG.info("Checking {} integration flows for JMS message adapters", mIntegrationFlows.size()); 
      
           for (IntegrationFlow flow : mIntegrationFlows) { 
            if (flow instanceof StandardIntegrationFlow) { 
             final StandardIntegrationFlow standardFlow = (StandardIntegrationFlow) flow; 
      
             for (Object component : standardFlow.getIntegrationComponents()) { 
              if (component instanceof JmsMessageDrivenChannelAdapter) { 
               final JmsMessageDrivenChannelAdapter adapter = (JmsMessageDrivenChannelAdapter) component; 
      
               LOG.info("Destroying JMS adapter {}", adapter.getComponentName()); 
               adapter.destroy(); 
              } 
             } 
            } 
           } 
          } 
      } 
      

      そして、それは動作しますが、それは間違いなく間違っているように感じています溶液。

      以前私はバネ統合のXML構成を使用していましたが、この問題はありませんでした。私は何が欠けていますか?

  • 答えて

    1

    これは間違いなくバグです。そしてあなたはそれを適切に回避するように見えます。

    DisposableBeanを破壊することを検討します。

    私はこの修正をSpring Integration Java DSLに追加しています。 Spring Integration 4.3.9の直後に、次の1.2.2をリリースします。

    春の統合5.0は明日リリースのM3の修正を予定しています。

    関連する問題