From f2976d916d899624b680249c97548d0d4f55f7dc Mon Sep 17 00:00:00 2001 From: Fran Mendez Date: Tue, 14 Nov 2023 12:00:54 +0100 Subject: [PATCH 01/14] docs: migrate code generation and message validation tutorials to use Glee --- pages/docs/tutorials/generate-code.md | 61 ++++++++++++++------------- 1 file changed, 32 insertions(+), 29 deletions(-) diff --git a/pages/docs/tutorials/generate-code.md b/pages/docs/tutorials/generate-code.md index 0ddf35bd818..30e077001f9 100644 --- a/pages/docs/tutorials/generate-code.md +++ b/pages/docs/tutorials/generate-code.md @@ -6,12 +6,13 @@ weight: 100 ## Introduction -In this tutorial, you'll learn how to generate code from your AsyncAPI document using the AsyncAPI generator tool. +In this tutorial, you'll learn how to generate code from your AsyncAPI document using [Glee](https://github.com/asyncapi/glee). ## Background context -The [AsyncAPI Generator](https://github.com/asyncapi/generator) is a tool that you can use to generate whatever you want based on the AsyncAPI document. You can generate docs and code. It can be used as a library in a Node.js application or through the [AsyncAPI CLI](https://github.com/asyncapi/cli). +[Glee](https://github.com/asyncapi/glee) is a TS/JS framework that enables you to create APIs and messaging clients based on the AsyncAPI document. Instead of generating code, this framework tightly integrates with your AsyncAPI document and binds functions to specific +AsyncAPI operations. You only have to provide the code for these functions and Glee will take care of the rest. -The generator tool supports a number of templates to generate code for a variety of different languages and protocols as the output. These templates help to specify what exactly must be generated, and in this tutorial, you'll use a [Node.js template](https://github.com/asyncapi/nodejs-template). +Glee is often used with the [AsyncAPI CLI](/tools/cli) for a better development experience. ## Installation guide @@ -24,45 +25,47 @@ import CliInstallation from '../../../assets/docs/fragments/cli-installation.md' -## Generate code +## Create a Glee project -To generate code from the [AsyncAPI document created in a previous tutorial](https://asyncapi.com/docs/tutorials/create-asyncapi-document), follow the steps listed below: - - - -If you did not follow the previous tutorial and do not have an `asyncapi.yaml` file ready, generate one running `asyncapi new --example=tutorial.yml --no-tty`. - - - -1. Trigger generation of the Node.js code: +1. Trigger the creation of the Glee project: - {`asyncapi generate fromTemplate asyncapi.yaml @asyncapi/nodejs-template -o output -p server=mosquitto`} + {`asyncapi new glee --name=tutorial`} Let's break down the previous command: - - `asyncapi generate fromTemplate` is how you use AsyncAPI Generator via the AsyncAPI CLI. - - ` asyncapi.yaml` is how you point to your AsyncAPI document and can be a URL. - - `@asyncapi/nodejs-template` is how you specify the Node.js template. - - `-o` determines where to output the result. - - `-p` defines additional parameters you want to pass to the template. Here, the `server` parameter specifies the server's name as it is defined in AsyncAPI document. + - `asyncapi new glee` is how you use Glee via the AsyncAPI CLI. + - `--name=tutorial` is how you tell the AsyncAPI CLI to name your new Glee project. -2. List all files in directory and check that the Node.js application is generated: +2. List all files in directory and check that the Glee project is created: - {`cd output && ls`} + {`cd tutorial && ls`} Upon execution of the command above, the following is an example of the expected result: {`$ ls - Dockerfile - asyncapi.yaml - docs - src + LICENSE README.md - config + asyncapi.yaml + functions + package-lock.json package.json`} + By default, Glee provides a sample `asyncapi.yaml` file. If you want to use the [AsyncAPI document created in the previous tutorial](https://asyncapi.com/docs/tutorials/create-asyncapi-document), either replace the file if you have it somewhere else or generate a new one by running `rm asyncapi.yaml && asyncapi new --example=tutorial.yml --no-tty`. + +3. Create the necessary functions: + + {`touch functions/onLightMeasured.js`} + + + + + If you look at the content of the `functions` folder, you should also see another file named `onHello.js`. You can safely delete it + by running `rm functions/onHello.js`. + + + ## Start generated application 1. Install dependencies of the newly generated application: @@ -71,7 +74,7 @@ If you did not follow the previous tutorial and do not have an `asyncapi.yaml` f 2. Start the application: - {`npm start`} + {`npm run dev`} ## Send message to broker @@ -91,9 +94,9 @@ If you did not follow the previous tutorial and do not have an `asyncapi.yaml` f { id: 1, lumens: 3, sentAt: '2017-06-07T12:34:32.000Z' }`} ## Summary -In this tutorial, you learned how to generate your code from the [Streetlights API specification document created in a previous tutorial](https://asyncapi.com/docs/tutorials/create-asyncapi-document) using the AsyncAPI generator tool. +In this tutorial, you learned how to create a Glee project from the [Streetlights API specification document created in a previous tutorial](https://asyncapi.com/docs/tutorials/create-asyncapi-document). -Additionally, you've learned how to run your code by installing the generated code's dependencies and sending several test messages to the Streelights application using the MQTT client. +Additionally, you've learned how to run your code by installing the project's dependencies and sending several test messages to the Streelights application using the MQTT client. ## Next steps Now that you've completed this tutorial, go ahead and learn how to [validate your AsyncAPI messages (events)](https://asyncapi.com/docs/tutorials/message-validation) through the message validation techniques supported by AsyncAPI. From 226a0575a37ab94f630c5feb147a08b13071c22d Mon Sep 17 00:00:00 2001 From: Fran Mendez Date: Tue, 21 Nov 2023 12:09:23 +0100 Subject: [PATCH 02/14] Update tutorials to use the latest Glee release --- pages/docs/tutorials/generate-code.md | 14 +- pages/docs/tutorials/message-validation.md | 173 ++++++++++----------- 2 files changed, 83 insertions(+), 104 deletions(-) diff --git a/pages/docs/tutorials/generate-code.md b/pages/docs/tutorials/generate-code.md index 30e077001f9..f480a09fe55 100644 --- a/pages/docs/tutorials/generate-code.md +++ b/pages/docs/tutorials/generate-code.md @@ -29,12 +29,13 @@ import CliInstallation from '../../../assets/docs/fragments/cli-installation.md' 1. Trigger the creation of the Glee project: - {`asyncapi new glee --name=tutorial`} + {`asyncapi new glee --name=tutorial --template tutorial`} Let's break down the previous command: - `asyncapi new glee` is how you use Glee via the AsyncAPI CLI. - `--name=tutorial` is how you tell the AsyncAPI CLI to name your new Glee project. + - `--template=tutorial` is how you tell the AsyncAPI CLI to use the a template of a Glee project that was created especifically for this tutorial. 2. List all files in directory and check that the Glee project is created: @@ -52,20 +53,11 @@ import CliInstallation from '../../../assets/docs/fragments/cli-installation.md' package.json`} - By default, Glee provides a sample `asyncapi.yaml` file. If you want to use the [AsyncAPI document created in the previous tutorial](https://asyncapi.com/docs/tutorials/create-asyncapi-document), either replace the file if you have it somewhere else or generate a new one by running `rm asyncapi.yaml && asyncapi new --example=tutorial.yml --no-tty`. - 3. Create the necessary functions: {`touch functions/onLightMeasured.js`} - - - If you look at the content of the `functions` folder, you should also see another file named `onHello.js`. You can safely delete it - by running `rm functions/onHello.js`. - - - ## Start generated application 1. Install dependencies of the newly generated application: @@ -90,7 +82,7 @@ import CliInstallation from '../../../assets/docs/fragments/cli-installation.md' 3. Go back to the previous terminal to check if your application logged the streetlight condition you just sent. You should see something like this displayed in the terminal: - {`light/measured was received: + {`lightMeasured was received from mosquitto: { id: 1, lumens: 3, sentAt: '2017-06-07T12:34:32.000Z' }`} ## Summary diff --git a/pages/docs/tutorials/message-validation.md b/pages/docs/tutorials/message-validation.md index e06d226b291..e85f48c0ca2 100644 --- a/pages/docs/tutorials/message-validation.md +++ b/pages/docs/tutorials/message-validation.md @@ -1,93 +1,80 @@ ---- -title: Message validation in runtime -description: In this tutorial, you'll learn how to validate AsyncAPI messages (events). - -weight: 130 ---- - -## Introduction -In this tutorial, you'll learn how to validate messages (events) that are sent to your AsyncAPI application. - -## Background context -Message validation can be performed at both the **producer** and **consumer** levels. Message validation requires the participation of the producer, consumer, and broker. We will learn how to validate messages at the consumer level by discarding invalid messages based on the parameters provided. - -You will be using the [Eclipse Mosquitto](https://mosquitto.org/) broker. The MQTT protocol provides a lightweight method of messaging using a publish/subscribe model. You will also use an MQTT client that runs an MQTT library and connects to an MQTT broker over a network. Here publishers and subscribers are MQTT clients. The publisher and subscriber labels refer to whether the client is publishing or subscribing to receive messages. - -In the previous tutorial, you generated your application using the [AsyncAPI Generator](https://github.com/asyncapi/generator) Node.js template. - - -If you did not follow the previous tutorial and do not have an `asyncapi.yaml` file ready, then generate one by running: -`asyncapi new --example=tutorial.yml --no-tty`. - -Next, generate a server by running: - - asyncapi generate fromTemplate asyncapi.yaml @asyncapi/nodejs-template -o output -p server=mosquitto - cd output && npm install - - - -Now you will be validating the messages which you will be sending to your application using a Mosquitto broker and an MQTT client. - -## Validate messages -In this step, you will send a message to your application using an MQTT broker and check the errors logged when you accidentally send an invalid message. - -1. Start your generated application. - - -{`npm start`} - - -2. Let's send a message: - - - {`mqtt pub -t 'light/measured' -h 'test.mosquitto.org' -m '{"id": 1, "lumens": "3", "sentAt": "2017-06-07T12:34:32.000Z"}'`} - - -Go back to the previous terminal and check if your application logged the streetlight condition you just sent, with errors related to the invalid message. You should see something displayed in the terminal similar to the following: - - - {`light/measured was received: -{ id: 1, lumens: '3', sentAt: '2017-06-07T12:34:32.000Z' } -❗ Message Rejected. data.lumens should be integer`} - - -Here, you can see that the property `lumens` has type `integer`, but you are sending a message with type `string`. - - - {` message: - name: lumensInfo - payload: - type: object - properties: - id: - type: integer - minimum: 0 - description: Id of the streetlight. - lumens: - type: integer - minimum: 0 - description: Light intensity measured in lumens.`} - - -3. Send a correct message to your application: - - - {`mqtt pub -t 'light/measured' -h 'test.mosquitto.org' -m '{"id": 1, "lumens": 3, "sentAt": "2017-06-07T12:34:32.000Z"}'`} - - -You can see that your generated application received a message in the terminal: - - - {`light/measured was received: -{ id: 1, lumens: 3, sentAt: '2017-06-07T12:34:32.000Z' }`} - - -This indicates that your message is valid and the application recieved it correctly. - -## Summary -In this tutorial, you learned how to connect your generated application to an MQTT broker, send messages through it, identify when an invalid message is sent to your application, and how to correct an invalid message. - -## Next steps -Now that you've completed this tutorial, enjoy our [AsyncAPI message validation guide](https://www.asyncapi.com/docs/guides/message-validation). - ---- +--- +title: Message validation in runtime +description: In this tutorial, you'll learn how to validate AsyncAPI messages (events). + +weight: 130 +--- + +## Introduction +In this tutorial, you'll learn how to validate messages (events) that are sent to your AsyncAPI application. + +## Background context +Message validation can be performed at both the **producer** and **consumer** levels. Message validation requires the participation of the producer, consumer, and broker. We will learn how to validate messages at the consumer level by discarding invalid messages based on the parameters provided. + +You will be using the [Eclipse Mosquitto](https://mosquitto.org/) broker. The MQTT protocol provides a lightweight method of messaging using a publish/subscribe model. You will also use an MQTT client that runs an MQTT library and connects to an MQTT broker over a network. Here publishers and subscribers are MQTT clients. The publisher and subscriber labels refer to whether the client is publishing or subscribing to receive messages. + +In the [previous tutorial](https://asyncapi.com/docs/tutorials/generate-code), you generated your application using [Glee](https://github.com/asyncapi/glee). Now you will be validating the messages which you will be sending to your application using a Mosquitto broker and an MQTT client. + +## Validate messages +In this step, you will send a message to your application using an MQTT broker and check the errors logged when you accidentally send an invalid message. + +1. Start your generated application. + + +{`npm run dev`} + + +2. Let's send a message: + + + {`mqtt pub -t 'light/measured' -h 'test.mosquitto.org' -m '{"id": 1, "lumens": "3", "sentAt": "2017-06-07T12:34:32.000Z"}'`} + + +Go back to the previous terminal and check if your application logged the streetlight condition you just sent, with errors related to the invalid message. You should see something displayed in the terminal similar to the following: + + + {`lightMeasured was received from mosquitto: +{ id: 1, lumens: '3', sentAt: '2017-06-07T12:34:32.000Z' } +❗ Message Rejected. data.lumens should be integer`} + + +Here, you can see that the property `lumens` has type `integer`, but you are sending a message with type `string`. + + + {` message: + name: lumensInfo + payload: + type: object + properties: + id: + type: integer + minimum: 0 + description: Id of the streetlight. + lumens: + type: integer + minimum: 0 + description: Light intensity measured in lumens.`} + + +3. Send a correct message to your application: + + + {`mqtt pub -t 'light/measured' -h 'test.mosquitto.org' -m '{"id": 1, "lumens": 3, "sentAt": "2017-06-07T12:34:32.000Z"}'`} + + +You can see that your generated application received a message in the terminal: + + + {`lightMeasured was received from mosquitto: +{ id: 1, lumens: 3, sentAt: '2017-06-07T12:34:32.000Z' }`} + + +This indicates that your message is valid and the application received it correctly. + +## Summary +In this tutorial, you learned how to connect your generated application to an MQTT broker, send messages through it, identify when an invalid message is sent to your application, and how to correct an invalid message. + +## Next steps +Now that you've completed this tutorial, enjoy our [AsyncAPI message validation guide](https://www.asyncapi.com/docs/guides/message-validation). + +--- From deb8d7d1b22e59515034ba161d06c3e26d8d68e7 Mon Sep 17 00:00:00 2001 From: Fran Mendez Date: Tue, 21 Nov 2023 12:14:51 +0100 Subject: [PATCH 03/14] Fix typos and remove unnecessary steps --- pages/docs/tutorials/generate-code.md | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/pages/docs/tutorials/generate-code.md b/pages/docs/tutorials/generate-code.md index f480a09fe55..09a528ca5c7 100644 --- a/pages/docs/tutorials/generate-code.md +++ b/pages/docs/tutorials/generate-code.md @@ -35,7 +35,7 @@ import CliInstallation from '../../../assets/docs/fragments/cli-installation.md' Let's break down the previous command: - `asyncapi new glee` is how you use Glee via the AsyncAPI CLI. - `--name=tutorial` is how you tell the AsyncAPI CLI to name your new Glee project. - - `--template=tutorial` is how you tell the AsyncAPI CLI to use the a template of a Glee project that was created especifically for this tutorial. + - `--template=tutorial` is how you tell the AsyncAPI CLI to use the template of a Glee project that was created especifically for this tutorial. 2. List all files in directory and check that the Glee project is created: @@ -49,15 +49,9 @@ import CliInstallation from '../../../assets/docs/fragments/cli-installation.md' README.md asyncapi.yaml functions - package-lock.json package.json`} -3. Create the necessary functions: - - {`touch functions/onLightMeasured.js`} - - ## Start generated application 1. Install dependencies of the newly generated application: From 9d38d5f9587f65c85061a29a6be4954688fcf1b5 Mon Sep 17 00:00:00 2001 From: Fran Mendez Date: Tue, 21 Nov 2023 12:16:47 +0100 Subject: [PATCH 04/14] Fix punctuation marks --- pages/docs/tutorials/message-validation.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/pages/docs/tutorials/message-validation.md b/pages/docs/tutorials/message-validation.md index e85f48c0ca2..37b724e29b4 100644 --- a/pages/docs/tutorials/message-validation.md +++ b/pages/docs/tutorials/message-validation.md @@ -18,7 +18,7 @@ In the [previous tutorial](https://asyncapi.com/docs/tutorials/generate-code), y ## Validate messages In this step, you will send a message to your application using an MQTT broker and check the errors logged when you accidentally send an invalid message. -1. Start your generated application. +1. Start your generated application: {`npm run dev`} @@ -38,7 +38,7 @@ Go back to the previous terminal and check if your application logged the street ❗ Message Rejected. data.lumens should be integer`} -Here, you can see that the property `lumens` has type `integer`, but you are sending a message with type `string`. +Here, you can see that the property `lumens` has type `integer`, but you are sending a message with type `string`: {` message: From a815df44a056ffa88f6f679d824b612aee54f915 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=20M=C3=A9ndez?= Date: Wed, 22 Nov 2023 11:33:16 +0100 Subject: [PATCH 05/14] Update pages/docs/tutorials/generate-code.md Co-authored-by: Lukasz Gornicki --- pages/docs/tutorials/generate-code.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/docs/tutorials/generate-code.md b/pages/docs/tutorials/generate-code.md index 09a528ca5c7..845e6580867 100644 --- a/pages/docs/tutorials/generate-code.md +++ b/pages/docs/tutorials/generate-code.md @@ -6,7 +6,7 @@ weight: 100 ## Introduction -In this tutorial, you'll learn how to generate code from your AsyncAPI document using [Glee](https://github.com/asyncapi/glee). +In this tutorial, you'll learn how to generate an application that uses [Glee](https://github.com/asyncapi/glee) framework. You'll do it with AsyncAPI document and [AsyncAPI CLI](/tools/cli). ## Background context [Glee](https://github.com/asyncapi/glee) is a TS/JS framework that enables you to create APIs and messaging clients based on the AsyncAPI document. Instead of generating code, this framework tightly integrates with your AsyncAPI document and binds functions to specific From 14215f602ea1b6ba87577f2dedf6306eda95afea Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=20M=C3=A9ndez?= Date: Wed, 22 Nov 2023 11:35:03 +0100 Subject: [PATCH 06/14] Update pages/docs/tutorials/generate-code.md Co-authored-by: Lukasz Gornicki --- pages/docs/tutorials/generate-code.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pages/docs/tutorials/generate-code.md b/pages/docs/tutorials/generate-code.md index 845e6580867..0b8a68c4539 100644 --- a/pages/docs/tutorials/generate-code.md +++ b/pages/docs/tutorials/generate-code.md @@ -77,7 +77,8 @@ import CliInstallation from '../../../assets/docs/fragments/cli-installation.md' 3. Go back to the previous terminal to check if your application logged the streetlight condition you just sent. You should see something like this displayed in the terminal: {`lightMeasured was received from mosquitto: - { id: 1, lumens: 3, sentAt: '2017-06-07T12:34:32.000Z' }`} + { id: 1, lumens: 3, sentAt: '2017-06-07T12:34:32.000Z' } + Streetlight with id "1" updated its lighting information to 3 lumens at 2017-06-07T12:34:32.000Z.`} ## Summary In this tutorial, you learned how to create a Glee project from the [Streetlights API specification document created in a previous tutorial](https://asyncapi.com/docs/tutorials/create-asyncapi-document). From 9300456bb132762fb6bd996a9f78ae04fd13e390 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=20M=C3=A9ndez?= Date: Wed, 22 Nov 2023 11:35:57 +0100 Subject: [PATCH 07/14] Update pages/docs/tutorials/generate-code.md Co-authored-by: Lukasz Gornicki --- pages/docs/tutorials/generate-code.md | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/pages/docs/tutorials/generate-code.md b/pages/docs/tutorials/generate-code.md index 0b8a68c4539..109c897ea3c 100644 --- a/pages/docs/tutorials/generate-code.md +++ b/pages/docs/tutorials/generate-code.md @@ -9,8 +9,7 @@ weight: 100 In this tutorial, you'll learn how to generate an application that uses [Glee](https://github.com/asyncapi/glee) framework. You'll do it with AsyncAPI document and [AsyncAPI CLI](/tools/cli). ## Background context -[Glee](https://github.com/asyncapi/glee) is a TS/JS framework that enables you to create APIs and messaging clients based on the AsyncAPI document. Instead of generating code, this framework tightly integrates with your AsyncAPI document and binds functions to specific -AsyncAPI operations. You only have to provide the code for these functions and Glee will take care of the rest. +[Glee](https://github.com/asyncapi/glee) is a TS/JS framework that enables you to create APIs and messaging clients based on the AsyncAPI document. Instead of generating code, this framework tightly integrates with your AsyncAPI document and binds functions to specific AsyncAPI operations. You only have to provide the code for these functions and Glee will take care of the rest. Glee is often used with the [AsyncAPI CLI](/tools/cli) for a better development experience. From 4cec8b94f684c5c7ed74e932c8202fe2d90c8815 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=20M=C3=A9ndez?= Date: Wed, 22 Nov 2023 11:36:45 +0100 Subject: [PATCH 08/14] Update pages/docs/tutorials/generate-code.md Co-authored-by: Lukasz Gornicki --- pages/docs/tutorials/generate-code.md | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/pages/docs/tutorials/generate-code.md b/pages/docs/tutorials/generate-code.md index 109c897ea3c..e7ae4a939e1 100644 --- a/pages/docs/tutorials/generate-code.md +++ b/pages/docs/tutorials/generate-code.md @@ -13,6 +13,15 @@ In this tutorial, you'll learn how to generate an application that uses [Glee](h Glee is often used with the [AsyncAPI CLI](/tools/cli) for a better development experience. +In the previous tutorial, you created an AsyncAPI document that is used in this tutorial. + + + +If you did not follow the previous tutorial and do not have an `asyncapi.yaml` file for overview, then generate one by running the following command using AsyncAPI CLI: +`asyncapi new --example=tutorial.yml --no-tty`. + + + ## Installation guide From e873b35fd97ea2f1ebfd9b26e06d98cf8c0987b0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=20M=C3=A9ndez?= Date: Wed, 22 Nov 2023 11:37:07 +0100 Subject: [PATCH 09/14] Update pages/docs/tutorials/message-validation.md Co-authored-by: Lukasz Gornicki --- pages/docs/tutorials/message-validation.md | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/pages/docs/tutorials/message-validation.md b/pages/docs/tutorials/message-validation.md index 37b724e29b4..4ecd2e6f957 100644 --- a/pages/docs/tutorials/message-validation.md +++ b/pages/docs/tutorials/message-validation.md @@ -13,7 +13,16 @@ Message validation can be performed at both the **producer** and **consumer** le You will be using the [Eclipse Mosquitto](https://mosquitto.org/) broker. The MQTT protocol provides a lightweight method of messaging using a publish/subscribe model. You will also use an MQTT client that runs an MQTT library and connects to an MQTT broker over a network. Here publishers and subscribers are MQTT clients. The publisher and subscriber labels refer to whether the client is publishing or subscribing to receive messages. -In the [previous tutorial](https://asyncapi.com/docs/tutorials/generate-code), you generated your application using [Glee](https://github.com/asyncapi/glee). Now you will be validating the messages which you will be sending to your application using a Mosquitto broker and an MQTT client. +In the [previous tutorial](https://asyncapi.com/docs/tutorials/generate-code), you generated your application that uses [Glee](https://github.com/asyncapi/glee) framework. Now you will be validating the messages which you will be sending to your application using a Mosquitto broker and an MQTT client. + + + +If you did not follow the previous tutorial and do not have an application generated, then follow these instructions: + + asyncapi new glee --name=tutorial --template tutorial`. + cd tutorial && npm install + + ## Validate messages In this step, you will send a message to your application using an MQTT broker and check the errors logged when you accidentally send an invalid message. From 555b599b2587d4ea59eaab044fc0191995f892eb Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=20M=C3=A9ndez?= Date: Wed, 22 Nov 2023 11:37:33 +0100 Subject: [PATCH 10/14] Update pages/docs/tutorials/message-validation.md Co-authored-by: Lukasz Gornicki --- pages/docs/tutorials/message-validation.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/pages/docs/tutorials/message-validation.md b/pages/docs/tutorials/message-validation.md index 4ecd2e6f957..330abdc3c2a 100644 --- a/pages/docs/tutorials/message-validation.md +++ b/pages/docs/tutorials/message-validation.md @@ -75,7 +75,8 @@ You can see that your generated application received a message in the terminal: {`lightMeasured was received from mosquitto: -{ id: 1, lumens: 3, sentAt: '2017-06-07T12:34:32.000Z' }`} +{ id: 1, lumens: 3, sentAt: '2017-06-07T12:34:32.000Z' } +Streetlight with id "1" updated its lighting information to 3 lumens at 2017-06-07T12:34:32.000Z.`} This indicates that your message is valid and the application received it correctly. From 8498b15895f5f53b9e21fed95d285da93f1412c0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=20M=C3=A9ndez?= Date: Wed, 22 Nov 2023 11:38:53 +0100 Subject: [PATCH 11/14] Update pages/docs/tutorials/message-validation.md --- pages/docs/tutorials/message-validation.md | 23 +++++++++++++++++++++- 1 file changed, 22 insertions(+), 1 deletion(-) diff --git a/pages/docs/tutorials/message-validation.md b/pages/docs/tutorials/message-validation.md index 330abdc3c2a..cc343ce7c03 100644 --- a/pages/docs/tutorials/message-validation.md +++ b/pages/docs/tutorials/message-validation.md @@ -44,7 +44,28 @@ Go back to the previous terminal and check if your application logged the street {`lightMeasured was received from mosquitto: { id: 1, lumens: '3', sentAt: '2017-06-07T12:34:32.000Z' } -❗ Message Rejected. data.lumens should be integer`} +x You have received a malformed event or there has been error processing it. Please review the error below: +TYPE should be integer + + 1 | { + 2 | "id": 1, +> 3 | "lumens": "3", + | ^^^ 👈🏽 type should be integer + 4 | "sentAt": "2017-06-07T12:34:32.000Z" + 5 | } + +ONEOF should match exactly one schema in oneOf + +> 1 | { + | ^ +> 2 | "id": 1, + | ^^^^^^^^^^ +> 3 | "lumens": "3", + | ^^^^^^^^^^ +> 4 | "sentAt": "2017-06-07T12:34:32.000Z" + | ^^^^^^^^^^ +> 5 | } + | ^^ 👈🏽 oneOf should match exactly one schema in oneOf Here, you can see that the property `lumens` has type `integer`, but you are sending a message with type `string`: From 821670418840a2ca3cd391897a08e9f0d5d783e4 Mon Sep 17 00:00:00 2001 From: Fran Mendez Date: Sun, 26 Nov 2023 15:53:38 +0100 Subject: [PATCH 12/14] fix compilation errors --- pages/docs/tutorials/message-validation.md | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/pages/docs/tutorials/message-validation.md b/pages/docs/tutorials/message-validation.md index cc343ce7c03..4cc7239661a 100644 --- a/pages/docs/tutorials/message-validation.md +++ b/pages/docs/tutorials/message-validation.md @@ -46,16 +46,16 @@ Go back to the previous terminal and check if your application logged the street { id: 1, lumens: '3', sentAt: '2017-06-07T12:34:32.000Z' } x You have received a malformed event or there has been error processing it. Please review the error below: TYPE should be integer - + 1 | { 2 | "id": 1, > 3 | "lumens": "3", | ^^^ 👈🏽 type should be integer 4 | "sentAt": "2017-06-07T12:34:32.000Z" 5 | } - + ONEOF should match exactly one schema in oneOf - + > 1 | { | ^ > 2 | "id": 1, @@ -65,7 +65,7 @@ ONEOF should match exactly one schema in oneOf > 4 | "sentAt": "2017-06-07T12:34:32.000Z" | ^^^^^^^^^^ > 5 | } - | ^^ 👈🏽 oneOf should match exactly one schema in oneOf + | ^^ 👈🏽 oneOf should match exactly one schema in oneOf`} Here, you can see that the property `lumens` has type `integer`, but you are sending a message with type `string`: From 7da26284006fedd2fb5632f17b3bd52f1cbf928d Mon Sep 17 00:00:00 2001 From: Alejandra Quetzalli Date: Wed, 29 Nov 2023 10:11:48 -0800 Subject: [PATCH 13/14] tw editorial fixes --- pages/docs/tutorials/generate-code.md | 10 +++++----- pages/docs/tutorials/message-validation.md | 7 +++---- 2 files changed, 8 insertions(+), 9 deletions(-) diff --git a/pages/docs/tutorials/generate-code.md b/pages/docs/tutorials/generate-code.md index e7ae4a939e1..c57d46a25e9 100644 --- a/pages/docs/tutorials/generate-code.md +++ b/pages/docs/tutorials/generate-code.md @@ -6,10 +6,10 @@ weight: 100 ## Introduction -In this tutorial, you'll learn how to generate an application that uses [Glee](https://github.com/asyncapi/glee) framework. You'll do it with AsyncAPI document and [AsyncAPI CLI](/tools/cli). +In this tutorial, you'll learn how to generate an application that uses the [Glee](https://github.com/asyncapi/glee) framework. You'll do it with an AsyncAPI document and the [AsyncAPI CLI](/tools/cli). ## Background context -[Glee](https://github.com/asyncapi/glee) is a TS/JS framework that enables you to create APIs and messaging clients based on the AsyncAPI document. Instead of generating code, this framework tightly integrates with your AsyncAPI document and binds functions to specific AsyncAPI operations. You only have to provide the code for these functions and Glee will take care of the rest. +[Glee](https://github.com/asyncapi/glee) is a TypeScript/JavaScript framework that enables you to create APIs and messaging clients based on your AsyncAPI document. Instead of generating code, this framework tightly integrates with your AsyncAPI document and binds functions to specific AsyncAPI operations. You only have to provide the code for these functions and Glee handles the rest. Glee is often used with the [AsyncAPI CLI](/tools/cli) for a better development experience. @@ -17,7 +17,7 @@ In the previous tutorial, you created an AsyncAPI document that is used in this -If you did not follow the previous tutorial and do not have an `asyncapi.yaml` file for overview, then generate one by running the following command using AsyncAPI CLI: +If you did not follow the previous tutorial and do not have an `asyncapi.yaml` file for overview, then generate one by running the following command using the AsyncAPI CLI: `asyncapi new --example=tutorial.yml --no-tty`. @@ -43,9 +43,9 @@ import CliInstallation from '../../../assets/docs/fragments/cli-installation.md' Let's break down the previous command: - `asyncapi new glee` is how you use Glee via the AsyncAPI CLI. - `--name=tutorial` is how you tell the AsyncAPI CLI to name your new Glee project. - - `--template=tutorial` is how you tell the AsyncAPI CLI to use the template of a Glee project that was created especifically for this tutorial. + - `--template=tutorial` is how you tell the AsyncAPI CLI to use the template of a Glee project that was created specifically for this tutorial. -2. List all files in directory and check that the Glee project is created: +2. List all files in the directory and confirm your Glee project creation: {`cd tutorial && ls`} diff --git a/pages/docs/tutorials/message-validation.md b/pages/docs/tutorials/message-validation.md index 4cc7239661a..47d0f528241 100644 --- a/pages/docs/tutorials/message-validation.md +++ b/pages/docs/tutorials/message-validation.md @@ -13,7 +13,7 @@ Message validation can be performed at both the **producer** and **consumer** le You will be using the [Eclipse Mosquitto](https://mosquitto.org/) broker. The MQTT protocol provides a lightweight method of messaging using a publish/subscribe model. You will also use an MQTT client that runs an MQTT library and connects to an MQTT broker over a network. Here publishers and subscribers are MQTT clients. The publisher and subscriber labels refer to whether the client is publishing or subscribing to receive messages. -In the [previous tutorial](https://asyncapi.com/docs/tutorials/generate-code), you generated your application that uses [Glee](https://github.com/asyncapi/glee) framework. Now you will be validating the messages which you will be sending to your application using a Mosquitto broker and an MQTT client. +In the [previous tutorial, you generated an application](https://asyncapi.com/docs/tutorials/generate-code) that uses [Glee](https://github.com/asyncapi/glee) framework. Now you will be validating the messages that you will be sending to your application using a Mosquitto broker and an MQTT client. @@ -33,7 +33,7 @@ In this step, you will send a message to your application using an MQTT broker a {`npm run dev`} -2. Let's send a message: +2. Send a message: {`mqtt pub -t 'light/measured' -h 'test.mosquitto.org' -m '{"id": 1, "lumens": "3", "sentAt": "2017-06-07T12:34:32.000Z"}'`} @@ -100,7 +100,7 @@ You can see that your generated application received a message in the terminal: Streetlight with id "1" updated its lighting information to 3 lumens at 2017-06-07T12:34:32.000Z.`} -This indicates that your message is valid and the application received it correctly. +Such a terminal message indicates that your message is valid and the application received it correctly. ## Summary In this tutorial, you learned how to connect your generated application to an MQTT broker, send messages through it, identify when an invalid message is sent to your application, and how to correct an invalid message. @@ -108,4 +108,3 @@ In this tutorial, you learned how to connect your generated application to an MQ ## Next steps Now that you've completed this tutorial, enjoy our [AsyncAPI message validation guide](https://www.asyncapi.com/docs/guides/message-validation). ---- From 8aecd6a6c6a0d38ded36d8ac76f60155564b016d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Fran=20M=C3=A9ndez?= Date: Wed, 29 Nov 2023 19:18:48 +0100 Subject: [PATCH 14/14] Update pages/docs/tutorials/message-validation.md --- pages/docs/tutorials/message-validation.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pages/docs/tutorials/message-validation.md b/pages/docs/tutorials/message-validation.md index 47d0f528241..faea57f4a73 100644 --- a/pages/docs/tutorials/message-validation.md +++ b/pages/docs/tutorials/message-validation.md @@ -11,7 +11,7 @@ In this tutorial, you'll learn how to validate messages (events) that are sent t ## Background context Message validation can be performed at both the **producer** and **consumer** levels. Message validation requires the participation of the producer, consumer, and broker. We will learn how to validate messages at the consumer level by discarding invalid messages based on the parameters provided. -You will be using the [Eclipse Mosquitto](https://mosquitto.org/) broker. The MQTT protocol provides a lightweight method of messaging using a publish/subscribe model. You will also use an MQTT client that runs an MQTT library and connects to an MQTT broker over a network. Here publishers and subscribers are MQTT clients. The publisher and subscriber labels refer to whether the client is publishing or subscribing to receive messages. +You will be using the [Eclipse Mosquitto](https://mosquitto.org/) broker. The MQTT protocol provides a lightweight method of messaging using a publish/subscribe model. You will also use an MQTT client that runs an MQTT library and connects to an MQTT broker over a network. Here producers and consumers are MQTT clients. The producer and consumer labels refer to whether the client is sending or receiving messages. In the [previous tutorial, you generated an application](https://asyncapi.com/docs/tutorials/generate-code) that uses [Glee](https://github.com/asyncapi/glee) framework. Now you will be validating the messages that you will be sending to your application using a Mosquitto broker and an MQTT client.