Messaging With STOMP Over WebSockets using Spring Angular ActiveMQ

Web Socket

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

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


ActiveMQ 5.15.9/5.18.3, Netty API, ActiveMQ API, ActiveMQ STOMP API

Spring Boot WebSocket Angular Example

Configuring ActiveMQ

Please look at the tutorial how to configure ActiveMQ.

Project Setup

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

For the maven based project you can use the following pom.xml file:

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns=""








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

I have enabled stompBrokerRelay with ActiveMQ host and port.

public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {

	public void registerStompEndpoints(StompEndpointRegistry registry) {
		// registry.addEndpoint("/websocket").setAllowedOrigins("*").withSockJS(); //
		// spring boot 2.x.x
		registry.addEndpoint("/websocket").setAllowedOrigins("http://localhost:4200").withSockJS(); // spring boot 3.x.x

	public void configureMessageBroker(MessageBrokerRegistry config) {


You don’t need to update the client application.

Running ActiveMQ Broker

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

\apache-activemq-5.xy.z\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 Example.

Source Code


1 thought on “Messaging With STOMP Over WebSockets using Spring Angular ActiveMQ

Leave a Reply

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