2017-11-24 6 views
0

のいずれかにエラーが発生したときにエラーチャンネルを呼び出す:移動し、任意の例外は、「firstChannel」の流れにスローされる2以下のいずれかが起こっている場合は、受信者リスト - ルータ

  1. 無視して-send-failures = "true"プロパティの場合、 "secondChannel"は が呼び出され、 "myErrorChannel"は呼び出されません。
  2. ignore-send-failures = "true"プロパティがない場合、 "secondChannel"は呼び出されず、 "myErrorChannel"が呼び出されます。

「firstChannel」フローで例外がスローされた場合、「secondChannel」と「myErrorChannel」の両方を呼び出す方法を教えてください。 設定の詳細は、以下を参照してください:下流の流れは、フローの最初のコンポーネントのために、単一のブラックボックス呼び出しのようですので

<int:channel id="myErrorChannel" datatype="java.lang.Throwable"/> 
    <int:service-activator input-channel="myErrorChannel" > 
     <beans:bean class="org.springframework.integration.samples.jms.ErrorServiceActivatorProxy"></beans:bean> 
    </int:service-activator> 

<jms:message-driven-channel-adapter id="jmsIn" channel="jmsInChannel" destination="requestQueue" error-channel="myErrorChannel"/> 

<int:channel id="firstChannel" /> 
<int:channel id="secondChannel" /> 

<int:recipient-list-router id="recipientListRouter" input-channel="jmsInChannel" ignore-send-failures="true"> 
    <int:recipient channel="firstChannel"/> 
    <int:recipient channel="secondChannel"/> 
</int:recipient-list-router> 

<int:channel id="firstChannelOutboundChannel"/> 
<int:transformer input-channel="firstChannel" output-channel="firstChannelOutboundChannel"> 
    <beans:bean class="org.springframework.integration.samples.jms.FileIOTransformer"></beans:bean> 
</int:transformer> 

<jms:outbound-channel-adapter 
     id="firstChannelOutbound" 
     channel="firstChannelOutboundChannel" 
     connection-factory="jmsConnectionFactory" 
     destination="outputQueueOne" 
     auto-startup="true" /> 

<jms:outbound-channel-adapter 
     id="secondChannelOutbound" 
     channel="secondChannel" 
     connection-factory="jmsConnectionFactory" 
     destination="outputQueueTwo" 
     auto-startup="true"/> 

答えて

0

それはそのように動作します。そこからメッセージを1つ送信することで、そこに1つの例外をキャッチして実行を停止することができます。

しかし、try-catchメカニズムを有罪なコードに近づけることができます。最初の受信者に問題があるので、そこでエラーを処理して例外を飲み込む必要があります。この方法では、受信者リストルータは最初の受信者のエラーを知らず、2番目の受信者を呼び出します。

FileIOTransformerにtry-catchを追加する最も簡単な方法です。ただしとtrapExceptionを使用すると、https://docs.spring.io/spring-integration/docs/4.3.12.RELEASE/reference/html/messaging-endpoints-chapter.html#expression-adviceを使用できます。ただし、この種のアドバイスは現在のコンポーネントに直接適用されるだけであることに注意する必要があります。下流の例外を捕捉しません。

もう1つのトリックは、try-catchでChannelInterceptorを実装し、firstChannelに追加することです。

+0

お寄せいただきありがとうございます! –

関連する問題