Creating a RabbitMQSource¶
This topic describes how to create a RabbitMQSource.
Prerequisites¶
- You have installed Knative Eventing
- You have installed CertManager v1.5.4 - easiest integration with RabbitMQ Messaging Topology Operator
- You have installed RabbitMQ Messaging Topology Operator - our recommendation is latest release with CertManager
- A working RabbitMQ Instance, we recommend to create one Using the RabbitMQ Cluster Operator.
For more information about configuring the
RabbitmqClusterCRD, see the RabbitMQ website
Install the RabbitMQ controller¶
-
Install the RabbitMQSource controller by running the command:
kubectl apply -f https://storage.googleapis.com/knative-nightly/eventing-rabbitmq/latest/rabbitmq-source.yaml -
Verify that
rabbitmq-controller-managerandrabbitmq-webhookare running:kubectl get deployments.apps -n knative-sourcesExample output:
NAME READY UP-TO-DATE AVAILABLE AGE rabbitmq-controller-manager 1/1 1 1 3s rabbitmq-webhook 1/1 1 1 4s
Create a Service¶
-
Create the
event-displayService 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 -
Apply the YAML file by running the command:
Wherekubectl apply -f <filename>.yaml<filename>is the name of the file you created in the previous step.Example output:
service.serving.knative.dev/event-display created -
Ensure that the Service Pod is running, by running the command:
kubectl get podsThe 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 RabbitMQSource¶
Choose either an in-cluster RabbitMQ Cluster Operator instance (name) or an external RabbitMQ server (connectionSecret). Do not set both fields in the same RabbitmqSource.
apiVersion: sources.knative.dev/v1alpha1
kind: RabbitmqSource
metadata:
name: <source-name>
spec:
rabbitmqClusterReference:
name: <cluster-name>
rabbitmqResourcesConfig:
parallelism: 10
exchangeName: "eventing-rabbitmq-source"
queueName: "eventing-rabbitmq-source"
delivery:
retry: 5
backoffPolicy: "linear"
backoffDelay: "PT1S"
sink:
ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: event-display
apiVersion: sources.knative.dev/v1alpha1
kind: RabbitmqSource
metadata:
name: <source-name>
spec:
rabbitmqClusterReference:
connectionSecret:
name: rabbitmq-secret-credentials
rabbitmqResourcesConfig:
parallelism: 10
exchangeName: "eventing-rabbitmq-source"
queueName: "eventing-rabbitmq-source"
delivery:
retry: 5
backoffPolicy: "linear"
backoffDelay: "PT1S"
sink:
ref:
apiVersion: serving.knative.dev/v1
kind: Service
name: event-display
Apply the YAML file:
kubectl apply -f <filename>.yaml
- `<source-name>` is the name you want for your RabbitMQSource object.
- `<cluster-name>` is the name of the RabbitMQ cluster you created earlier.
!!! note
You cannot set `name` and `connectionSecret` at the same time, since `name` is for a RabbitMQ Cluster Operator instance running in the same cluster as the Source, and `connectionSecret` is for an external RabbitMQ server.
-
Apply the YAML file by running the command:
Wherekubectl apply -f <filename><filename>is the name of the file you created in the previous step.
Verify¶
Check the event-display Service to see if it is receiving events. It might take a while for the Source to start sending events to the Sink.
kubectl -l='serving.knative.dev/service=event-display' logs -c user-container
☁️ cloudevents.Event
Context Attributes,
specversion: 1.0
type: dev.knative.rabbitmq.event
source: /apis/v1/namespaces/default/rabbitmqsources/<source-name>
subject: f147099d-c64d-41f7-b8eb-a2e53b228349
id: f147099d-c64d-41f7-b8eb-a2e53b228349
time: 2021-12-16T20:11:39.052276498Z
datacontenttype: application/json
Data,
{
...
Random Data
...
}
Cleanup¶
-
Delete the RabbitMQSource:
kubectl delete -f <source-yaml-filename> -
Delete the RabbitMQ credentials secret:
kubectl delete -f <secret-yaml-filename> -
Delete the event display Service:
kubectl delete -f <service-yaml-filename>
Additional information¶
- For more samples visit the
eventing-rabbitmqGithub repository samples directory - To report a bug or request a feature, open an issue in the
eventing-rabbitmqGithub repository.