26.5. 샘플
JMS는 다른 구성 요소에도 많은 예에서 사용됩니다. 그러나 시작하기 위해 아래에서 몇 가지 샘플을 제공합니다.
26.5.1. JMS에서 수신 링크 복사링크가 클립보드에 복사되었습니다!
다음 샘플에서는 JMS 메시지를 수신하고 메시지를 10.0.0.1으로 라우팅하는 경로를 구성합니다.
from("jms:queue:foo"). to("bean:myBusinessLogic");
from("jms:queue:foo").
to("bean:myBusinessLogic");
물론 EIP 패턴 중 하나를 사용할 수 있으므로 경로가 컨텍스트를 기반으로 할 수 있습니다. 예를 들어, 다음은 큰 소비자를 위한 주문 주제를 필터링하는 방법입니다.
from("jms:topic:OrdersTopic"). filter().method("myBean", "isGoldCustomer"). to("jms:queue:BigSpendersQueue");
from("jms:topic:OrdersTopic").
filter().method("myBean", "isGoldCustomer").
to("jms:queue:BigSpendersQueue");
26.5.2. JMS로 전송 링크 복사링크가 클립보드에 복사되었습니다!
아래 샘플에서 파일 폴더를 폴링하고 파일 콘텐츠를 JMS 주제로 보냅니다. 파일 내용을 10.0.0.1sMessage 대신 textMessage로 원하는 경우 본문을 String으로 변환해야 합니다.As we want the content of the file as a text
, we need to convert the body to a Message
instead of a 10.0.0.1sMessageString
:
from("file://orders"). convertBodyTo(String.class). to("jms:topic:OrdersTopic");
from("file://orders").
convertBodyTo(String.class).
to("jms:topic:OrdersTopic");
26.5.3. 주석 사용 링크 복사링크가 클립보드에 복사되었습니다!
Camel에는 주석도 있으므로 CloudEvent Consuming 및ECDHE Producing을 사용할 수 있습니다.
26.5.4. Spring DSL 샘플 링크 복사링크가 클립보드에 복사되었습니다!
이전 예에서는 Java DSL을 사용합니다. Camel은 Spring XML DSL도 지원합니다. 다음은 Spring DSL을 사용하는 큰 용도 샘플입니다.
26.5.5. 기타 샘플 링크 복사링크가 클립보드에 복사되었습니다!
JMS는 이 Camel 설명서의 다른 구성 요소 및 EIP 패턴에 대한 많은 예에서 나타납니다. 문서를 자유롭게 검색할 수 있습니다.
26.5.6. JMS를 Dead Letter Queue로 사용 링크 복사링크가 클립보드에 복사되었습니다!
일반적으로 JMS 를 전송으로 사용하면 페이로드로 본문과 헤더만 전송됩니다. Dead Letter Channel 과 함께 JMS 대기열을 사용하려는 경우 JMS 대기열을 Dead Letter Queue로 사용하여 생성된 Exception은 JMS 메시지에 저장되지 않습니다. 그러나 JMS dead letter 큐에서 transferExchange
옵션을 사용하여 Camel에 org.apache.camel.support.DefaultExchangeHolder
가 있는 javax.jms.ObjectMessage
로 전체 교환을 저장하도록 지시할 수 있습니다. 이를 통해 Dead Letter Queue에서 소비하고 Exchange.EXCEPTION_CAUGHT
키를 사용하여 Exchange 속성에서 발생한 예외를 검색할 수 있습니다. 아래 데모에서는 이를 보여줍니다.
// setup error handler to use JMS as queue and store the entire Exchange errorHandler(deadLetterChannel("jms:queue:dead?transferExchange=true"));
// setup error handler to use JMS as queue and store the entire Exchange
errorHandler(deadLetterChannel("jms:queue:dead?transferExchange=true"));
그런 다음 JMS 큐에서 사용하고 문제를 분석할 수 있습니다.
26.5.7. JMS를 Dead Letter Channel로 사용하여 오류를 저장 링크 복사링크가 클립보드에 복사되었습니다!
JMS를 사용하여 원인 오류 메시지를 저장하거나 사용자 지정 본문을 저장하여 초기화할 수 있습니다. 다음 예제에서는 MessageECDHE EIP를 사용하여 JMS dead letter 큐로 이동하기 전에 실패한 교환에 대해 변환을 수행합니다.
// we sent it to a seda dead queue first errorHandler(deadLetterChannel("seda:dead")); // and on the seda dead queue we can do the custom transformation before its sent to the JMS queue from("seda:dead").transform(exceptionMessage()).to("jms:queue:dead");
// we sent it to a seda dead queue first
errorHandler(deadLetterChannel("seda:dead"));
// and on the seda dead queue we can do the custom transformation before its sent to the JMS queue
from("seda:dead").transform(exceptionMessage()).to("jms:queue:dead");
여기서는 원본 원인 오류 메시지만 변환에 저장합니다. 그러나 모든 표현식을 사용하여 원하는 내용을 보낼 수 있습니다. 예를 들어 CloudEvent에서 메서드를 호출하거나 사용자 지정 프로세서를 사용할 수 있습니다.