paulwong

          在SPRING INTEGRATION中手動開始和停止JMS LISTENER

          如果要對JMS BROKER生產和消費MESSAGE,一種方式是用JmsTemplate發送和消費消息,另一種方式是SPRING INTEGRATION。

          SPRING INTEGRATION是實現了EIP模式的一種框架,即使用CHANNEL和JMS-INBOUND-ADAPTER、JMS-OUTBOUND-ADAPTER,完全脫離了JmsTemplate的API。

          如果需要實現這種場景:從BROKER取一條消息,處理消息,且處理途中不要再從BROKER再取消息,處理完后再取消息,再處理。

          這樣要求手動開始和停止JMS LISTENER,即手動開始和停止JMS-INBOUND-ADAPTER、JMS-OUTBOUND-ADAPTER。

          @Bean
          @InboundChannelAdapter(value = "loaderResponseChannel")
          public MessageSource loaderResponseSource() throws Exception {
              return Jms
                      .inboundAdapter(oracleConnectionFactory())
                      .configureJmsTemplate(
                              t -> t.deliveryPersistent(true)
                                      .jmsMessageConverter(jacksonJmsMessageConverter())
                      ).destination(jmsInbound).get();
          }

          當使用@InboundChannelAdapter時,會自動注冊一個SourcePollingChannelAdapter ,但這個名字比較長:configrationName.loaderResponseSource.inboundChannelAdapter。

          呼叫這個實例的start()和stop()方法即可。

          @Bean
          public IntegrationFlow controlBusFlow() {
              return IntegrationFlows.from("controlBus")
                        .controlBus()
                        .get();
          }

          Message operation = MessageBuilder.withPayload("@configrationName.loaderResponseSource.inboundChannelAdapter.start()").build();
          operationChannel.send(operation)

          https://stackoverflow.com/questions/45632469/shutdown-spring-integration-with-jms-inboundadapter

          https://docs.spring.io/spring-integration/docs/5.0.7.RELEASE/reference/html/system-management-chapter.html#control-bus

          https://github.com/spring-projects/spring-integration-java-dsl/blob/master/src/test/java/org/springframework/integration/dsl/test/jms/JmsTests.java

          https://stackoverflow.com/questions/50428552/how-to-stop-or-suspend-polling-after-batch-job-fail

          posted on 2019-10-09 17:16 paulwong 閱讀(617) 評論(0)  編輯  收藏 所屬分類: SPRING INTERGRATION

          主站蜘蛛池模板: 伊宁市| 远安县| 犍为县| 铜川市| 白玉县| 翼城县| 荥经县| 宣化县| 石台县| 大方县| 成安县| 徐州市| 稷山县| 沭阳县| 北安市| 崇明县| 琼中| 福贡县| 上饶市| 乐平市| 五台县| 林芝县| 青川县| 青浦区| 加查县| 苏尼特右旗| 海门市| 临武县| 汤原县| 濮阳县| 开平市| 苍南县| 鹤壁市| 昭苏县| 隆尧县| 芦溪县| 固镇县| 德化县| 永春县| 从化市| 嘉禾县|