325.12. 동적 값이 있는 IN 쿼리 사용

Camel 2.17로 사용 가능

Camel 2.17 이후 SQL 생산자는 IN 값이 동적인 IN 문과 함께 SQL 쿼리를 사용할 수 있습니다. 예를 들면, 메시지 본문 또는 헤더 등에서 For example from the message body or a header etc

IN을 사용하려면 다음이 필요합니다.

  • 다음과 같이 매개변수 이름 앞에 다음과 같이 지정합니다.
  • 매개 변수 추가 (Add ) around the parameter

예를 들어 예제에서는 이를 더 잘 설명합니다. 다음 쿼리가 사용됩니다.The following query is used:

-- this is a comment
select *
from projects
where project in (:#in:names)
order by id

다음 경로에서:

from("direct:query")
    .to("sql:classpath:sql/selectProjectsIn.sql")
    .to("log:query")
    .to("mock:query");

그런 다음 IN 쿼리는 다음과 같은 동적 값이 있는 키 이름과 함께 헤더를 사용할 수 있습니다.

// use an array
template.requestBodyAndHeader("direct:query", "Hi there!", "names", new String[]{"Camel", "AMQ"});

// use a list
List<String> names = new ArrayList<String>();
names.add("Camel");
names.add("AMQ");

template.requestBodyAndHeader("direct:query", "Hi there!", "names", names);

// use a string separated values with comma
template.requestBodyAndHeader("direct:query", "Hi there!", "names", "Camel,AMQ");

외부화가 아닌 끝점에서 쿼리를 지정할 수도 있습니다(외부화는 SQL 쿼리를 유지 관리하도록 함)

from("direct:query")
    .to("sql:select * from projects where project in (:#in:names) order by id")
    .to("log:query")
    .to("mock:query");