26.5. 샘플


JMS는 다른 구성 요소에도 많은 예에서 사용됩니다. 그러나 시작하기 위해 아래에서 몇 가지 샘플을 제공합니다.

26.5.1. JMS에서 수신

다음 샘플에서는 JMS 메시지를 수신하고 메시지를 10.0.0.1으로 라우팅하는 경로를 구성합니다.

from("jms:queue:foo").
   to("bean:myBusinessLogic");
Copy to Clipboard Toggle word wrap

물론 EIP 패턴 중 하나를 사용할 수 있으므로 경로가 컨텍스트를 기반으로 할 수 있습니다. 예를 들어, 다음은 큰 소비자를 위한 주문 주제를 필터링하는 방법입니다.

from("jms:topic:OrdersTopic").
  filter().method("myBean", "isGoldCustomer").
  to("jms:queue:BigSpendersQueue");
Copy to Clipboard Toggle word wrap

26.5.2. JMS로 전송

아래 샘플에서 파일 폴더를 폴링하고 파일 콘텐츠를 JMS 주제로 보냅니다. 파일 내용을 10.0.0.1sMessage 대신 textMessage로 원하는 경우 본문을 String으로 변환해야 합니다.As we want the content of the file as a text Message instead of a 10.0.0.1sMessage, we need to convert the body to a String:

from("file://orders").
  convertBodyTo(String.class).
  to("jms:topic:OrdersTopic");
Copy to Clipboard Toggle word wrap

26.5.3. 주석 사용

Camel에는 주석도 있으므로 CloudEvent Consuming 및ECDHE Producing을 사용할 수 있습니다.

26.5.4. Spring DSL 샘플

이전 예에서는 Java DSL을 사용합니다. Camel은 Spring XML DSL도 지원합니다. 다음은 Spring DSL을 사용하는 큰 용도 샘플입니다.

<route>
  <from uri="jms:topic:OrdersTopic"/>
  <filter>
    <method ref="myBean" method="isGoldCustomer"/>
    <to uri="jms:queue:BigSpendersQueue"/>
  </filter>
</route>
Copy to Clipboard Toggle word wrap

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"));
Copy to Clipboard Toggle word wrap

그런 다음 JMS 큐에서 사용하고 문제를 분석할 수 있습니다.

from("jms:queue:dead").to("bean:myErrorAnalyzer");

// and in our bean
String body = exchange.getIn().getBody();
Exception cause = exchange.getProperty(Exchange.EXCEPTION_CAUGHT, Exception.class);
// the cause message is
String problem = cause.getMessage();
Copy to Clipboard Toggle word wrap

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");
Copy to Clipboard Toggle word wrap

여기서는 원본 원인 오류 메시지만 변환에 저장합니다. 그러나 모든 표현식을 사용하여 원하는 내용을 보낼 수 있습니다. 예를 들어 CloudEvent에서 메서드를 호출하거나 사용자 지정 프로세서를 사용할 수 있습니다.

맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

Red Hat을 사용하는 고객은 신뢰할 수 있는 콘텐츠가 포함된 제품과 서비스를 통해 혁신하고 목표를 달성할 수 있습니다. 최신 업데이트를 확인하세요.

보다 포괄적 수용을 위한 오픈 소스 용어 교체

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 언어를 교체하기 위해 최선을 다하고 있습니다. 자세한 내용은 다음을 참조하세요.Red Hat 블로그.

Red Hat 소개

Red Hat은 기업이 핵심 데이터 센터에서 네트워크 에지에 이르기까지 플랫폼과 환경 전반에서 더 쉽게 작업할 수 있도록 강화된 솔루션을 제공합니다.

Theme

© 2025 Red Hat