Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: mqtt event handler #34

Merged
merged 31 commits into from
Aug 2, 2021
Merged
Show file tree
Hide file tree
Changes from 19 commits
Commits
Show all changes
31 commits
Select commit Hold shift + click to select a range
16fef18
added question for choosing server in cli
NektariosFifes Jul 15, 2021
eaf4985
initial
NektariosFifes Jul 23, 2021
1a7f1e2
now able to specify payload and parameters for channel url.
NektariosFifes Jul 25, 2021
0a2caf5
eslint warnings fix
NektariosFifes Jul 26, 2021
94cd7fe
Merge branch 'master' into mqtt_event_handler
NektariosFifes Jul 26, 2021
e2e53c4
fixes in cli. Refactored Code.
NektariosFifes Jul 27, 2021
87aad76
fixes in cli. Refactored Code.
NektariosFifes Jul 27, 2021
bc40e87
Merge remote-tracking branch 'origin/mqtt_event_handler' into mqtt_ev…
NektariosFifes Jul 27, 2021
fe41e99
fix
NektariosFifes Jul 27, 2021
8a6ef79
fix eslint warnings
NektariosFifes Jul 27, 2021
0eb4262
fix empty block statement.
NektariosFifes Jul 27, 2021
c5745dc
fixes + basepath feature
NektariosFifes Jul 28, 2021
4a25a9c
fixes
NektariosFifes Jul 29, 2021
bb59aae
fix in cli
NektariosFifes Jul 29, 2021
a9a0bbe
fixes
NektariosFifes Jul 29, 2021
ff5f9ec
added message for unsupported Protocol
NektariosFifes Jul 29, 2021
4890e52
fix in README.md
NektariosFifes Jul 29, 2021
de601c7
minor fix
NektariosFifes Jul 29, 2021
a3eaa67
fix in description
NektariosFifes Jul 29, 2021
858f1b2
Update README.md
NektariosFifes Jul 30, 2021
ce855e7
Update README.md
NektariosFifes Jul 30, 2021
1877abc
Update package.json
NektariosFifes Jul 30, 2021
1274cbc
Update src/bin/cli.js
NektariosFifes Jul 30, 2021
f5b6195
Update src/RequestHandler/mqttHandler.js
NektariosFifes Jul 30, 2021
32fe4a2
fixes
NektariosFifes Jul 30, 2021
a810ce0
fixe
NektariosFifes Jul 30, 2021
97300a1
extra line fix
NektariosFifes Jul 30, 2021
c78295d
fix in README.md
NektariosFifes Jul 30, 2021
078ff81
removed unused file
NektariosFifes Jul 30, 2021
6823cc8
added error handling for unsupported protocol and incorrect value of …
NektariosFifes Jul 30, 2021
d31e1fa
change in unknown protocol handling
NektariosFifes Aug 2, 2021
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 2 additions & 6 deletions .eslintrc
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@

env:
node: true
es6: true
mocha: false

mocha: true

plugins:
- sonarjs
Expand All @@ -16,9 +14,7 @@ extends:
- plugin:security/recommended

parserOptions:
ecmaVersion: 2018
ecmaFeatures:
experimentalObjectRestSpread: true
ecmaVersion: 2020

rules:
# Ignore Rules
Expand Down
53 changes: 50 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,14 +1,19 @@
# AsyncApi Performance Tester
# AsyncApi Simulator
___

In development

---

Ever wondered what it would feel like your application to
be the center of interest?

Does it seem distant or difficult to switch from development mode
to production mode?

#### Define and simulate high traffic
#### scenarios for your app and create statistics.
#### Define and simulate high traffic scenarios for your app and create statistics.
NektariosFifes marked this conversation as resolved.
Show resolved Hide resolved



Usage

Expand All @@ -17,6 +22,48 @@ simulator -f ./my_api.yaml -s ./scenario.yaml
simulator -f ../subdirectory/my_api.json -s ./scenario.json
```

Run sample application with --gameProcessor or by specifying the corresponding
asyncApi and scenario files.
NektariosFifes marked this conversation as resolved.
Show resolved Hide resolved
```
simulator -f ./example-projects/game-processor/asyncapi.yaml -s ./example-projects/game-processor/scenario.yaml
or
simulator -b ../ -f ./simulatorFolder/example-projects/game-processor/asyncapi.yaml -s ./simulatorFolder/example-projects/game-processor/scenario.yaml
```



### Cli

```
Options:
-v async-api performance tester cli version
-f, --filepath <type> The filepath of a async-api specification yaml or json asyncApiF
-s, --scenario <type> The filepath of a AsyncApi File defining a scenario based on the spec.
-b, --basedir <type> The basePath from which relative paths are computed.
Defaults to the root directory of the project.
-h, --help display help for command


