277장. 예: PetStore


examples 디렉토리의 camel-example-rest-openapi 프로젝트의 예제를 체크아웃합니다.

예를 들어, PetStore 에서 REST API를 사용하고자 하는 경우, 표준 URI와 원하는 작업 ID를 OpenApi 사양에서 참조하거나 사양을 다운로드하여 CLASSPATH의 루트(루트)로 저장하여 자동으로 사용됩니다. Undertow 구성 요소를 사용하여 Spring Boot에 대한 모든 요청 및 Camels excelent 지원을 수행합니다.

Maven POM 파일에 정의된 우리의 종속 항목은 다음과 같습니다.

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-undertow-starter</artifactId>
</dependency>

<dependency>
  <groupId>org.apache.camel.springboot</groupId>
  <artifactId>camel-rest-openapi-starter</artifactId>
</dependency>

Undertow 구성 요소 및 RestOpenApiComponent 를 정의하여 시작합니다.

@Bean
public Component petstore(CamelContext camelContext, UndertowComponent undertow) {
    RestOpenApiComponent petstore = new RestOpenApiComponent(camelContext);
    petstore.setSpecificationUri("https://petstore3.swagger.io/api/v3/openapi.json");
    petstore.setDelegate(undertow);

    return petstore;
}
참고

Camel for Spring Boot의 지원은 UndertowComponent Spring bean을 자동으로 생성하고 접두사 camel.component.undertow를 사용하여 application.properties (또는 application.yml)를 사용하여 구성할 수 있습니다. PetStore REST API와 상호 작용하는 데 사용할 수 있는 Camel 컨텍스트에 이름이 지정된 구성 요소를 사용하기 위해 여기에서 petstore 구성 요소를 정의할 수 있습니다. 이 구성 요소가 사용되는 유일한 rest-openapi 구성 요소인 경우 ( application.properties사용) 동일한 방식으로 구성할 수 있습니다.

이제 애플리케이션에서 ProducerTemplate 을 사용하여 PetStore REST 메서드를 호출할 수 있습니다.

@Autowired
ProducerTemplate template;

String getPetJsonById(int petId) {
    return template.requestBodyAndHeaders("petstore:getPetById", null, "petId", petId);
}
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

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

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

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

Red Hat 소개

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

Theme

© 2026 Red Hat
맨 위로 이동