272.6. Camel로 데이터 전송

외부 라이브러리에서 Camel 경로로 이벤트를 푸시해야 하는 경우 Reactive Streams 끝점을 소비자로 설정해야 합니다.

from("reactive-streams:elements")
.to("log:INFO");

요소 스트림의 핸들은 CamelReactiveStreams 유틸리티 클래스에서 얻을 수 있습니다.

CamelReactiveStreamsService camel = CamelReactiveStreams.get(context);

Subscriber<String> elements = camel.streamSubscriber("elements", String.class);

구독자는 요소 스트림에서 사용하는 Camel 경로로 이벤트를 푸시하는 데 사용할 수 있습니다.

다음은 RxJava 2 와 함께 사용하는 방법의 예입니다(예: 이벤트를 게시하는 데 모든 반응 프레임워크를 사용할 수 있음).

Flowable.interval(1, TimeUnit.SECONDS)
    .map(i -> "Item " + i)
    .subscribe(elements);

문자열 항목은 예제의 RxJava에 의해 1초마다 생성되며 위에 정의된 Camel 경로로 푸시됩니다.

272.6.1. 직접 API를 사용하여 Camel에 데이터 전송

또한 이 경우 직접 API를 사용하여 엔드포인트 URI에서 Camel 구독자를 얻을 수 있습니다.

CamelReactiveStreamsService camel = CamelReactiveStreams.get(context);

// Send two strings to the "seda:queue" endpoint
Flowable.just("hello", "world")
    .subscribe(camel.subscriber("seda:queue", String.class));