Camel Extensions for Quarkus를 사용하여 애플리케이션 개발


Red Hat Integration 2023.q2

Camel Extensions for Quarkus를 사용하여 애플리케이션 개발

Integration Documentation Team Integration Support Team http://access.redhat.com/support

초록

이 안내서는 Camel Extensions for Quarkus에서 Camel 애플리케이션을 작성하는 개발자를 위한 것입니다.

머리말

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

Red Hat은 코드, 문서, 웹 속성에서 문제가 있는 용어를 교체하기 위해 최선을 다하고 있습니다. 먼저 마스터(master), 슬레이브(slave), 블랙리스트(blacklist), 화이트리스트(whitelist) 등 네 가지 용어를 교체하고 있습니다. 이러한 변경 작업은 작업 범위가 크므로 향후 여러 릴리스에 걸쳐 점차 구현할 예정입니다. 자세한 내용은 CTO Chris Wright의 메시지를 참조하십시오.

1장. Camel Extensions for Quarkus를 사용하여 애플리케이션 개발 소개

이 안내서는 Camel Extensions for Quarkus에서 Camel 애플리케이션을 작성하는 개발자를 위한 것입니다.

Camel Extensions for Quarkus에서 지원되는 Camel 구성 요소에는 Camel Extensions for Quarkus 확장 기능이 연결되어 있습니다. 이 배포에서 지원되는 Camel Extensions for Quarkus 확장에 대한 자세한 내용은 Camel Extensions for Quarkus 참조 가이드를 참조하십시오.

2장. 종속성 관리

2.1. 새 프로젝트를 시작하기 위한 Quarkus 툴링

특정 Camel Extensions for Quarkus 릴리스는 특정 Quarkus 릴리스에서만 작동해야 합니다.

새 프로젝트에서 종속성 버전을 바로 얻는 가장 쉽고 간단한 방법은 Quarkus 툴 중 하나를 사용하는 것입니다.

이러한 도구를 사용하면 확장을 선택하고 새 Maven 프로젝트를 스캐폴드할 수 있습니다.

생성된 pom.xml 은 다음과 유사합니다.

