Spring Stomp Server is only a Spring-Boot-Application with a very simple Websocket-Stomp Configurion as described by the Spring Boot Guide:
https://spring.io/guides/gs/messaging-stomp-websocket/
For e2e tests with angular, a Mock-Websocket-Stomp server is needed to also automatically test the Websocket functionality.
The benefit to use Spring Stomp Server as mock websocket endpoint is:
“Spring Stomp Server” should never be used on a Production System! It is only designed to be used as simple Mock-Server for automatic tests.
the usage can be summerized into two steps:
java -jar
”-D...
” AND/OR by YAML “spring-stomp-server.yaml
”The best way is, to use maven for downloading the artifact:
package.json:
"scripts": { ... "stomp-server:download": "mvn org.apache.maven.plugins:maven-dependency-plugin:3.0.0:copy -Dartifact=net.brabenetz.app:spring-stomp-server:1.0.0 -DoutputDirectory=./target -Dmdep.stripVersion=true", ... },
(Benefit for maven: maven has a local repository where the artifacts are cached. So download will only be done once for all your projects)
Alternative download with wget:
package.json:
"scripts": { ... "stomp-server:download": "wget https://repo1.maven.org/maven2/net/brabenetz/app/spring-stomp-server/1.0.0/spring-stomp-server-1.0.0.jar -O ./target/spring-stomp-server.jar", ... },
TIP: This step can be add as post install script:
package.json:
"scripts": { "postinstall": "npm run stomp-server:download", ... "stomp-server:download": "...", ... },
This will execute automatically after “npm install”.
package.json:
"scripts": { ... "stomp-server": "java -jar ./target/spring-stomp-server.jar ", ... },
With that, the Websocket endpoint will be ws:/localhost:8182/websocket
And the Stomp Config will listen on all destinations with the prefixes “/topic”, “/app”, “/user”.
For local development you can simply start the server in the background by “npm run stomp-server
”.
For e2e tests, you can do it with the npm package ‘concurrently’:
package.json:
"scripts": { ... "e2e": "concurrently -s first -k --names \"STOMP-SERVER,ANGULAR-CLI\" --prefix \"[{name}]\" \"npm run stomp-server\" \"npm run e2e:ng\"", "e2e:ng": "ng e2e", ... },
The preferd way to apply a custom config is by System-Properties “-D...
” AND/OR by YAML “spring-stomp-server.yaml
”.
(There are more ways, see: https://www.tutorialspoint.com/spring_boot/spring_boot_application_properties.htm )
If a property exists as SystemProperty AND in YAML, the SystemProperty wins.
A detailed description for the most relevant properties can be found in:
https://brabenetz.github.io/spring-stomp-server/archiv/latest/configuration.html
package.json:
"scripts": { ... "stomp-server": "java -jar -Dserver.port=8182 -Dspring-stomp-server.destination-prefixes=/topic,/app,/user -Dspring-stomp-server.websocket-endpoints=/my-backend-app/websocket ./target/spring-stomp-server.jar ", ... },
With that, the Websocket endpoint will be ws:/localhost:8182/my-backend-app/websocket
And the Stomp Config will listen on all destinations with the prefixes “/topic”, “/app”, “/user”.
package.json:
"scripts": { ... "stomp-server": "java -jar ./target/spring-stomp-server.jar ", ... },
spring-stomp-server.yaml: (in same folder as package.json)
server.port: 8182 spring-stomp-server: websocket-endpoints: - "/my-backend-app/websocket" destination-prefixes: - "/topic" - "/app" - "/user"
With that, the Websocket endpoint will be ws:/localhost:8182/my-backend-app/websocket
And the Stomp Config will listen on all destinations with the prefixes “/topic”, “/app”, “/user”.
For More information about the configurations see JavaDoc: WebSocketConfigProperties.java