[go: up one dir, main page]

Skip to content

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:

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

    kubectl get deployments.apps -n knative-sources
    

    Example output:

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

Create a Service

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

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

    kubectl apply -f <filename>.yaml
    
    Where <filename> is the name of the file you created in the previous step.

    Example output:

    service.serving.knative.dev/event-display created
    

  3. Ensure that the Service Pod is running, by running the command:

    kubectl get pods
    

    The Pod name is prefixed with event-display:

    NAME                                            READY     STATUS    RESTARTS   AGE
    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:
apiVersion: sources.knative.dev/v1alpha1
kind: RedisStreamSource
metadata:
  name: <redis-stream-source>
spec:
  address: <redis-uri>
  stream: <redis-stream-name>
  group: <consumer-group-name>
  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:

    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:

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

    Sample output:

    ☁️  cloudevents.Event
    Validation: valid
    Context Attributes,
      specversion: 1.0
      type: dev.knative.sources.redisstream
      source: /mystream
      id: 1597775814718-0
      time: 2020-08-18T18:36:54.719802342Z
      datacontenttype: application/json
    Data,
      [
        "fruit",
        "banana"
        "color",
        "yellow"
      ]
    

Delete the RedisStreamSource object

  • Delete the RedisStreamSource object:

    kubectl delete -f <filename>
    

Additional information

We use analytics and cookies to understand site traffic. Information about your use of our site is shared with Google for that purpose. Learn more.

× OK