<project>
  ...
  <properties>
    <quarkus.platform.artifact-id>quarkus-bom</quarkus.platform.artifact-id>
    <quarkus.platform.group-id>com.redhat.quarkus.platform</quarkus.platform.group-id>
    <quarkus.platform.version>
        <!-- The latest 2.13.x version from https://maven.repository.redhat.com/ga/com/redhat/quarkus/platform/quarkus-bom -->
    </quarkus.platform.version>
    ...
  </properties>
  <dependencyManagement>
    <dependencies>
      <!-- The BOMs managing the dependency versions -->
      <dependency>
        <groupId>${quarkus.platform.group-id}</groupId>
        <artifactId>quarkus-bom</artifactId>
        <version>${quarkus.platform.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
      <dependency>
        <groupId>${quarkus.platform.group-id}</groupId>
        <artifactId>quarkus-camel-bom</artifactId>
        <version>${quarkus.platform.version}</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>

  <dependencies>
    <!-- The extensions you chose in the project generator tool -->
    <dependency>
      <groupId>org.apache.camel.quarkus</groupId>
      <artifactId>camel-quarkus-sql</artifactId>
      <!-- No explicit version required here and below -->
    </dependency>
    ...
  </dependencies>
  ...
</project>
Copy to Clipboard Toggle word wrap
작은 정보

사용 가능한 확장은 Quarkus Core, Camel Quarkus 및 Hazelcast, Kogito 및 OptaPlanner와 같은 다른 여러 타사 참여 프로젝트에 걸쳐 있습니다.

BOM은 "Bill of materialss"를 의미합니다 - 주요 목적은 아티팩트 버전을 관리하여 프로젝트의 BOM을 가져오는 최종 사용자가 함께 작동해야 하는 특정 버전을 주의할 필요가 없도록 하는 pom.xml 입니다. 즉, pom.xml 의 < depependencyManagement > 섹션에 가져온 BOM을 사용하면 지정된 BOM에서 관리하는 종속 항목에 대한 버전을 지정하지 않도록 할 수 있습니다.

pom.xml 에 포함된 특정 BOM은 최소한의 일관된 BOM 세트를 선택하도록 구성된 생성기 도구를 사용하여 선택하는 확장 기능에 따라 달라집니다.

pom.xml 파일의 BOM에서 관리하지 않는 나중에 확장을 추가하도록 선택하는 경우 적절한 BOM을 수동으로 검색할 필요가 없습니다. quarkus-maven-plugin 을 사용하면 확장을 선택할 수 있으며 도구는 필요에 따라 적절한 BOM을 추가합니다. quarkus-maven-plugin 을 사용하여 BOM 버전을 업그레이드할 수도 있습니다.

com.redhat.quarkus.platform BOMs는 서로 일치하므로 아티팩트가 둘 이상의 BOM에서 관리되는 경우 항상 동일한 버전으로 관리됩니다. 이는 애플리케이션 개발자가 다양한 독립 프로젝트에서 제공될 수 있는 개별 아티팩트의 호환성을 주의할 필요가 없다는 장점이 있습니다.

3장. Camel 경로 정의

Camel Extensions for Quarkus는 Java DSL 언어를 지원하여 Camel 경로를 정의합니다.

3.1. Java DSL

org.apache.camel.builder.RouteBuilder 확장 및 사용 가능한 fluent builder 메서드를 사용하는 것이 Camel 경로를 정의하는 가장 일반적인 방법입니다. 다음은 타이머 구성 요소를 사용하는 경로의 간단한 예입니다.

import org.apache.camel.builder.RouteBuilder;

public class TimerRoute extends RouteBuilder {

    @Override
    public void configure() throws Exception {
        from("timer:foo?period=1000")
                .log("Hello World");
    }
}
Copy to Clipboard Toggle word wrap

3.1.1. 끝점 DSL

Camel 3.0부터 fluent builders를 사용하여 Camel 엔드포인트를 정의할 수도 있습니다. 다음 예제는 이전 예제와 동일합니다.

import org.apache.camel.builder.RouteBuilder;
import static org.apache.camel.builder.endpoint.StaticEndpointBuilders.timer;

public class TimerRoute extends RouteBuilder {

    @Override
    public void configure() throws Exception {
        from(timer("foo").period(1000))
                .log("Hello World");
    }
}
Copy to Clipboard Toggle word wrap
참고

모든 Camel 구성 요소에 대한 빌더 방법은 camel-quarkus-core 를 통해 사용할 수 있지만 경로가 제대로 작동하려면 지정된 구성 요소의 확장을 추가해야 합니다. 위 예제의 경우 camel-quarkus-timer 입니다.

4장. 설정

Camel Quarkus는 Quarkus 애플리케이션 라이프사이클에 따라 기본적으로 시작/중지되는 Camel 컨텍스트 빈을 자동으로 구성하고 배포합니다. 구성 단계는 Quarkus의 보강 단계에서 빌드 시 수행되며 Camel Quarkus 특정 quarkus.camel.* 속성을 사용하여 조정할 수 있는 Camel Quarkus 확장에 의해 구동됩니다.

참고

Quarkus.camel.* 구성 속성은 개별 확장 페이지에 문서화되어 있습니다. 예를 들면 Camel Quarkus Core 를 참조하십시오.

구성이 완료되면 RUNTIME_INIT 단계에서 최소한의 Camel 런타임이 어셈블되어 시작됩니다.

4.1. Camel 구성 요소 구성

4.1.1. application.properties

속성을 통해 Apache Camel의 구성 요소 및 기타 측면을 구성하려면 애플리케이션이 camel-quarkus-core 직접 또는 전송에 따라 달라지도록 합니다. 대부분의 Camel Quarkus 확장은 camel-quarkus-core 에 따라 다르기 때문에 일반적으로 명시적으로 추가할 필요가 없습니다.

Camel-quarkus-core 는 Camel Main에서 Camel Quarkus까지 기능을 제공합니다.

아래 예제에서는 LogComponent 에서 application.properties 를 통해 특정 ExchangeFormatter 구성을 설정합니다.

camel.component.log.exchange-formatter = #class:org.apache.camel.support.processor.DefaultExchangeFormatter
camel.component.log.exchange-formatter.show-exchange-pattern = false
camel.component.log.exchange-formatter.show-body-type = false
Copy to Clipboard Toggle word wrap

4.1.2. CDI

CDI를 사용하여 프로그래밍 방식으로 구성 요소를 구성할 수도 있습니다.

권장되는 방법은 ComponentAddEvent 를 관찰하고 경로 및 CamelContext 가 시작되기 전에 구성 요소를 구성하는 것입니다.

import javax.enterprise.context.ApplicationScoped;
import javax.enterprise.event.Observes;
import org.apache.camel.quarkus.core.events.ComponentAddEvent;
import org.apache.camel.component.log.LogComponent;
import org.apache.camel.support.processor.DefaultExchangeFormatter;

@ApplicationScoped
public static class EventHandler {
    public void onComponentAdd(@Observes ComponentAddEvent event) {
        if (event.getComponent() instanceof LogComponent) {
            /* Perform some custom configuration of the component */
            LogComponent logComponent = ((LogComponent) event.getComponent());
            DefaultExchangeFormatter formatter = new DefaultExchangeFormatter();
            formatter.setShowExchangePattern(false);
            formatter.setShowBodyType(false);
            logComponent.setExchangeFormatter(formatter);
        }
    }
}
Copy to Clipboard Toggle word wrap
4.1.2.1. @Named 구성 요소 인스턴스 생성

또는 @Named 생산자 메서드에서 직접 구성 요소를 만들고 구성할 수 있습니다. Camel은 구성 요소 URI 스키마를 사용하여 레지스트리에서 구성 요소를 조회하는 방식으로 작동합니다. 예를 들어 LogComponent Camel의 경우 console이라는 로그를 찾습니다.

주의

@Named 구성 요소를 생성하는 동안 일반적으로 작동하지만 일부 구성 요소에는 미묘한 문제가 발생할 수 있습니다.

Camel Quarkus 확장에서는 다음 중 하나를 수행할 수 있습니다.

  • 기본 Camel 구성 요소 유형의 사용자 지정 하위 유형을 전달합니다. Vert.x WebSocket 확장 예제를 참조하십시오.
  • 구성 요소의 일부 Quarkus별 사용자 지정을 수행합니다. JPA 확장 예제를 참조하십시오.

이러한 작업은 자체 구성 요소 인스턴스를 생성할 때 수행되지 않으므로 관찰자 방법에서 구성 요소를 구성하는 것이 권장되는 방법입니다.

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;

import org.apache.camel.component.log.LogComponent;
import org.apache.camel.support.processor.DefaultExchangeFormatter;

@ApplicationScoped
public class Configurations {
    /**
     * Produces a {@link LogComponent} instance with a custom exchange formatter set-up.
     */
    @Named("log") 
1

    LogComponent log() {
        DefaultExchangeFormatter formatter = new DefaultExchangeFormatter();
        formatter.setShowExchangePattern(false);
        formatter.setShowBodyType(false);

        LogComponent component = new LogComponent();
        component.setExchangeFormatter(formatter);

        return component;
    }
}
Copy to Clipboard Toggle word wrap
1
메서드 이름이 동일한 경우 @Named 주석의 "log" 인수를 생략할 수 있습니다.

4.2. 규칙별 구성

속성을 통한 Camel 구성을 지원할 뿐만 아니라 camel-quarkus-core 를 사용하면 Camel 동작을 구성하는 규칙을 사용할 수 있습니다. 예를 들어 CDI 컨테이너에 단일 ExchangeFormatter 인스턴스가 있는 경우 해당 빈을 LogComponent 에 자동으로 연결합니다.

5장. Camel Quarkus의 CDI(Context and DependencyECDHE)

CDI는 Quarkus 및 Camel Quarkus에서 핵심적인 역할을 수행하며 이를 위한 첫 번째 클래스 지원도 제공합니다.

예를 들어 Camel RouteBuilder 에 빈 및 구성 값을 삽입하기 위해 @Inject,@ConfigProperty 및 유사한 주석을 사용할 수 있습니다. 예를 들면 다음과 같습니다.

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import org.apache.camel.builder.RouteBuilder;
import org.eclipse.microprofile.config.inject.ConfigProperty;

@ApplicationScoped 
1

public class TimerRoute extends RouteBuilder {

    @ConfigProperty(name = "timer.period", defaultValue = "1000") 
2

    String period;

    @Inject
    Counter counter;

    @Override
    public void configure() throws Exception {
        fromF("timer:foo?period=%s", period)
                .setBody(exchange -> "Incremented the counter: " + counter.increment())
                .to("log:cdi-example?showExchangePattern=false&showBodyType=false");
    }
}
Copy to Clipboard Toggle word wrap
1
@ApplicationScoped 주석은 @Inject@ConfigPropertyRouteBuilder 에서 작동하는 데 필요합니다. @ApplicationScoped 빈은 CDI 컨테이너에서 관리하며 해당 라이프사이클은 일반 RouteBuilder 중 하나보다 약간 더 복잡합니다. 즉, RouteBuilder 에서 @ApplicationScoped 를 사용하면 부팅 시간 페널티가 있으므로 실제로 필요할 때 @ApplicationScopedRouteBuilder 에 주석을 달 수 있습니다.
2
timer.period 속성의 값은 예제 프로젝트의 gRPC /main/resources/application.properties 에 정의됩니다.
작은 정보

자세한 내용은 QuarkusDependencyECDHE 가이드를 참조하십시오.

5.1. CamelContext액세스

CamelContext 에 액세스하려면 다음 명령을 실행하여 console에 삽입합니다.

import javax.inject.Inject;
import javax.enterprise.context.ApplicationScoped;
import java.util.stream.Collectors;
import java.util.List;
import org.apache.camel.CamelContext;

@ApplicationScoped
public class MyBean {

    @Inject
    CamelContext context;

    public List<String> listRouteIds() {
        return context.getRoutes().stream().map(Route::getId).sorted().collect(Collectors.toList());
    }
}
Copy to Clipboard Toggle word wrap

5.2. CDI 및 Camel iPXE 구성 요소

5.2.1. 이름별 console 참조

이름으로 경로 정의의 빈을 참조하려면 @Named("myNamedBean")@ApplicationScoped 로 빈에 주석을 답니다. 기본 모드에서는 @RegisterForReflection 주석이 중요합니다.

import javax.enterprise.context.ApplicationScoped;
import javax.inject.Named;
import io.quarkus.runtime.annotations.RegisterForReflection;

@ApplicationScoped
@Named("myNamedBean")
@RegisterForReflection
public class NamedBean {
    public String hello(String name) {
        return "Hello " + name + " from the NamedBean";
    }
}
Copy to Clipboard Toggle word wrap

그런 다음 경로 정의에 myNamedBean 이름을 사용할 수 있습니다.

import org.apache.camel.builder.RouteBuilder;
public class CamelRoute extends RouteBuilder {
    @Override
    public void configure() {
        from("direct:named")
                .to("bean:namedBean?method=hello");
    }
}
Copy to Clipboard Toggle word wrap

6장. 가시성

6.1. 건강 및 활성 상태 점검

상태 및 활성 검사는 MicroProfile Health 확장을 통해 지원됩니다.

Camel Health API 또는 Quarkus MicroProfile Health를 통해 구성할 수 있습니다.

구성된 모든 점검은 표준 MicroProfile Health 엔드포인트 URL에서 사용할 수 있습니다.

6.2. 메트릭

메트릭 노출을 위한 MicroProfile 메트릭을 제공합니다.

일부 기본 Camel 메트릭은 기본적으로 제공되지 않으며 경로에 추가 메트릭을 구성하여 보완할 수 있습니다.

메트릭은 표준 Quarkus 지표 끝점에서 사용할 수 있습니다.

7장. 기본 모드

네이티브 모드에서 애플리케이션을 컴파일 및 테스트하는 방법에 대한 자세한 내용은 Quarkus 애플리케이션 컴파일에서 네이티브 실행 파일로 네이티브 실행 파일 제공을 참조하십시오.

7.1. 문자 인코딩

기본적으로 일부 collectd sets는 기본 모드에서 사용할 수 없습니다.

Charset.defaultCharset(), US-ASCII, ISO-8859-1, UTF-8, UTF-16BE, UTF-16LE, UTF-16
Copy to Clipboard Toggle word wrap

애플리케이션에 이 세트에 포함되어 있지 않은 인코딩이 필요하거나 기본 모드에서 UnsupportedCharsetException 이 표시되는 경우 application.properties 에 다음 항목을 추가하십시오.

quarkus.native.add-all-charsets = true
Copy to Clipboard Toggle word wrap

Quarkus 설명서에서 quarkus.native.add-all-charsets 도 참조하십시오.

7.2. 로케일

기본적으로 빌드 JVM 기본 로케일만 기본 이미지에 포함됩니다. Quarkus에서는 application.properties 를 통해 로케일을 설정하는 방법을 제공하므로 LANGLC_* environement 변수를 사용하지 않아도 됩니다.

quarkus.native.user-country=US
quarkus.native.user-language=en
Copy to Clipboard Toggle word wrap

또한 여러 로케일을 네이티브 이미지에 포함시키고 Mandrel 명령줄 옵션 -H:IncludeLocales=fr,en,H:+IncludeAllLocales-H:DefaultLocale=de 를 통해 기본 로케일을 선택할 수 있습니다. Quarkus quarkus.native.additional-build-args 속성을 통해 설정할 수 있습니다.

7.3. 네이티브 실행 파일에 리소스 포함

런타임 시 네이티브 실행 파일을 포함하여 명시적으로 나열해야 하는 클래스.getResource() , ClassLoader.getResource(), ClassLoader.getResourceAsStream() 을 통해 액세스한 리소스.

이 작업은 아래 설명과 같이 Quarkus quarkus.native.resources.includesquarkus.native.resources .excludes 속성을 사용하여 수행할 수 있습니다.

quarkus.native.resources.includes = docs/*,images/*
quarkus.native.resources.excludes = docs/ignored.adoc,images/ignored.png
Copy to Clipboard Toggle word wrap

위의 예에서 docs/included.adocimages/included.png 라는 리소스는 docs/ignored.adocimages/ignored.png 가 없는 동안 기본 실행 파일에 포함됩니다.

resources.includesresources.excludes 는 둘 다 쉼표로 구분된 10.0.0.1-path 스타일 glob 패턴 목록입니다.

자세한 내용은 Camel Extensions for Quarkus 참조 참조를 참조하십시오.

7.4. 기본 모드에서 onException 절 사용

기본 모드에서 camel onException 처리를 사용할 때 애플리케이션 개발자는 리플렉션에 대한 예외 클래스를 등록합니다.

예를 들어 아래와 같이 onException 처리가 포함된 camel 컨텍스트가 있습니다.For example, having a camel context with onException handling as below:

onException(MyException.class).handled(true);
from("direct:route-that-could-produce-my-exception").throw(MyException.class);
Copy to Clipboard Toggle word wrap

리플렉션을 위해 mypackage.MyException 클래스를 등록해야 합니다. 리플렉션 을 위한 등록 클래스의 자세한 내용을 참조하십시오.

7.5. 리플렉션에 대한 클래스 등록

기본적으로 동적 리플렉션은 기본 모드에서 사용할 수 없습니다. 반사 액세스가 필요한 클래스는 컴파일 타임에 리플렉션을 위해 등록되어야 합니다.

대부분의 경우 Quarkus 확장이 리플렉션이 필요한 클래스를 감지하고 자동으로 등록할 수 있기 때문에 애플리케이션 개발자는 주의할 필요가 없습니다.

그러나 경우에 따라 Quarkus 확장에서 일부 클래스를 누락할 수 있으며 애플리케이션 개발자가 등록할 수 있습니다. 이를 수행하는 방법에는 두 가지가 있습니다.

  1. @io.quarkus.runtime.annotations.RegisterForReflection 주석은 사용되는 클래스를 등록하거나 target 속성을 통해 타사 클래스를 등록할 수도 있습니다.
  2. application.propertiesquarkus.camel.native.reflection 옵션:

    quarkus.camel.native.reflection.include-patterns = org.apache.commons.lang3.tuple.*
    quarkus.camel.native.reflection.exclude-patterns = org.apache.commons.lang3.tuple.*Triple
    Copy to Clipboard Toggle word wrap

    이러한 옵션이 제대로 작동하려면 선택한 클래스를 포함하는 아티팩트에 Jandex 인덱스('META-INF/jandex.idx')를 포함하거나 'quarkus.index-dependency.*' 옵션을 사용하여 인덱싱해야 합니다. 예를 들어 'application.properties' -

    quarkus.index-dependency.commons-lang3.group-id = org.apache.commons
    quarkus.index-dependency.commons-lang3.artifact-id = commons-lang3
    Copy to Clipboard Toggle word wrap

7.6. 직렬화에 대한 클래스 등록

quarkus.camel.native.reflection.serialization-enabled 를 통해 직렬화 지원을 요청하는 경우 CamelSerializationProcessor.BASE_SERIALIZATION_CLASSES 에 나열된 클래스가 직렬화에 대해 자동으로 등록됩니다.

사용자는 @RegisterForReflection(serialization = true) 을 사용하여 더 많은 클래스를 등록할 수 있습니다.

법적 공지

Copyright © 2023 Red Hat, Inc.
The text of and illustrations in this document are licensed by Red Hat under a Creative Commons Attribution–Share Alike 3.0 Unported license ("CC-BY-SA"). An explanation of CC-BY-SA is available at http://creativecommons.org/licenses/by-sa/3.0/. In accordance with CC-BY-SA, if you distribute this document or an adaptation of it, you must provide the URL for the original version.
Red Hat, as the licensor of this document, waives the right to enforce, and agrees not to assert, Section 4d of CC-BY-SA to the fullest extent permitted by applicable law.
Red Hat, Red Hat Enterprise Linux, the Shadowman logo, the Red Hat logo, JBoss, OpenShift, Fedora, the Infinity logo, and RHCE are trademarks of Red Hat, Inc., registered in the United States and other countries.
Linux® is the registered trademark of Linus Torvalds in the United States and other countries.
Java® is a registered trademark of Oracle and/or its affiliates.
XFS® is a trademark of Silicon Graphics International Corp. or its subsidiaries in the United States and/or other countries.
MySQL® is a registered trademark of MySQL AB in the United States, the European Union and other countries.
Node.js® is an official trademark of Joyent. Red Hat is not formally related to or endorsed by the official Joyent Node.js open source or commercial project.
The OpenStack® Word Mark and OpenStack logo are either registered trademarks/service marks or trademarks/service marks of the OpenStack Foundation, in the United States and other countries and are used with the OpenStack Foundation's permission. We are not affiliated with, endorsed or sponsored by the OpenStack Foundation, or the OpenStack community.
All other trademarks are the property of their respective owners.
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

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

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

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

Red Hat 소개

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

Theme

© 2025 Red Hat