Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
.DS_Store
.idea/
.vscode/
.history/
45 changes: 0 additions & 45 deletions docs/eventing/choice.md

This file was deleted.

45 changes: 45 additions & 0 deletions docs/eventing/parallel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
---
title: "Parallel"
weight: 20
type: "docs"
---

Parallel CRD provides a way to easily define a list of branches, each receiving
the same CloudEvent sent to the Parallel ingress channel. Typically, each branch
consists of a filter function guarding the execution of the branch.

Parallel creates `Channel`s and `Subscription`s under the hood.

## Usage

### Parallel Spec

Parallel has three parts for the Spec:

1. `branches` defines the list of `filter` and `subscriber` pairs, one per branch,
and optionally a `reply` object. For each branch:
1. (optional) the `filter` is evaluated and when it returns an event the `subscriber` is
executed. Both `filter` and `subscriber` must be `Callable`.
1. the event returned by the `subscriber` is sent to the branch `reply`
object. When the `reply` is empty, the event is sent to the `spec.reply`
object (see below).
1. (optional) `channelTemplate` defines the Template which will be used to
create `Channel`s.
1. (optional) `reply` defines where the result of each branch is sent to when
the branch does not have its own `reply` object.

### Parallel Status

Parallel has three parts for the Status:

1. `conditions` which details the overall status of the Parallel object
1. `ingressChannelStatus` and `branchesStatuses` which convey the status of
underlying `Channel` and `Subscription` resource that are created as part of
this Parallel.
1. `address` which is exposed so that Parallel can be used where Addressable can
be used. Sending to this address will target the `Channel` which is fronting
this Parallel (same as `ingressChannelStatus`).

## Examples

Learn how to use Parallel by following the [examples](./samples/parallel/README.md)
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
The following examples will help you understand how to use Choice to describe
The following examples will help you understand how to use Parallel to describe
various flows.

## Prerequisites

All examples require:

- A Kubernetes cluster with
- Knative Eventing v0.8+
- Knative Eventing v0.9+
- Knative Service v0.8+

All examples are using the
Expand All @@ -23,5 +23,5 @@ trivial filtering, transformation and routing of the incoming events.

The examples are:

- [Choice with multiple cases and global reply](./multiple-cases/README.md)
- [Choice with mutually exclusive cases](./mutual-exclusivity/README.md)
- [Parallel with multiple branches and global reply](./multiple-branches/README.md)
- [Parallel with mutually exclusive cases](./mutual-exclusivity/README.md)
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
---
title: "Choice Example"
linkTitle: "Choice"
title: "Parallel Example"
linkTitle: "Parallel"
weight: 10
type: "docs"
---
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
We are going to create a Choice with two cases:
We are going to create a Parallel with two branches:

- the first case accepts events with a time that is is even
- the second case accepts events with a time that is is odd
- the first branch accepts events with a time that is is even
- the second branch accepts events with a time that is is odd

The events produced by each case are then sent to the `event-display` service.
The events produced by each branch are then sent to the `event-display` service.

## Prerequisites

Expand All @@ -12,7 +12,7 @@ Please refer to the sample overview for the [prerequisites](../README.md).
### Create the Knative Services

Let's first create the filter and transformer services that we will use in our
Choice.
Parallel.

```yaml
apiVersion: serving.knative.dev/v1alpha1
Expand Down Expand Up @@ -78,20 +78,20 @@ spec:
kubectl create -f ./filters.yaml -f ./transformers.yaml
```

### Create the Choice
### Create the Parallel

The `choice.yaml` file contains the specifications for creating the Choice.
The `parallel.yaml` file contains the specifications for creating the Parallel.

```yaml
apiVersion: messaging.knative.dev/v1alpha1
kind: Choice
kind: Parallel
metadata:
name: odd-even-choice
name: odd-even-parallel
spec:
channelTemplate:
apiVersion: messaging.knative.dev/v1alpha1
kind: InMemoryChannel
cases:
branches:
- filter:
ref:
apiVersion: serving.knative.dev/v1alpha1
Expand Down Expand Up @@ -119,10 +119,10 @@ spec:
```

```shell
kubectl create -f ./choice.yaml
kubectl create -f ./parallel.yaml
```

### Create the CronJobSource targeting the Choice
### Create the CronJobSource targeting the Parallel

