2.3. Usage
ここでは、avro-serialize-action の使用方法について説明します。
2.3.1. Knative Action リンクのコピーリンクがクリップボードにコピーされました!
avro-serialize-action Kamelet を Knative バインディングの中間ステップとして使用できます。
avro-serialize-action-binding.yaml
apiVersion: camel.apache.org/v1alpha1
kind: KameletBinding
metadata:
name: avro-serialize-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\"}]}"
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-serialize-action-binding.yamlファイルをローカルドライブに保存し、設定に合わせて編集します。 以下のコマンドを使用して、アクションを実行します。
oc apply -f avro-serialize-action-binding.yaml
2.3.1.3. Kamel CLI を使用するための手順 リンクのコピーリンクがクリップボードにコピーされました!
以下のコマンドを使用して、アクションを設定および実行します。
kamel bind --name avro-serialize-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"}]}' channel:mychannel
このコマンドは、クラスターの現在の namespace に KameletBinding を作成します。
2.3.2. Kafka Action リンクのコピーリンクがクリップボードにコピーされました!
avro-serialize-action Kamelet を Kafka バインディングの中間ステップとして使用することができます。
avro-serialize-action-binding.yaml
apiVersion: camel.apache.org/v1alpha1
kind: KameletBinding
metadata:
name: avro-serialize-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\"}]}"
sink:
ref:
kind: KafkaTopic
apiVersion: kafka.strimzi.io/v1beta1
name: my-topic
2.3.2.1. 前提条件 リンクのコピーリンクがクリップボードにコピーされました!
AMQ Streams Operator を OpenShift クラスターにインストールし、現在の namespace に my-topic という名前のトピックを作成していることを確認します。接続先の OpenShift クラスターにRed Hat Integration - Camel Kがインストールされていることを確認します。
2.3.2.2. クラスター CLI の使用手順 リンクのコピーリンクがクリップボードにコピーされました!
-
avro-serialize-action-binding.yamlファイルをローカルドライブに保存し、設定に合わせて編集します。 以下のコマンドを使用して、アクションを実行します。
oc apply -f avro-serialize-action-binding.yaml
2.3.2.3. Kamel CLI を使用するための手順 リンクのコピーリンクがクリップボードにコピーされました!
以下のコマンドを使用して、アクションを設定および実行します。
kamel bind --name avro-serialize-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"}]}' kafka.strimzi.io/v1beta1:KafkaTopic:my-topic
このコマンドは、クラスターの現在の namespace に KameletBinding を作成します。