From 8563e26b1514c8979490de10646e47409fafeef1 Mon Sep 17 00:00:00 2001 From: MinhPhuong Cao Date: Sun, 21 Jul 2024 19:42:18 -0700 Subject: [PATCH 1/3] Add blog for mqtt source --- blog/docs/articles/introduce-mqtt-source.md | 106 ++++++++++++++++++++ 1 file changed, 106 insertions(+) create mode 100644 blog/docs/articles/introduce-mqtt-source.md diff --git a/blog/docs/articles/introduce-mqtt-source.md b/blog/docs/articles/introduce-mqtt-source.md new file mode 100644 index 0000000000..4e218aa622 --- /dev/null +++ b/blog/docs/articles/introduce-mqtt-source.md @@ -0,0 +1,106 @@ +# Introducing MQTT Source with ContainerSource CRD + +**Author: Phuong Cao...** + +Knative Eventing is taking a step forward in IoT integration with the introduction of an MQTT Source. This new feature contributes to addressing a growing need in the IoT space, allowing developers to seamlessly transform MQTT messages into CloudEvents and ingest them into the Knative Eventing system. + +## Why MQTT Source? + +With the proliferation of IoT devices and edge computing, there's an increasing number of devices emitting MQTT messages to brokers. Until now, processing these messages within Knative Eventing required additional steps. The new MQTT Source bridges this gap, enabling direct ingestion and processing of MQTT messages in a cloud-native event-driven architecture. + +## Feature Description: + +Instead of developing a full-fledged controller from scratch, we've taken a simpler and more efficient approach. The MQTT Source is implemented as a container image that can be used with the existing ContainerSource CRD. This approach is similar to what we've done for the WebSocket protocol, allowing us to transform MQTT messages received into CloudEvents and send them to specified brokers. + +## Installations: + +This feature uses mqtt_paho to receive and send MQTT messages as CloudEvents. The Mosquitto Eclipse package is used to send test MQTT messages, so it can be disregarded when the feature is complete and MQTT messages are sent from another source. + +```shell +go get github.com/eclipse/paho.golang/paho +go get github.com/cloudevents/sdk-go/v2 +go get github.com/cloudevents/sdk-go/protocol/mqtt_paho/v2 +``` + +## Using the feature: + +1. Set up an MQTT broker (for testing, you can use Mosquitto): + +```shell +docker run -it --rm --name mosquitto -p 1883:1883 eclipse-mosquitto:2.0 mosquitto -c /mosquitto-no-auth.conf +``` + +2. Set up sink: + The MQTT Source needs a sink to receive the CloudEvent message it sends. For testing purposes, we can use an event display service to receive and display those messages. Add this event_display.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 +``` + +Then keep this event_display running: + +```shell +kubectl apply event-display.yaml +``` + +## Deploy the MQTT Source + +We will first need to build the Container Source using command: + +```shell +ko build cmd/mqttsource/main.go +``` + +Then, use the following yaml file in config/tools/mqtt_source. Here, you can specify a different topic and event source by adding args. The default source would be localhost:1883, assuming you have started the mosquitto MQTT broker, and the default topic would be mqtt-topic + +``` +apiVersion: sources.knative.dev/v1 +kind: ContainerSource +metadata: + name: mqttsource +spec: + template: + spec: + containers: + - image: ko://knative.dev/eventing/cmd/mqttsource + securityContext: + allowPrivilegeEscalation: false + readOnlyRootFilesystem: true + runAsNonRoot: true + capabilities: + drop: + - ALL + seccompProfile: + type: RuntimeDefault + + + sink: + ref: + apiVersion: serving.knative.dev/v1 + kind: Service + name: event-display +``` + +```shell +ko apply -f config/tools/mqttsource/mqttsource.yaml +``` + +4. Send testing messages: + Use this command to trigger the mosquitto broker to send a MQTT message to the MQTT Source. + +```shell +mosquitto_pub -t '' -m '{"specversion" : "1.0","type" :"com.example.someevent", "id" : "1234-1234-1234","source" : "/mycontext/subcontext","data":{"msg":"}}' -D PUBLISH user-property Content-Type application/cloudevents+json; charset=utf-8 +``` + +The MQTT Source will receive this message, transform it into a CloudEvent, and send it to the specified sink in your Knative Eventing system. The event received will also be logged to the console. You can view the message if it is successfully sent by viewing the logs of event_display. From 282b4ffa9537b933ebc60692f06631e01d7e4d21 Mon Sep 17 00:00:00 2001 From: MinhPhuong Cao Date: Sun, 21 Jul 2024 19:45:06 -0700 Subject: [PATCH 2/3] add link to nav --- blog/config/nav.yml | 1 + 1 file changed, 1 insertion(+) diff --git a/blog/config/nav.yml b/blog/config/nav.yml index f06e40f3ff..2caa1e514b 100644 --- a/blog/config/nav.yml +++ b/blog/config/nav.yml @@ -81,6 +81,7 @@ nav: - articles/knative-v0-3-autoscaling-a-love-story.md - articles/ko-fast-kubernetes-microservice-development-in-go.md - articles/build-deploy-manage-modern-serverless-workloads-using-knative-on-kubernetes.md + - articles/introduce-mqtt-source.md - Steering Committee: - steering/2024-02-14-trademark-committee-dissolved.md - steering/toc-2022-election-announcement.md From 0592e21bff5d0be73d20315a63a1bb72fa9f4c72 Mon Sep 17 00:00:00 2001 From: MinhPhuong Cao Date: Sun, 28 Jul 2024 14:25:30 -0700 Subject: [PATCH 3/3] Resolve comments --- blog/config/nav.yml | 2 +- blog/docs/articles/introduce-mqtt-source.md | 12 +----------- 2 files changed, 2 insertions(+), 12 deletions(-) diff --git a/blog/config/nav.yml b/blog/config/nav.yml index 2caa1e514b..1422a0ce3e 100644 --- a/blog/config/nav.yml +++ b/blog/config/nav.yml @@ -47,6 +47,7 @@ nav: - releases/announcing-knative-v0-3-release.md - releases/announcing-knative-v0-2-release.md - Articles: + - articles/introduce-mqtt-source.md - articles/llm-agents-overview.md - articles/cross-namespace-event-links-feature.md - articles/aws_to_func_migration.md @@ -81,7 +82,6 @@ nav: - articles/knative-v0-3-autoscaling-a-love-story.md - articles/ko-fast-kubernetes-microservice-development-in-go.md - articles/build-deploy-manage-modern-serverless-workloads-using-knative-on-kubernetes.md - - articles/introduce-mqtt-source.md - Steering Committee: - steering/2024-02-14-trademark-committee-dissolved.md - steering/toc-2022-election-announcement.md diff --git a/blog/docs/articles/introduce-mqtt-source.md b/blog/docs/articles/introduce-mqtt-source.md index 4e218aa622..b8a767a511 100644 --- a/blog/docs/articles/introduce-mqtt-source.md +++ b/blog/docs/articles/introduce-mqtt-source.md @@ -1,6 +1,6 @@ # Introducing MQTT Source with ContainerSource CRD -**Author: Phuong Cao...** +**Author: [Phuong Cao](https://www.linkedin.com/in/phuong-cao-pc/)** Knative Eventing is taking a step forward in IoT integration with the introduction of an MQTT Source. This new feature contributes to addressing a growing need in the IoT space, allowing developers to seamlessly transform MQTT messages into CloudEvents and ingest them into the Knative Eventing system. @@ -12,16 +12,6 @@ With the proliferation of IoT devices and edge computing, there's an increasing Instead of developing a full-fledged controller from scratch, we've taken a simpler and more efficient approach. The MQTT Source is implemented as a container image that can be used with the existing ContainerSource CRD. This approach is similar to what we've done for the WebSocket protocol, allowing us to transform MQTT messages received into CloudEvents and send them to specified brokers. -## Installations: - -This feature uses mqtt_paho to receive and send MQTT messages as CloudEvents. The Mosquitto Eclipse package is used to send test MQTT messages, so it can be disregarded when the feature is complete and MQTT messages are sent from another source. - -```shell -go get github.com/eclipse/paho.golang/paho -go get github.com/cloudevents/sdk-go/v2 -go get github.com/cloudevents/sdk-go/protocol/mqtt_paho/v2 -``` - ## Using the feature: 1. Set up an MQTT broker (for testing, you can use Mosquitto):