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.

    1. apiVersion: serving.knative.dev/v1
    2. kind: Service
    3. metadata:
    4. name: event-display
    5. spec:
    6. template:
    7. spec:
    8. containers:
    9. - image: gcr.io/knative-releases/knative.dev/eventing-contrib/cmd/event_display

    The parallel.yaml file contains the specifications for creating the Parallel object.

    1. apiVersion: flows.knative.dev/v1
    2. kind: Parallel
    3. metadata:
    4. name: me-odd-even-parallel
    5. spec:
    6. channelTemplate:
    7. apiVersion: messaging.knative.dev/v1
    8. kind: InMemoryChannel
    9. branches:
    10. - filter:
    11. subscriber:
    12. ref:
    13. apiVersion: serving.knative.dev/v1
    14. kind: Service
    15. - filter:
    16. uri: "http://me-even-odd-switcher.default.svc.cluster.local/1"
    17. subscriber:
    18. ref:
    19. apiVersion: serving.knative.dev/v1
    20. kind: Service
    21. name: me-odd-transformer
    22. reply:
    23. ref:
    24. apiVersion: serving.knative.dev/v1
    25. kind: Service
    26. name: me-event-display
    1. kubectl create -f ./parallel.yaml
    1. 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:

    1. kubectl logs -l serving.knative.dev/service=me-event-display --tail=50 -c user-container
    2. ☁️ cloudevents.Event
    3. Validation: valid
    4. Context Attributes,
    5. specversion: 1.0
    6. type: dev.knative.sources.ping
    7. id: 0b0db15c-9b36-4388-8eaa-8c23a9dc2707
    8. time: 2020-03-03T21:30:00.0007292Z
    9. datacontenttype: application/json; charset=utf-8
    10. Extensions,
    11. 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
    12. traceparent: 00-e8b17109cd21d4fa66a86633b5a614c7-ba96d220fe13211c-00
    13. Data,
    14. {
    15. "message": "we are even!"
    16. }
    17. ☁️ cloudevents.Event
    18. Validation: valid
    19. Context Attributes,
    20. specversion: 1.0
    21. type: dev.knative.sources.ping
    22. source: /apis/v1/namespaces/default/pingsources/me-ping-source
    23. id: 321170d1-dea7-4b18-9290-28adb1de089b
    24. time: 2020-03-03T21:31:00.0007847Z
    25. datacontenttype: application/json; charset=utf-8
    26. Extensions,
    27. 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
    28. traceparent: 00-78d8b044d23c85789f0a13fd3679ac24-1d69ddde56d620c7-00
    29. Data,
    30. {
    31. "message": "this is odd!"