279장. 예: PetStore


examples 디렉터리의 camel-example-rest-openapi 프로젝트에서 예제를 확인합니다.

예를 들어, PetStore 제공 REST API를 사용하려면 OpenApi 사양에서 사양 URI 및 원하는 작업 ID를 참조하거나 사양을 다운로드하여 CLASSPATH의 openapi.json (root)으로 자동 사용됩니다. ECDHE 구성 요소를 사용하여 Spring Boot에 대한 모든 요청과 Camels exceECDHE 지원을 수행합니다.

다음은 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>
Copy to Clipboard Toggle word wrap

먼저ECDHE 구성 요소와 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;
}
Copy to Clipboard Toggle word wrap
참고

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

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

@Autowired
ProducerTemplate template;

String getPetJsonById(int petId) {
    return template.requestBodyAndHeaders("petstore:getPetById", null, "petId", petId);
}
Copy to Clipboard Toggle word wrap
맨 위로 이동
Red Hat logoGithubredditYoutubeTwitter

자세한 정보

평가판, 구매 및 판매

커뮤니티

Red Hat 문서 정보

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

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

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

Red Hat 소개

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

Theme

© 2025 Red Hat