From 605bffe350b8f3d8c7f475184ffd201d33b4d4bf Mon Sep 17 00:00:00 2001 From: Haritha Hasathcharu <42366642+hasathcharu@users.noreply.github.com.> Date: Mon, 1 Jul 2024 13:49:31 +0530 Subject: [PATCH] Address review suggessions --- samples/basic-chat/README.md | 6 ++++-- .../basic-chat/client-with-dispatcherStreamId/asyncapi.yaml | 2 +- samples/basic-chat/client-with-dispatcherStreamId/main.bal | 4 +--- samples/basic-chat/client/main.bal | 6 ++---- samples/basic-chat/server-demo/messages.md | 2 +- .../basic-chat/server-with-dispatcherStreamId/messages.md | 4 ++-- samples/basic-chat/server/messages.md | 2 +- 7 files changed, 12 insertions(+), 14 deletions(-) diff --git a/samples/basic-chat/README.md b/samples/basic-chat/README.md index 35348b0fb..f86cf35b7 100644 --- a/samples/basic-chat/README.md +++ b/samples/basic-chat/README.md @@ -9,22 +9,24 @@ This is a set of Ballerina WebSocket test examples. The examples demonstrates ho You can generate a demo AsyncAPI specification using the `server-demo` package. A pregenerated specification already exists in the `specs` directory. If you want to generate the specification again, you can use the following command, where `main.bal` is the Ballerina file that contains the entry point to the WebSocket service. ```bash +cd server-demo bal asyncapi --protocol ws -i main.bal -o specs ``` ## A client-server example -The `client` package and the `server` package are a simple example of a client-server application. The client sends a message to the server, which responds with a message, and the client logs the response. The client continuously listens for messages from the server. +The `client` and `server` packages exemplify a basic client-server application. The client sends a message to the server, which responds with a message, and the client logs the response. The client continuously listens for messages from the server. You can have two instances of the client to pass messages between them through the server. In the `client` package, the files `client.bal`, `types.bal`, and `utils.bal` are generated by the AsyncAPI tool, whereas the `main.bal` file is an example usage of the generated client. -In the `server` package, the `messages.md` file contains the message examples that the server expects. The `main.bal` file is the WebSocket server implementation. +In the `server` package, the `messages.md` file provides example messages outlining the expected structure by the server. The `main.bal` file contains the WebSocket server implementation. You can regenerate the client using the following command: ```bash +cd client bal asyncapi --protocol ws -i asyncapi.yaml ``` diff --git a/samples/basic-chat/client-with-dispatcherStreamId/asyncapi.yaml b/samples/basic-chat/client-with-dispatcherStreamId/asyncapi.yaml index 697a5b914..adb82d358 100644 --- a/samples/basic-chat/client-with-dispatcherStreamId/asyncapi.yaml +++ b/samples/basic-chat/client-with-dispatcherStreamId/asyncapi.yaml @@ -121,4 +121,4 @@ components: $ref: '#/components/messages/Response' x-response-type: simple-rpc x-dispatcherKey: event -x-dispatcherStreamId: id \ No newline at end of file +x-dispatcherStreamId: id diff --git a/samples/basic-chat/client-with-dispatcherStreamId/main.bal b/samples/basic-chat/client-with-dispatcherStreamId/main.bal index c02c1dc7b..96fbdca7d 100644 --- a/samples/basic-chat/client-with-dispatcherStreamId/main.bal +++ b/samples/basic-chat/client-with-dispatcherStreamId/main.bal @@ -49,11 +49,9 @@ public function main() returns error? { function printSingleResponse(stream subscription) { record {|Response value;|}|error? message = subscription.next(); - if message !is error? { + if message is record {|Response value;|} { io:println(message.value); } else if message is error { io:println("Error occurred at worker: " + message.message()); - } else { - io:println("NILL"); } } diff --git a/samples/basic-chat/client/main.bal b/samples/basic-chat/client/main.bal index ac11b09af..ec31195c1 100644 --- a/samples/basic-chat/client/main.bal +++ b/samples/basic-chat/client/main.bal @@ -48,11 +48,9 @@ public function main() returns error? { function printSingleResponse(stream subscription) { record {|Response value;|}|error? message = subscription.next(); - if message !is error? { + if message is record {|Response value;|} { io:println(message.value); } else if message is error { io:println("Error occurred at worker: " + message.message()); - } else { - io:println("NILL"); } -} \ No newline at end of file +} diff --git a/samples/basic-chat/server-demo/messages.md b/samples/basic-chat/server-demo/messages.md index fa4a3fad3..708a2b48f 100644 --- a/samples/basic-chat/server-demo/messages.md +++ b/samples/basic-chat/server-demo/messages.md @@ -13,5 +13,5 @@ ## Chat Message Example ```json -{"event":"chat","message":"Hello ballerina", "toUserId": "cc6b1efffe42ea75-0001e3b1-00000002-237f98c8d2877f67-d7aa765b"} +{"event":"chat","message":"Hello Ballerina", "toUserId": "cc6b1efffe42ea75-0001e3b1-00000002-237f98c8d2877f67-d7aa765b"} ``` \ No newline at end of file diff --git a/samples/basic-chat/server-with-dispatcherStreamId/messages.md b/samples/basic-chat/server-with-dispatcherStreamId/messages.md index bb094b6b1..7063740ec 100644 --- a/samples/basic-chat/server-with-dispatcherStreamId/messages.md +++ b/samples/basic-chat/server-with-dispatcherStreamId/messages.md @@ -7,11 +7,11 @@ ## Unsubscribe Message Example ```json -{"event":"unsubscribe", id:"Hellooooo"} +{"event":"unsubscribe", id:"UNSUB_ID"} ``` ## Chat Message Example ```json -{"event":"chat","message":"Hello ballerina", "toUserId": "cc6b1efffe42ea75-000420c8-00000002-3ff441ce1aa91480-ef8175ca", "id":"CHAT_ID"} +{"event":"chat","message":"Hello Ballerina", "toUserId": "cc6b1efffe42ea75-000420c8-00000002-3ff441ce1aa91480-ef8175ca", "id":"CHAT_ID"} ``` \ No newline at end of file diff --git a/samples/basic-chat/server/messages.md b/samples/basic-chat/server/messages.md index 56903e809..11a0bc442 100644 --- a/samples/basic-chat/server/messages.md +++ b/samples/basic-chat/server/messages.md @@ -13,5 +13,5 @@ ## Chat Message Example ```json -{"event":"chat","message":"Hello ballerina", "toUserId": "cc6b1efffe42ea75-0003c7e2-00000002-aa19eabfbcf62d1d-48179b7d"} +{"event":"chat","message":"Hello Ballerina", "toUserId": "cc6b1efffe42ea75-0003c7e2-00000002-aa19eabfbcf62d1d-48179b7d"} ``` \ No newline at end of file