2.3. 사용법
이 섹션에서는 avro-deserialize-action 을 사용하는 방법에 대해 설명합니다.
2.3.1. Knative 작업 링크 복사링크가 클립보드에 복사되었습니다!
avro-deserialize-action Kamelet을 Knative 바인딩의 중간 단계로 사용할 수 있습니다.
avro-deserialize-action-binding.yaml
apiVersion: camel.apache.org/v1alpha1
kind: KameletBinding
metadata:
name: avro-deserialize-action-binding
spec:
source:
ref:
kind: Kamelet
apiVersion: camel.apache.org/v1alpha1
name: timer-source
properties:
message: '{"first":"Ada","last":"Lovelace"}'
steps:
- ref:
kind: Kamelet
apiVersion: camel.apache.org/v1alpha1
name: json-deserialize-action
- ref:
kind: Kamelet
apiVersion: camel.apache.org/v1alpha1
name: avro-serialize-action
properties:
schema: "{\"type\": \"record\", \"namespace\": \"com.example\", \"name\": \"FullName\", \"fields\": [{\"name\": \"first\", \"type\": \"string\"},{\"name\": \"last\", \"type\": \"string\"}]}"
- ref:
kind: Kamelet
apiVersion: camel.apache.org/v1alpha1
name: avro-deserialize-action
properties:
schema: "{\"type\": \"record\", \"namespace\": \"com.example\", \"name\": \"FullName\", \"fields\": [{\"name\": \"first\", \"type\": \"string\"},{\"name\": \"last\", \"type\": \"string\"}]}"
- ref:
kind: Kamelet
apiVersion: camel.apache.org/v1alpha1
name: json-serialize-action
sink:
ref:
kind: Channel
apiVersion: messaging.knative.dev/v1
name: mychannel
2.3.1.1. 사전 요구 사항 링크 복사링크가 클립보드에 복사되었습니다!
연결된 OpenShift 클러스터에 "Red Hat Integration - Camel K" 가 설치되어 있는지 확인합니다.
2.3.1.2. 클러스터 CLI 사용 절차 링크 복사링크가 클립보드에 복사되었습니다!
-
avro-deserialize-action-binding.yaml파일을 로컬 드라이브에 저장한 다음, 필요에 따라 편집합니다. 다음 명령을 사용하여 작업을 실행합니다.
oc apply -f avro-deserialize-action-binding.yaml
2.3.1.3. Kamel CLI 사용 절차 링크 복사링크가 클립보드에 복사되었습니다!
다음 명령을 사용하여 작업을 구성하고 실행합니다.
kamel bind --name avro-deserialize-action-binding timer-source?message='{"first":"Ada","last":"Lovelace"}' --step json-deserialize-action --step avro-serialize-action -p step-1.schema='{"type": "record", "namespace": "com.example", "name": "FullName", "fields": [{"name": "first", "type": "string"},{"name": "last", "type": "string"}]}' --step avro-deserialize-action -p step-2.schema='{"type": "record", "namespace": "com.example", "name": "FullName", "fields": [{"name": "first", "type": "string"},{"name": "last", "type": "string"}]}' --step json-serialize-action channel:mychannel
이 명령은 클러스터의 현재 네임스페이스에 KameletBinding을 생성합니다.
2.3.2. Kafka 작업 링크 복사링크가 클립보드에 복사되었습니다!
avro-deserialize-action Kamelet을 Kafka 바인딩의 중간 단계로 사용할 수 있습니다.
avro-deserialize-action-binding.yaml
apiVersion: camel.apache.org/v1alpha1
kind: KameletBinding
metadata:
name: avro-deserialize-action-binding
spec:
source:
ref:
kind: Kamelet
apiVersion: camel.apache.org/v1alpha1
name: timer-source
properties:
message: '{"first":"Ada","last":"Lovelace"}'
steps:
- ref:
kind: Kamelet
apiVersion: camel.apache.org/v1alpha1
name: json-deserialize-action
- ref:
kind: Kamelet
apiVersion: camel.apache.org/v1alpha1
name: avro-serialize-action
properties:
schema: "{\"type\": \"record\", \"namespace\": \"com.example\", \"name\": \"FullName\", \"fields\": [{\"name\": \"first\", \"type\": \"string\"},{\"name\": \"last\", \"type\": \"string\"}]}"
- ref:
kind: Kamelet
apiVersion: camel.apache.org/v1alpha1
name: avro-deserialize-action
properties:
schema: "{\"type\": \"record\", \"namespace\": \"com.example\", \"name\": \"FullName\", \"fields\": [{\"name\": \"first\", \"type\": \"string\"},{\"name\": \"last\", \"type\": \"string\"}]}"
- ref:
kind: Kamelet
apiVersion: camel.apache.org/v1alpha1
name: json-serialize-action
sink:
ref:
kind: KafkaTopic
apiVersion: kafka.strimzi.io/v1beta1
name: my-topic
2.3.2.1. 사전 요구 사항 링크 복사링크가 클립보드에 복사되었습니다!
OpenShift 클러스터에 AMQ Streams Operator를 설치하고 현재 네임스페이스에 my-topic 이라는 주제를 생성했는지 확인합니다. 또한 연결된 OpenShift 클러스터에 "Red Hat Integration - Camel K" 가 설치되어 있는지 확인합니다.
2.3.2.2. 클러스터 CLI 사용 절차 링크 복사링크가 클립보드에 복사되었습니다!
-
avro-deserialize-action-binding.yaml파일을 로컬 드라이브에 저장한 다음, 필요에 따라 편집합니다. 다음 명령을 사용하여 작업을 실행합니다.
oc apply -f avro-deserialize-action-binding.yaml
2.3.2.3. Kamel CLI 사용 절차 링크 복사링크가 클립보드에 복사되었습니다!
다음 명령을 사용하여 작업을 구성하고 실행합니다.
kamel bind --name avro-deserialize-action-binding timer-source?message='{"first":"Ada","last":"Lovelace"}' --step json-deserialize-action --step avro-serialize-action -p step-1.schema='{"type": "record", "namespace": "com.example", "name": "FullName", "fields": [{"name": "first", "type": "string"},{"name": "last", "type": "string"}]}' --step avro-deserialize-action -p step-2.schema='{"type": "record", "namespace": "com.example", "name": "FullName", "fields": [{"name": "first", "type": "string"},{"name": "last", "type": "string"}]}' --step json-serialize-action kafka.strimzi.io/v1beta1:KafkaTopic:my-topic
이 명령은 클러스터의 현재 네임스페이스에 KameletBinding을 생성합니다.