-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
3b6e76c
commit afb68d0
Showing
32 changed files
with
3,453 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
# Ballerina WebSockets Test Examples | ||
|
||
## Overview | ||
|
||
This is a set of Ballerina WebSocket test examples. The examples demonstrates how to use the AsyncAPI tools to generate the specification from a Ballerina WebSocket service and how to use the generated specification to create a Ballerina WebSocket client. Moreover, the examples demonstrate how to use the generated WebSockets client to write a simple client application. | ||
|
||
## Generating the AsyncAPI specification | ||
|
||
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 | ||
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. | ||
|
||
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. | ||
|
||
You can regenerate the client using the following command: | ||
|
||
```bash | ||
bal asyncapi --protocol ws -i asyncapi.yaml | ||
``` | ||
|
||
You can run the server and client using the following commands: | ||
|
||
```bash | ||
bal run server | ||
bal run client | ||
``` | ||
|
||
## A client-server example with a dispatcher stream id | ||
|
||
The same application can be run with a dispatcher stream id using the `client-with-dispatcherStreamId` package and the `server-with-dispatcherStreamId` package. |
8 changes: 8 additions & 0 deletions
8
samples/basic-chat/client-with-dispatcherStreamId/Ballerina.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
[package] | ||
org = "wso2" | ||
name = "test_websocket" | ||
version = "0.1.0" | ||
distribution = "2201.9.0" | ||
|
||
[build-options] | ||
observabilityIncluded = true |
348 changes: 348 additions & 0 deletions
348
samples/basic-chat/client-with-dispatcherStreamId/Dependencies.toml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,348 @@ | ||
# AUTO-GENERATED FILE. DO NOT MODIFY. | ||
|
||
# This file is auto-generated by Ballerina for managing dependency versions. | ||
# It should not be modified by hand. | ||
|
||
[ballerina] | ||
dependencies-toml-version = "2" | ||
distribution-version = "2201.9.0" | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "auth" | ||
version = "2.11.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "crypto"}, | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "lang.array"}, | ||
{org = "ballerina", name = "lang.string"}, | ||
{org = "ballerina", name = "log"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "cache" | ||
version = "3.8.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "constraint"}, | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "task"}, | ||
{org = "ballerina", name = "time"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "constraint" | ||
version = "1.5.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "crypto" | ||
version = "2.7.2" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "time"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "file" | ||
version = "1.9.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "io"}, | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "os"}, | ||
{org = "ballerina", name = "time"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "http" | ||
version = "2.11.2" | ||
dependencies = [ | ||
{org = "ballerina", name = "auth"}, | ||
{org = "ballerina", name = "cache"}, | ||
{org = "ballerina", name = "constraint"}, | ||
{org = "ballerina", name = "crypto"}, | ||
{org = "ballerina", name = "file"}, | ||
{org = "ballerina", name = "io"}, | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "jwt"}, | ||
{org = "ballerina", name = "lang.array"}, | ||
{org = "ballerina", name = "lang.decimal"}, | ||
{org = "ballerina", name = "lang.int"}, | ||
{org = "ballerina", name = "lang.regexp"}, | ||
{org = "ballerina", name = "lang.runtime"}, | ||
{org = "ballerina", name = "lang.string"}, | ||
{org = "ballerina", name = "lang.value"}, | ||
{org = "ballerina", name = "log"}, | ||
{org = "ballerina", name = "mime"}, | ||
{org = "ballerina", name = "oauth2"}, | ||
{org = "ballerina", name = "observe"}, | ||
{org = "ballerina", name = "time"}, | ||
{org = "ballerina", name = "url"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "io" | ||
version = "1.6.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "lang.value"} | ||
] | ||
modules = [ | ||
{org = "ballerina", packageName = "io", moduleName = "io"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "jballerina.java" | ||
version = "0.0.0" | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "jwt" | ||
version = "2.12.1" | ||
dependencies = [ | ||
{org = "ballerina", name = "cache"}, | ||
{org = "ballerina", name = "crypto"}, | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "lang.int"}, | ||
{org = "ballerina", name = "lang.string"}, | ||
{org = "ballerina", name = "log"}, | ||
{org = "ballerina", name = "time"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "lang.__internal" | ||
version = "0.0.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "lang.object"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "lang.array" | ||
version = "0.0.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "lang.__internal"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "lang.decimal" | ||
version = "0.0.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "lang.int" | ||
version = "0.0.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "lang.__internal"}, | ||
{org = "ballerina", name = "lang.object"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "lang.object" | ||
version = "0.0.0" | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "lang.regexp" | ||
version = "0.0.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "lang.runtime" | ||
version = "0.0.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "lang.string" | ||
version = "0.0.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "lang.regexp"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "lang.value" | ||
version = "0.0.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "log" | ||
version = "2.9.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "io"}, | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "lang.value"}, | ||
{org = "ballerina", name = "observe"} | ||
] | ||
modules = [ | ||
{org = "ballerina", packageName = "log", moduleName = "log"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "mime" | ||
version = "2.9.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "io"}, | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "lang.int"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "oauth2" | ||
version = "2.11.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "cache"}, | ||
{org = "ballerina", name = "crypto"}, | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "log"}, | ||
{org = "ballerina", name = "time"}, | ||
{org = "ballerina", name = "url"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "observe" | ||
version = "1.2.3" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "os" | ||
version = "1.8.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "io"}, | ||
{org = "ballerina", name = "jballerina.java"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "task" | ||
version = "2.5.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "time"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "time" | ||
version = "2.4.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "url" | ||
version = "2.4.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "uuid" | ||
version = "1.8.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "crypto"}, | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "lang.int"}, | ||
{org = "ballerina", name = "time"} | ||
] | ||
modules = [ | ||
{org = "ballerina", packageName = "uuid", moduleName = "uuid"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerina" | ||
name = "websocket" | ||
version = "2.11.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "auth"}, | ||
{org = "ballerina", name = "constraint"}, | ||
{org = "ballerina", name = "http"}, | ||
{org = "ballerina", name = "io"}, | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "jwt"}, | ||
{org = "ballerina", name = "lang.array"}, | ||
{org = "ballerina", name = "lang.runtime"}, | ||
{org = "ballerina", name = "lang.string"}, | ||
{org = "ballerina", name = "lang.value"}, | ||
{org = "ballerina", name = "log"}, | ||
{org = "ballerina", name = "oauth2"}, | ||
{org = "ballerina", name = "time"} | ||
] | ||
modules = [ | ||
{org = "ballerina", packageName = "websocket", moduleName = "websocket"} | ||
] | ||
|
||
[[package]] | ||
org = "ballerinai" | ||
name = "observe" | ||
version = "0.0.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"}, | ||
{org = "ballerina", name = "observe"} | ||
] | ||
modules = [ | ||
{org = "ballerinai", packageName = "observe", moduleName = "observe"} | ||
] | ||
|
||
[[package]] | ||
org = "haritha" | ||
name = "test_websocket" | ||
version = "0.1.0" | ||
dependencies = [ | ||
{org = "ballerina", name = "io"}, | ||
{org = "ballerina", name = "log"}, | ||
{org = "ballerina", name = "uuid"}, | ||
{org = "ballerina", name = "websocket"}, | ||
{org = "ballerinai", name = "observe"}, | ||
{org = "xlibb", name = "pipe"} | ||
] | ||
modules = [ | ||
{org = "haritha", packageName = "test_websocket", moduleName = "test_websocket"} | ||
] | ||
|
||
[[package]] | ||
org = "xlibb" | ||
name = "pipe" | ||
version = "1.4.1" | ||
dependencies = [ | ||
{org = "ballerina", name = "jballerina.java"} | ||
] | ||
modules = [ | ||
{org = "xlibb", packageName = "pipe", moduleName = "pipe"} | ||
] | ||
|
Oops, something went wrong.