Spring Stomp Server

Spring Stomp Server for ui e2e Websocket testing

License

License

Categories

Categories

Net
GroupId

GroupId

net.brabenetz.app
ArtifactId

ArtifactId

spring-stomp-server
Last Version

Last Version

1.0.1
Release Date

Release Date

Type

Type

jar
Description

Description

Spring Stomp Server
Spring Stomp Server for ui e2e Websocket testing
Project URL

Project URL

http://spring-stomp-server.brabenetz.net
Project Organization

Project Organization

Brabenetz Harald, Austria
Source Code Management

Source Code Management

https://github.com/brabenetz/spring-stomp-server

Download spring-stomp-server

How to add to project

<!-- https://jarcasting.com/artifacts/net.brabenetz.app/spring-stomp-server/ -->
<dependency>
    <groupId>net.brabenetz.app</groupId>
    <artifactId>spring-stomp-server</artifactId>
    <version>1.0.1</version>
</dependency>
// https://jarcasting.com/artifacts/net.brabenetz.app/spring-stomp-server/
implementation 'net.brabenetz.app:spring-stomp-server:1.0.1'
// https://jarcasting.com/artifacts/net.brabenetz.app/spring-stomp-server/
implementation ("net.brabenetz.app:spring-stomp-server:1.0.1")
'net.brabenetz.app:spring-stomp-server:jar:1.0.1'
<dependency org="net.brabenetz.app" name="spring-stomp-server" rev="1.0.1">
  <artifact name="spring-stomp-server" type="jar" />
</dependency>
@Grapes(
@Grab(group='net.brabenetz.app', module='spring-stomp-server', version='1.0.1')
)
libraryDependencies += "net.brabenetz.app" % "spring-stomp-server" % "1.0.1"
[net.brabenetz.app/spring-stomp-server "1.0.1"]

Dependencies

compile (1)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter-websocket jar 2.3.1.RELEASE

test (2)

Group / Artifact Type Version
org.springframework.boot : spring-boot-starter-test jar 2.3.1.RELEASE
org.springframework.boot : spring-boot-configuration-processor Optional jar 2.3.1.RELEASE

Project Modules

There are no modules declared in this project.

Build Status Coverage Status Coverity Maven site License: Apache 2.0 Maven Central Javadocs

Spring Stomp Server

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/

Basic Idea

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:

  • Easy to use, even without java knowledge
  • Interoperability: works on linux, mac-os and windows the same way (only java 8 or higher is needed)
  • It is the most realistic way if your real enpoint is a spring-boot application

"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.

Integration into an angular application

the usage can be summerized into two steps:

  • download jar from the central Maven Repository
  • start the application with "java -jar"
  • custom config with System-Properties "-D..." AND/OR by YAML "spring-stomp-server.yaml"

download jar from the central Maven Repository

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".

start the application with java -jar

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",
    ...
  },

custom configuration

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

custom configuration with System-Properties

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".

custom configuration with spring-stomp-server.yaml

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".

More Details

Versions

Version
1.0.1
1.0.0