This will create a CronJobSource which will send a CloudEvent with {"message":
"Even or odd?"} as the data payload every minute.
Expand All @@ -137,8 +137,8 @@ spec:
data: '{"message": "Even or odd?"}'
sink:
apiVersion: messaging.knative.dev/v1alpha1
kind: Choice
name: odd-even-choice
kind: Parallel
name: odd-even-parallel
```

```shell
Expand Down Expand Up @@ -166,7 +166,7 @@ Context Attributes,
time: 2019-07-31T18:10:00.000309586Z
datacontenttype: application/json; charset=utf-8
Extensions,
knativehistory: odd-even-choice-kn-choice-0-kn-channel.default.svc.cluster.local, odd-even-choice-kn-choice-kn-channel.default.svc.cluster.local
knativehistory: odd-even-parallel-kn-parallel-0-kn-channel.default.svc.cluster.local, odd-even-parallel-kn-parallel-kn-channel.default.svc.cluster.local
Data,
{
"message": "we are even!"
Expand All @@ -181,7 +181,7 @@ Context Attributes,
time: 2019-07-31T18:11:00.002649881Z
datacontenttype: application/json; charset=utf-8
Extensions,
knativehistory: odd-even-choice-kn-choice-1-kn-channel.default.svc.cluster.local, odd-even-choice-kn-choice-kn-channel.default.svc.cluster.local
knativehistory: odd-even-parallel-kn-parallel-1-kn-channel.default.svc.cluster.local, odd-even-parallel-kn-parallel-kn-channel.default.svc.cluster.local
Data,
{
"message": "this is odd!"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ spec:
data: '{"message": "Even or odd?"}'
sink:
apiVersion: messaging.knative.dev/v1alpha1
kind: Choice
name: odd-even-choice
kind: Parallel
name: odd-even-parallel
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apiVersion: messaging.knative.dev/v1alpha1
kind: Choice
kind: Parallel
metadata:
name: odd-even-choice
name: odd-even-parallel
spec:
channelTemplate:
apiVersion: messaging.knative.dev/v1alpha1
kind: InMemoryChannel
cases:
branches:
- filter:
ref:
apiVersion: serving.knative.dev/v1alpha1
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
In this example, we are going to see how we can create a Choice with mutually
exclusive cases.
In this example, we are going to see how we can create a Parallel with mutually
exclusive branches.

This example is the same as the
[multiple cases example](../multiple-cases/README.md) except that we are now
[multiple barnaches example](../multiple-branches/README.md) except that we are now
going to rely on the Knative
[switcher](https://github.com/lionelvillard/knative-functions#switcher) function
[switch](https://github.com/lionelvillard/knative-functions#switch) function
to provide a soft mutual exclusivity guarantee.

NOTE: this example has to be deployed in the default namespace.
NOTE: this example must be deployed in the default namespace.

## Prerequisites

Expand All @@ -16,7 +16,7 @@ Please refer to the sample overview for the [prerequisites](../README.md).
### Create the Knative Services

Let's first create the switcher and transformer services that we will use in our
Choice.
Parallel.

```yaml
apiVersion: serving.knative.dev/v1alpha1
Expand Down Expand Up @@ -69,20 +69,20 @@ spec:
kubectl create -f ./switcher.yaml -f ./transformers.yaml
```

### Create the Choice
### Create the Parallel object

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

```yaml
apiVersion: messaging.knative.dev/v1alpha1
kind: Choice
kind: Parallel
metadata:
name: me-odd-even-choice
name: me-odd-even-parallel
spec:
channelTemplate:
apiVersion: messaging.knative.dev/v1alpha1
kind: InMemoryChannel
cases:
branches:
- filter:
uri: "http://me-even-odd-switcher.default.svc.cluster.local/0"
subscriber:
Expand All @@ -104,10 +104,10 @@ spec:
```

```shell
kubectl create -f ./choice.yaml
kubectl create -f ./parallel.yaml
```

### Create the CronJobSource targeting the Choice
### Create the CronJobSource targeting the Parallel object

This will create a CronJobSource which will send a CloudEvent with {"message":
"Even or odd?"} as the data payload every minute.
Expand All @@ -122,8 +122,8 @@ spec:
data: '{"message": "Even or odd?"}'
sink:
apiVersion: messaging.knative.dev/v1alpha1
kind: Choice
name: me-odd-even-choice
kind: Parallel
name: me-odd-even-parallel
```

```shell
Expand Down Expand Up @@ -151,7 +151,7 @@ Context Attributes,
time: 2019-07-31T20:56:00.000477587Z
datacontenttype: application/json; charset=utf-8
Extensions,
knativehistory: me-odd-even-choice-kn-choice-kn-channel.default.svc.cluster.local, me-odd-even-choice-kn-choice-0-kn-channel.default.svc.cluster.local
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
Data,
{
"message": "we are even!"
Expand All @@ -166,7 +166,7 @@ Context Attributes,
time: 2019-07-31T20:57:00.000312243Z
datacontenttype: application/json; charset=utf-8
Extensions,
knativehistory: me-odd-even-choice-kn-choice-1-kn-channel.default.svc.cluster.local, me-odd-even-choice-kn-choice-kn-channel.default.svc.cluster.local
knativehistory: me-odd-even-parallel-kn-parallel-1-kn-channel.default.svc.cluster.local, me-odd-even-parallel-kn-parallel-kn-channel.default.svc.cluster.local
Data,
{
"message": "this is odd!"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,5 @@ spec:
data: '{"message": "Even or odd?"}'
sink:
apiVersion: messaging.knative.dev/v1alpha1
kind: Choice
name: me-odd-even-choice
kind: Parallel
name: me-odd-even-parallel
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
apiVersion: messaging.knative.dev/v1alpha1
kind: Choice
kind: Parallel
metadata:
name: me-odd-even-choice
name: me-odd-even-parallel
spec:
channelTemplate:
apiVersion: messaging.knative.dev/v1alpha1
kind: InMemoryChannel
cases:
branches:
- filter:
uri: "http://me-even-odd-switcher.default.svc.cluster.local/0"
subscriber:
Expand Down