Sequence terminal
The functions used in these examples live in https://github.com/knative/eventing-contrib/blob/master/cmd/appender/main.go.
For this example, we’ll assume you have set up an InMemoryChannel
as well as Knative Serving (for our functions). The examples use default
namespace, again, if you want to deploy to another Namespace, you will need to modify the examples to reflect this.
If you want to use different type of Channel
, you will have to modify the Sequence.Spec.ChannelTemplate
to create the appropriate Channel resources.
Setup
kubectl -n default create -f ./steps.yaml
The sequence.yaml
file contains the specifications for creating the Sequence. If you are using a different type of Channel, you need to change the spec.channelTemplate to point to your desired Channel.
apiVersion: flows.knative.dev/v1beta1
kind: Sequence
metadata:
name: sequence
spec:
channelTemplate:
apiVersion: messaging.knative.dev/v1beta1
kind: InMemoryChannel
steps:
- ref:
kind: Service
name: first
- ref:
kind: Service
name: second
- ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: third
Change default
below to create the Sequence
in the Namespace where you want the resources to be created.
This will create a PingSource which will send a CloudEvent with {"message": "Hello world!"}
as the data payload every 2 minutes.
apiVersion: sources.knative.dev/v1alpha2
kind: PingSource
metadata:
name: ping-source
spec:
schedule: "*/2 * * * *"
jsonData: '{"message": "Hello world!"}'
ref:
apiVersion: flows.knative.dev/v1beta1
kind: Sequence
Here, if you are using different type of Channel, you need to change the spec.channelTemplate to point to your desired Channel.
kubectl -n default create -f ./ping-source.yaml
Let’s look at the logs for the first Step
in the Sequence
:
kubectl -n default logs -l serving.knative.dev/service=first -c user-container --tail=-1
2020/03/02 21:28:00 listening on 8080, appending " - Handled by 0" to events
2020/03/02 21:28:01 Received a new event:
2020/03/02 21:28:01 [2020-03-02T21:28:00.0010247Z] /apis/v1/namespaces/default/pingsources/ping-source dev.knative.sources.ping: &{Sequence:0 Message:Hello world!}
2020/03/02 21:28:01 Transform the event to:
2020/03/02 21:28:01 [2020-03-02T21:28:00.0010247Z] /apis/v1/namespaces/default/pingsources/ping-source dev.knative.sources.ping: &{Sequence:0 Message:Hello world! - Handled by 0}
Then we can look at the output of the second Step in the Sequence
:
kubectl -n default logs -l serving.knative.dev/service=second -c user-container --tail=-1
2020/03/02 21:28:02 listening on 8080, appending " - Handled by 1" to events
2020/03/02 21:28:02 Received a new event:
2020/03/02 21:28:02 [2020-03-02T21:28:00.0010247Z] /apis/v1/namespaces/default/pingsources/ping-source dev.knative.sources.ping: &{Sequence:0 Message:Hello world! - Handled by 0}
2020/03/02 21:28:02 [2020-03-02T21:28:00.0010247Z] /apis/v1/namespaces/default/pingsources/ping-source dev.knative.sources.ping: &{Sequence:0 Message:Hello world! - Handled by 0 - Handled by 1}
And you can see that the initial PingSource message ("Hello World!")
has now been modified by the first step in the Sequence to include “ - Handled by 0”. Exciting :)
Then we can look at the output of the last Step in the :