Creating a RedisStreamSource

version

This topic describes how to create a RedisStreamSource object.

Install the RedisStreamSource add-on

RedisStreamSource is a Knative Eventing add-on.

  1. Install RedisStreamSource by running the command:

    1. kubectl apply -f https://github.com/knative-sandbox/eventing-redis/releases/download/knative-v1.7.0/redis-source.yaml
  2. Verify that redis-controller-manageris running:

    1. kubectl get deployments.apps -n knative-sources

    Example output:

    1. NAME READY UP-TO-DATE AVAILABLE AGE
    2. redis-controller-manager 1/1 1 1 3s

Create a Service

  1. Create the event-display Service as a YAML file:

    1. apiVersion: serving.knative.dev/v1
    2. kind: Service
    3. metadata:
    4. name: event-display
    5. namespace: default
    6. spec:
    7. template:
    8. spec:
    9. containers:
    10. - # This corresponds to
    11. # https://github.com/knative/eventing/tree/main/cmd/event_display/main.go
    12. image: gcr.io/knative-releases/knative.dev/eventing/cmd/event_display
  2. Apply the YAML file by running the command:

    1. kubectl apply -f <filename>.yaml

    Where <filename> is the name of the file you created in the previous step.

    Example output:

    1. service.serving.knative.dev/event-display created
  3. Ensure that the Service Pod is running, by running the command:

    1. kubectl get pods

    The Pod name is prefixed with event-display:

    1. NAME READY STATUS RESTARTS AGE
    2. event-display-00001-deployment-5d5df6c7-gv2j4 2/2 Running 0 72s

Create a RedisStreamSource object

  1. Create the RedisStreamSource object using the YAML template below:
  1. apiVersion: sources.knative.dev/v1alpha1
  2. kind: RedisStreamSource
  3. metadata:
  4. name: <redis-stream-source>
  5. spec:
  6. address: <redis-uri>
  7. stream: <redis-stream-name>
  8. group: <consumer-group-name>
  9. sink: <sink>

Where:

  • <redis-stream-source> is the name of your source. (required)
  • <redis-uri> is the Redis URI. See the Redis documentation for more information. (required)
  • <redis-stream-name> is the name of the Redis stream. (required)
  • <consumer-group-name> is the name of the Redis consumer group. When left empty a group is automatically created for this source, and deleted when this source is deleted. (optional)
  • <sink> is where to send events. (required)

  • Apply the YAML file by running the command:

    1. kubectl apply -f <filename>

    Where <filename> is the name of the file you created in the previous step.

Verify the RedisStreamSource object

  1. View the logs for the event-display event consumer by running the command:

    1. kubectl logs -l app=event-display --tail=100

    Sample output:

    1. ☁️ cloudevents.Event
    2. Validation: valid
    3. Context Attributes,
    4. specversion: 1.0
    5. type: dev.knative.sources.redisstream
    6. source: /mystream
    7. id: 1597775814718-0
    8. time: 2020-08-18T18:36:54.719802342Z
    9. datacontenttype: application/json
    10. Data,
    11. [
    12. "fruit",
    13. "banana"
    14. "color",
    15. "yellow"
    16. ]

Delete the RedisStreamSource object

  • Delete the RedisStreamSource object:

    1. kubectl delete -f <filename>

Additional information