```

### Supported Protocols

- mqtt

### AsyncApi File

The file where the api you want to test is defined. By specifying the x-plot: {id} field
under a channel will automatically make the channel available for sending requests.



### Scenario File

Here with the plot-{id} (where id is the same as the x-plot: {id} in the field you specified in the async api channel) field you:
NektariosFifes marked this conversation as resolved.
Show resolved Hide resolved
- Connect your asyncApi and scenario File.
- Specify the parameters for each channel and have the options for them to be randomly generated.
- Specify the payload you want to send.




81 changes: 41 additions & 40 deletions example-projects/game-processor/asyncapi.yaml
Original file line number Diff line number Diff line change
@@ -1,66 +1,67 @@
asyncapi: 2.0.0
info:
info:
title: "Processor"
version: "0.0.1"
version: "0.0.1"
license:
name: Apache 2.0
url: https://www.apache.org/licenses/LICENSE-2.0
servers:
local:
servers:
local:
url: "0.0.0.0:1883"
description: "Development server",
description: "Development server"
protocol: "mqtt"
defaultContentType: application/json
channels:
channels:
game/server/{serverId}/events/player/{playerId}/item/{itemId}/pickup:
x-plot: 1
description: Channel used when a player picks up an item in-game
parameters:
serverId:
$ref: "./AsyncAPI/components/Parameters.yaml#/serverId"
playerId:
$ref: "./AsyncAPI/components/Parameters.yaml#/playerId"
itemId:
$ref: "./AsyncAPI/components/Parameters.yaml#/itemId"
publish:
serverId:
$ref: "./example-projects/game-processor/AsyncAPI/components/Parameters.yaml#/serverId"
playerId:
$ref: "./example-projects/game-processor/AsyncAPI/components/Parameters.yaml#/playerId"
itemId:
$ref: "./example-projects/game-processor/AsyncAPI/components/Parameters.yaml#/itemId"
publish:
message:
$ref: './AsyncAPI/components/messages/PlayerItemPickup.yaml'
$ref: './example-projects/game-processor/AsyncAPI/components/messages/PlayerItemPickup.yaml'
game/server/{serverId}/events/player/{playerId}/connect:
description: Channel used when a player joins (connect to) the game server
parameters:
serverId:
$ref: "./AsyncAPI/components/Parameters.yaml#/serverId"
playerId:
$ref: "./AsyncAPI/components/Parameters.yaml#/playerId"
publish:
serverId:
$ref: "./example-projects/game-processor/AsyncAPI/components/Parameters.yaml#/serverId"
playerId:
$ref: "./example-projects/game-processor/AsyncAPI/components/Parameters.yaml#/playerId"
publish:
message:
$ref: './AsyncAPI/components/messages/PlayerConnected.yaml'
$ref: './example-projects/game-processor/AsyncAPI/components/messages/PlayerConnected.yaml'
game/server/{serverId}/events/player/{playerId}/disconnect:
description: Channel used when a player leaves (disconnects from) the game server
parameters:
serverId:
$ref: "./AsyncAPI/components/Parameters.yaml#/serverId"
playerId:
$ref: "./AsyncAPI/components/Parameters.yaml#/playerId"
publish:
serverId:
$ref: "./example-projects/game-processor/AsyncAPI/components/Parameters.yaml#/serverId"
playerId:
$ref: "./example-projects/game-processor/AsyncAPI/components/Parameters.yaml#/playerId"
publish:
message:
$ref: './AsyncAPI/components/messages/PlayerDisconnected.yaml'
game/server/{serverId}/events/player/{playerId}/chat:
$ref: './example-projects/game-processor/AsyncAPI/components/messages/PlayerDisconnected.yaml'
game/server/{serverId}/events/player/{playerId}/chat:
description: Channel used when a player writes something in chat
parameters:
serverId:
$ref: "./AsyncAPI/components/Parameters.yaml#/serverId"
playerId:
$ref: "./AsyncAPI/components/Parameters.yaml#/playerId"
publish:
serverId:
$ref: "./example-projects/game-processor/AsyncAPI/components/Parameters.yaml#/serverId"
playerId:
$ref: "./example-projects/game-processor/AsyncAPI/components/Parameters.yaml#/playerId"
publish:
message:
$ref: './AsyncAPI/components/messages/PlayerUsedChat.yaml'
game/server/{serverId}/events/player/{playerId}/hit:
$ref: './example-projects/game-processor/AsyncAPI/components/messages/PlayerUsedChat.yaml'
game/server/{serverId}/events/player/{playerId}/hit:
description: Channel used when a player hit another player in-game
parameters:
serverId:
$ref: "./AsyncAPI/components/Parameters.yaml#/serverId"
playerId:
$ref: "./AsyncAPI/components/Parameters.yaml#/playerId"
publish:
serverId:
$ref: "./example-projects/game-processor/AsyncAPI/components/Parameters.yaml#/serverId"
playerId:
$ref: "./example-projects/game-processor/AsyncAPI/components/Parameters.yaml#/playerId"
publish:
message:
$ref: './AsyncAPI/components/messages/PlayerHit.yaml'
$ref: './example-projects/game-processor/AsyncAPI/components/messages/PlayerHit.yaml'
4 changes: 2 additions & 2 deletions example-projects/game-processor/config.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ module.exports = {
mongodbPlayerHitCollection: "playerHit",
mongodbDisconnectsCollection: "disconnects",
mongodbChatCollection: "chat",
mqttHost: process.env.mqttHost || "tcp://0.0.0.0:1883"
};
mqttHost: process.env.mqttHost || "tcp://0.0.0.0:1883"
};
3 changes: 1 addition & 2 deletions example-projects/game-processor/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ async function saveToCollection(persistentLogId, collection, data) {
}
/**
* Short code for matching simple wildcards for topic and parameter separation
*
*
* https://stackoverflow.com/a/32402438/6803886
*/
function matchRuleShort(str, rule) {
Expand Down Expand Up @@ -72,7 +72,6 @@ async function start() {
console.log(`Got message on topic ${topic}`)
// message is Buffer
const parsedMessage = JSON.parse(message.toString())

// Naive approach to finding parameters, but it will have to do for now.
const topicSplit = topic.split('/')
if (matchRuleShort(topic, 'game/server/*/events/player/*/chat')) {
Expand Down
11 changes: 11 additions & 0 deletions example-projects/game-processor/scenario.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
version: 0.0.1
plot-1:
eps: 1
priority: 2
payload:
test:
subtest: '2'
parameters:
serverId: '1'
playerId: '5'
itemId: '3'
Loading