Using Sequence with Broker and Trigger
- Knative Serving
InMemoryChannel
NOTE: The examples use the default
namespace.
If you want to use different type of Channel
, you will have to modify the Sequence.Spec.ChannelTemplate
to create the appropriate Channel resources.
The functions used in these examples live in https://github.com/knative/eventing-contrib/blob/master/cmd/appender/main.go.
To create the cluster default Broker type:
Create the Knative Services
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: first
spec:
template:
spec:
containers:
- image: gcr.io/knative-releases/knative.dev/eventing-contrib/cmd/appender
env:
- name: MESSAGE
value: " - Handled by 0"
---
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: second
spec:
template:
spec:
containers:
- image: gcr.io/knative-releases/knative.dev/eventing-contrib/cmd/appender
env:
- name: MESSAGE
value: " - Handled by 1"
---
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: third
spec:
spec:
containers:
- image: gcr.io/knative-releases/knative.dev/eventing-contrib/cmd/appender
env:
- name: MESSAGE
value: " - Handled by 2"
- name: TYPE
---
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.
Also, change the spec.reply.name to point to your Broker
apiVersion: flows.knative.dev/v1
kind: Sequence
metadata:
name: sequence
spec:
channelTemplate:
apiVersion: messaging.knative.dev/v1
kind: InMemoryChannel
steps:
- ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: first
- ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: second
- ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: third
reply:
ref:
kind: Broker
apiVersion: eventing.knative.dev/v1
name: default
Change the default
namespace below to create the sequence in the namespace where you have configured your broker.
Create the PingSource targeting the Broker
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/v1beta2
kind: PingSource
metadata:
name: ping-source
spec:
schedule: "*/2 * * * *"
contentType: "application/json"
data: '{"message": "Hello world!"}'
ref:
apiVersion: eventing.knative.dev/v1
kind: Broker
name: default
Change the namespace below to create the PingSource in the namespace where you have configured your broker and sequence.
kubectl -n default create -f ./ping-source.yaml
apiVersion: eventing.knative.dev/v1
kind: Trigger
metadata:
name: sequence-trigger
spec:
broker: default
filter:
attributes:
type: dev.knative.sources.ping
subscriber:
ref:
apiVersion: flows.knative.dev/v1
kind: Sequence
name: sequence
Create the Service and Trigger displaying the events created by Sequence
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: sequence-display
spec:
template:
spec:
containers:
- image: gcr.io/knative-releases/knative.dev/eventing-contrib/cmd/appender
---
apiVersion: eventing.knative.dev/v1
kind: Trigger
metadata:
name: display-trigger
spec:
broker: default
filter:
attributes:
type: samples.http.mod3
subscriber:
ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: sequence-display
---
Change default
namespace below to create the service and trigger in the namespace where you have configured your broker.
You can now see the final output by inspecting the logs of the sequence-display pods.
kubectl -n default get pods
View the logs for the sequence-display
pod:
And you can see that the initial PingSource message has been appended to it by each of the steps in the Sequence.
Was this page helpful?
Sorry to hear that. Please tell us how we can improve.