본문 바로가기
  • 오늘도 한걸음. 수고많았어요.^^
  • 조금씩 꾸준히 오래 가자.ㅎ
IT기술/개발툴

[Camel] THROTTLE 사용하기

by 미노드 2023. 7. 4.

camel에선 throttle이라는 옵션을 제공한다.

유량제어를 위해 사용하는 옵션인데, 유량제어가 없다면,
endpoint, 즉 받는 곳에서 처리량 이상으로 입력을 받아 부하가 걸리는 경우가 있다.
endpoint측에서 받을 수 있는 스펙에 한계가 있기 때문에, 보내는 측에서 유량 제어를 걸어
전송되는 속도를 조절하는 것이다.

이를 throttle 이라는 옵션으로 쉽게 제공한다.

1. 10초에 3개 메시지로 전송

from("seda:a")
  .throttle(3).timePeriodMillis(10000)
  .to("mock:result");
<route>
  <from uri="seda:a"/>
  <throttle timePeriodMillis="10000">
    <constant>3</constant>
  </throttle>
  <to uri="mock:result"/>
</route>

2. 1초(기본값)에 50개 메시지로 전송

from("seda:a")
  .throttle(50)
  .to("seda:b");
<route>
  <from uri="seda:a"/>
  <throttle>
    <constant>50</constant>
  </throttle>
  <to uri="mock:result"/>
</route>

3. 정해진 값 이상 들어오면 에러로 처리하기

정해진 값 이상 들어올 경우 유량제어를 하게 되는데, 굳이 에러로 처리해서 뭔가 결과를 만들고 싶을 경우
사용할 수 있다.
ThrottlerRejectedExecutionException 으로 에러가 남게 된다고 함

from("seda:a")
  .throttle(100).rejectExecution(true)
  .to("seda:b");
<route>
  <from uri="seda:a"/>
  <throttle timePeriodMillis="100" rejectExecution="true">
    <constant>100</constant>
  </throttle>
  <to uri="seda:b"/>
</route>

그 외에 throttle 관련 요소는 여기를 참조해서 사용할 수 있다.

https://camel.apache.org/components/2.x/index.html

 

Home

Supports over 50 Data Formats Camel supports around 50 data formats, allowing to translate messages in multiple formats, and with support from industry standard formats from finance, telco, health-care, and more. See Supported Formats

camel.apache.org