Mutual Exclusive Cases
This example is the same as the multiple branches example except that we are now going to rely on the Knative function to provide a soft mutual exclusivity guarantee.
NOTE: this example must be deployed in the default namespace.
Let’s first create the switcher and transformer services that we will use in our Parallel.
apiVersion: serving.knative.dev/v1
kind: Service
metadata:
name: event-display
spec:
template:
spec:
containers:
- image: gcr.io/knative-releases/knative.dev/eventing-contrib/cmd/event_display
The parallel.yaml
file contains the specifications for creating the Parallel object.
apiVersion: flows.knative.dev/v1
kind: Parallel
metadata:
name: me-odd-even-parallel
spec:
channelTemplate:
apiVersion: messaging.knative.dev/v1
kind: InMemoryChannel
branches:
- filter:
subscriber:
ref:
apiVersion: serving.knative.dev/v1
kind: Service
- filter:
uri: "http://me-even-odd-switcher.default.svc.cluster.local/1"
subscriber:
ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: me-odd-transformer
reply:
ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: me-event-display
kubectl create -f ./parallel.yaml
kubectl create -f ./ping-source.yaml
You can now see the final output by inspecting the logs of the me-event-display
pods. Note that since we set the PingSource
to emit every minute, it might take some time for the events to show up in the logs.
Let’s look at the me-event-display
log:
kubectl logs -l serving.knative.dev/service=me-event-display --tail=50 -c user-container
☁️ cloudevents.Event
Validation: valid
Context Attributes,
specversion: 1.0
type: dev.knative.sources.ping
id: 0b0db15c-9b36-4388-8eaa-8c23a9dc2707
time: 2020-03-03T21:30:00.0007292Z
datacontenttype: application/json; charset=utf-8
Extensions,
knativehistory: me-odd-even-parallel-kn-parallel-kn-channel.default.svc.cluster.local; me-odd-even-parallel-kn-parallel-0-kn-channel.default.svc.cluster.local
traceparent: 00-e8b17109cd21d4fa66a86633b5a614c7-ba96d220fe13211c-00
Data,
{
"message": "we are even!"
}
☁️ cloudevents.Event
Validation: valid
Context Attributes,
specversion: 1.0
type: dev.knative.sources.ping
source: /apis/v1/namespaces/default/pingsources/me-ping-source
id: 321170d1-dea7-4b18-9290-28adb1de089b
time: 2020-03-03T21:31:00.0007847Z
datacontenttype: application/json; charset=utf-8
Extensions,
knativehistory: me-odd-even-parallel-kn-parallel-kn-channel.default.svc.cluster.local; me-odd-even-parallel-kn-parallel-1-kn-channel.default.svc.cluster.local
traceparent: 00-78d8b044d23c85789f0a13fd3679ac24-1d69ddde56d620c7-00
Data,
{
"message": "this is odd!"