|
| 1 | +# Autoscaling service based on queue depth |
| 2 | + |
| 3 | +## Prerequisites |
| 4 | + |
| 5 | +You can refer to the [Installation Guide](https://openfunction.dev/docs/getting-started/installation/) to setup OpenFunction. |
| 6 | + |
| 7 | +Follow [this guide](../../../../Prerequisites.md#kafka) to install a Kafka server named `kafka-server` and a Topic named `sample-topic`. |
| 8 | + |
| 9 | +Follow [this guide](../../../../Prerequisites.md#registry-credential) to create a registry credential. |
| 10 | + |
| 11 | +## Deployment |
| 12 | + |
| 13 | +The `cron-input-kafka-output-java` function will be triggered by Dapr's `bindings.cron` component at a frequency of once every 2 seconds. After being triggered, it will send a greeting to another service via Dapr's `bindings.kafka` component. |
| 14 | + |
| 15 | +Modify the `spec.image` field in `cron-input-kafka-output.yaml` to your own container registry address: |
| 16 | + |
| 17 | + ```yaml |
| 18 | + apiVersion: core.openfunction.io/v1beta1 |
| 19 | + kind: Function |
| 20 | + metadata: |
| 21 | + name: cron-input-kafka-output-java |
| 22 | + spec: |
| 23 | + image: "<your registry name>/cron-input-kafka-output-java:v1" |
| 24 | + ``` |
| 25 | +
|
| 26 | +Use the following commands to create this Function: |
| 27 | +
|
| 28 | + ```shell |
| 29 | + kubectl apply -f cron-input-kafka-output.yaml |
| 30 | + ``` |
| 31 | + |
| 32 | +Afterwards, use the following command to observe the log of the function: |
| 33 | + |
| 34 | + ```shell |
| 35 | + kubectl logs -f \ |
| 36 | + $(kubectl get po -l \ |
| 37 | + openfunction.io/serving=$(kubectl get functions cron-input-kafka-output-java -o jsonpath='{.status.serving.resourceRef}') \ |
| 38 | + -o jsonpath='{.items[0].metadata.name}') \ |
| 39 | + function |
| 40 | + ``` |
| 41 | + |
| 42 | +You will be able to see messages similar to the following: |
| 43 | + |
| 44 | + ```shell |
| 45 | + plugin plugin-example:v1.0.0 exec pre hook for binding serving-2w6ft-component-cron-jsvxg at 2022-10-19 08:00:25.Z |
| 46 | + receive event: |
| 47 | + send to output sample |
| 48 | + plugin plugin-example:v1.0.0 exec post hook for binding serving-2w6ft-component-cron-jsvxg at 2022-10-19 08:00:25.Z |
| 49 | + ``` |
| 50 | + |
| 51 | +Now we need to start the kafka-input function. |
| 52 | + |
| 53 | + ```shell |
| 54 | + kubectl apply -f ../kafka-input/kafka-input.yaml |
| 55 | + ``` |
| 56 | + |
| 57 | +Use the following command to observe the log of the function: |
| 58 | + |
| 59 | + ```shell |
| 60 | + kubectl logs -f \ |
| 61 | + $(kubectl get po -l \ |
| 62 | + openfunction.io/serving=$(kubectl get functions kafka-input-java -o jsonpath='{.status.serving.resourceRef}') \ |
| 63 | + -o jsonpath='{.items[0].metadata.name}') \ |
| 64 | + function |
| 65 | + ``` |
| 66 | + |
| 67 | +You will be able to see messages similar to the following: |
| 68 | + |
| 69 | + ```shell |
| 70 | + plugin plugin-example:v1.0.0 exec pre hook for binding serving-p7nll-component-target-topic-kjh7q at 2022-10-19 08:12:58.Z |
| 71 | + receive event: "" |
| 72 | + plugin plugin-example:v1.0.0 exec post hook for binding serving-p7nll-component-target-topic-kjh7q at 2022-10-19 08:12:58.Z |
| 73 | + ``` |
0 commit comments