Messaging with STOMP over WebSockets using Spring, Angular 8 and ActiveMQ


We will create push notify messaging with STOMP over WebSockets using Spring and ActiveMQ. We have seen similar tutorial at link, but we used in-memory message broker but here we will use external message broker – ActiveMQ. We will use Angular 8 for building front end or UI where message will be updated and displayed.

We will use the same tutorial with some modification to the existing code.


ActiveMQ 5.15.9, Netty API, ActiveMQ API, ActiveMQ STOMP API

Spring Boot WebSocket Angular 8 Gradle Example

Configuring ActiveMQ

Please look at the tutorial how to configure ActiveMQ.

Updating Build Script

I am assuming that you are following the same tutorial at Spring Boot WebSocket Angular 8 Gradle Example .

Update the build.gradle file with the following content.

buildscript {
	ext {
		springBootVersion = '2.1.8.RELEASE'
    repositories {
    dependencies {

apply plugin: 'java'
apply plugin: 'org.springframework.boot'

sourceCompatibility = 12
targetCompatibility = 12

repositories {
    maven {
    	url ''

dependencies {

Updating POJO

Update the POJO class Message to implement Serializable interface as we are going to use external message broker – ActiveMQ.

package com.roytuts.spring.websocket.vo;


public class Message implements Serializable {

	private static final long serialVersionUID = 1L;

	private String msg;

	public Message(String msg) {
		this.msg = msg;

	public String getMsg() {
		return msg;


Updating WebSocket Configuration

Updating WebSocket configuration class WebSocketConfig for configuring ActiveMQ with STOMP.

We enable stompBrokerRelay with ActiveMQ host and port.

package com.roytuts.spring.websocket.config;

import org.springframework.context.annotation.Configuration;
import org.springframework.messaging.simp.config.MessageBrokerRegistry;
import org.springframework.web.socket.config.annotation.EnableWebSocketMessageBroker;
import org.springframework.web.socket.config.annotation.StompEndpointRegistry;
import org.springframework.web.socket.config.annotation.WebSocketMessageBrokerConfigurer;

public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

	public void registerStompEndpoints(StompEndpointRegistry registry) {

	public void configureMessageBroker(MessageBrokerRegistry config) {

You don’t need to update on client application.

Running ActiveMQ Broker

Execute command from command line tool after navigating to the appropriate bin directory of ActiveMQ 5.15.9.

\apache-activemq-5.15.9\bin\start activemq

Related Posts:

Testing the Application

Make sure you run the server application followed by client application.

Then your client application will open at http://localhost:4200 in the browser and you will see the similar kind of message as you had seen for the output of Spring Boot WebSocket Angular 8 Gradle Example.

Source Code

download source code

Thanks for reading.

1 thought on “Messaging with STOMP over WebSockets using Spring, Angular 8 and ActiveMQ

Leave a Reply

Your email address will not be published. Required fields are marked *