281.4. 예: PetStore
예제 디렉터리의 camel-example-rest-swagger 프로젝트에서 예제 를 체크아웃합니다.
예를 들어 PetStore 제공 REST API가 Swagger 사양에서 사양 URI 및 원하는 작업 ID를 참조하거나 사양을 다운로드하여 CLASSPATH의 swagger.json (root에)으로 저장하려는 경우 자동으로 사용됩니다. undertow 구성 요소를 사용하여 모든 요청 및 Spring Boot에 대한 Camels 지원을 수행할 수 있습니다.
Maven POM 파일에 정의된 종속 항목은 다음과 같습니다.
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-undertow-starter</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-rest-swagger-starter</artifactId>
</dependency>
먼저 RestSwaggerComponent: 구성 요소 및 RestSwaggerComponent를 정의합니다.
@Bean
public Component petstore(CamelContext camelContext, UndertowComponent undertow) {
RestSwaggerComponent petstore = new RestSwaggerComponent(camelContext);
petstore.setSpecificationUri("http://petstore.swagger.io/v2/swagger.json");
petstore.setDelegate(undertow);
return petstore;
}
Camel for Spring Boot에서 지원이 자동으로 Cryostat Component Spring Quarkus를 생성하며, 접두사 camel.component.undertow를 사용하여 여기에서는 PetStore REST API와 상호 작용하는 데 사용할 수 있는 Camel 컨텍스트에 이름이 지정된 구성 요소를 가지기 위해 이 구성 요소를 정의하고 있습니다. 이 구성 요소는 동일한 방식으로 구성할 수 있는 유일한 application.properties (또는 application.yml)를 사용하여 구성할 수 있습니다.rest-swagger 구성 요소인 경우 application.properties를 사용합니다.
이제 애플리케이션에서 ProducerTemplate 을 사용하여 PetStore REST 메서드를 호출할 수 있습니다.
@Autowired
ProducerTemplate template;
String getPetJsonById(int petId) {
return template.requestBodyAndHeaders("petstore:getPetById", null, "petId", petId);
}