27장. Python (DEPRECATED)
27.1. 개요
Python은 다양한 애플리케이션 도메인에 사용되는 매우 강력한 동적 프로그래밍 언어입니다. Python은 종종 Tcl, Perl, Ruby, Scheme 또는 Java와 비교됩니다. Python 지원은 camel-script 모듈의 일부입니다.
Apache Camel의 Python은 더 이상 사용되지 않으며 향후 릴리스에서 제거될 예정입니다.
27.2. script 모듈 추가
경로에서 Python을 사용하려면 예 27.1. “camel-script 종속성 추가” 에 표시된 대로 camel-script 에 대한 종속성을 프로젝트에 추가해야 합니다.
예 27.1. camel-script 종속성 추가
<!-- Maven POM File -->
...
<dependencies>
...
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-script</artifactId>
<version>${camel-version}</version>
</dependency>
...
</dependencies>27.3. 정적 가져오기
애플리케이션 코드에서 python() 정적 메서드를 사용하려면 Java 소스 파일에 다음 import 문을 포함합니다.
import static org.apache.camel.builder.script.ScriptBuilder.*;
27.4. 기본 제공 속성
표 27.1. “Python 속성” Python을 사용할 때 액세스할 수 있는 기본 제공 속성을 나열합니다.
표 27.1. Python 속성
| 속성 | 유형 | 현재의 |
|---|---|---|
|
|
| Camel 컨텍스트 |
|
|
| 현재 교환 |
|
|
| IN 메시지 |
|
|
| OUT 메시지 |
|
|
|
|
ENGINE_SCOPE 에서 모두 설정된 속성입니다.
27.5. 예제
예 27.2. “Python을 사용하는 경로” Python을 사용하는 경로를 표시합니다.
예 27.2. Python을 사용하는 경로
<camelContext>
<route>
<from uri="direct:start"/>
<choice>
<when>
<langauge langauge="python">if request.headers.get('user') = 'admin'</langauge>
<to uri="seda:adminQueue"/>
</when>
<otherwise>
<to uri="seda:regularQueue"/>
</otherwise>
</choice>
</route>
</camelContext>27.6. 속성 구성 요소 사용
속성 구성 요소에서 속성 값에 액세스하려면 다음과 같이 기본 제공 속성 속성에서 resolve 메서드를 호출합니다.To access a property value from the properties component, invoke the resolve method on the built-in properties attribute, as follows:
.setHeader("myHeader").python("properties.resolve(PropKey)")
여기서 PropKey 는 확인하려는 속성의 키이며 키 값은 String 유형의 키입니다.
속성 구성 요소에 대한 자세한 내용은 Apache Camel 구성 요소 참조 가이드의 속성을 참조하십시오.https://access.redhat.com/documentation/en-us/red_hat_fuse/7.9/html-single/apache_camel_component_reference/index#properties-component