검색

6.6. camel-sql

download PDF

SQL 구성 요소를 사용하면 JDBC 쿼리를 사용하여 데이터베이스를 사용할 수 있습니다. 이 구성 요소와 JDBC 구성 요소의 차이점은 SQL의 경우 쿼리는 끝점의 속성이며 쿼리에 전달된 매개 변수로 메시지 페이로드를 사용한다는 것입니다.

CamelContext camelctx = new DefaultCamelContext();
camelctx.addRoutes(new RouteBuilder() {
    @Override
    public void configure() throws Exception {
        from("sql:select name from information_schema.users?dataSource=java:jboss/datasources/ExampleDS")
        .to("direct:end");
    }
});
참고

위에 표시된 JNDI 데이터 소스 조회는 DefaultCamelContext 를 구성하는 경우에만 작동합니다. 아래 CdiCamelContextSpringCamelContext 예제를 참조하십시오.

camel-cdi 구성 요소와 함께 사용하면 Java EE 주석을 사용하면 Camel에서 데이터 소스를 사용할 수 있습니다. 이 예에서는 Camel이 원하는 데이터 소스를 검색할 수 있도록 @Named 주석을 사용합니다.

public class DatasourceProducer {
    @Resource(name = "java:jboss/datasources/ExampleDS")
    DataSource dataSource;

    @Produces
    @Named("wildFlyExampleDS")
    public DataSource getDataSource() {
        return dataSource;
    }
}

이제 camel-sql 엔드포인트 구성의 dataSource 매개변수를 통해 데이터 소스를 참조할 수 있습니다.

@ApplicationScoped
@ContextName("camel-sql-cdi-context")
@Startup
public class CdiRouteBuilder extends RouteBuilder {
    @Override
    public void configure() throws Exception {
        from("sql:select name from information_schema.users?dataSource=wildFlyExampleDS")
        .to("direct:end");
    }
}

camel-spring 을 사용할 때 경로 구성은 다음과 같습니다.

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xmlns:jee="http://www.springframework.org/schema/jee"
       xsi:schemaLocation="
       http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
       http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
       http://www.springframework.org/schema/jee http://www.springframework.org/schema/jee/spring-jee.xsd">

    <jee:jndi-lookup id="wildFlyExampleDS" jndi-name="java:jboss/datasources/ExampleDS"/>

    <camelContext id="sql-spring-context" xmlns="http://camel.apache.org/schema/spring">
        <route>
            <from uri="sql:select name from information_schema.users?dataSource=#wildFlyExampleDS" />
            <to uri="direct:end" />
        </route>
    </camelContext>

</beans>

6.6.1. Spring JDBC XML 네임스페이스 지원

다음 Spring JDBC XML 구성 지원이 지원됩니다.

jdbc:embedded-database

<jdbc:embedded-database id="datasource" type="H2">
  <jdbc:script location="db-schema.sql"/>
</jdbc:embedded-database>
참고

JBoss EAP는 이에 대한 기본 지원이 있으므로 H2 데이터베이스만 기본적으로 지원됩니다. 다른 포함된 데이터베이스 공급자를 사용하려면 적절한 데이터베이스 드라이버를 설치해야 합니다.

jdbc:initialize-database

<jdbc:initialize-database data-source="datasource">
  <jdbc:script location="classpath:db-init.sql"/>
</jdbc:initialize-database>
Red Hat logoGithubRedditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

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

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

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

Red Hat 소개

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

© 2024 Red Hat, Inc.