A Simple Chat Application With Javascript And ActiveMQ Using ...

Niklas Tech Blog

Just another Tech blog from a forgetful mind

A simple chat application with javascript and ActiveMQ using STOMP messaging

Posted by Niklas on January 8, 2022

Here is a small chat program that can be used for building a rich chat application, or if you just want a very simple chat program for your friends. It contains sending and receiving STOMP messages from an Apache ActiveMQ topic.

Prerequisites: * Apace ActiveMQ server which can be found here: https://activemq.apache.org/components/classic/download/ Usually no configuration needed. Just start the server (./activemq start) and everything should work ok * Stomp.js. A helper script for handling the WebSocket communication between ActiveMQ and your javascript application. This script can be found here, courtesy of Jeff Mesnil and Mark Broadbent: https://github.com/jmesnil/stomp-websocket/tree/master/lib

HTML:

<!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8"> <title>A simple ActiveMQ chat application</title> <script src="stomp.js"></script> <script src="index.js"></script> </head> <body> <textarea id="chat" rows="10" cols="35"></textarea> <br /> <input id="message" size="40" type="text"> <br /> <button id="send" type="button" onclick="send()">Send</button> </body> </html>

Javascript:

// Setup websocket connection const client = Stomp.client("ws://localhost:61614/stomp", "v11.stomp"); // Setup header options const headers = {id: 'JUST.FCX', ack: 'client'}; // Connect to ActiveMQ (via websocket) client.connect("admin", "admin", function () { // Setup subscription of topic (/topic/chat) client.subscribe("/topic/chat", function (message) { const msg = message.body; // Add message to textarea document.getElementById("chat").value += msg + "\n"; // Acknowledge the message message.ack(); }, headers); }); function send() { const message = document.getElementById("message"); // Send message to topic (/topic/chat) client.send("/topic/chat", {}, message.value); // Reset input field message.value = ""; }

Tested on OSX 10.15.7 and Apache ActiveMQ v5.16.3

ActiveMQActiveMQ, Javascript MySQL Docker helper script Testing a simple web app in Mule with JUnit

Comments are closed.

RSS Feed

Tags

ActiveMQ Apache Camel C/C++ Crystal Reports Docker Git Gradle H2 HTML IBM MQ java Javascript Jest JQuery JUnit5 Kotlin Kubernetes Linux Mac MIME Mockito Mule MySQL Objective-c OpenShift Oracle OSX Pervasive PHP Play Framework PostgreSQL REST Software testing Spring Boot Sqlite SSL/TLS SVN Trac Vim webMethods WebSphere MQ Windows XML XSD Zend Framework

Recent Posts

  • List supported Chiper Suits in Kong Gateway using kubectl
  • AMQP with mTLS with AMQPNETLite
  • Apache Camel OpenAPI Contract-First Example in SpringBoot
  • Example of the Builder Pattern in Java
  • Kubernetes: Reference a section or value inside a manifest

Categories

  • ActiveMQ (4)
  • C/C++ (5)
  • Cheat sheets (16)
  • Databases (21)
  • HTML (2)
  • IBM MQ (15)
  • IPhone (1)
  • Java (30)
  • Javascript (8)
  • Kotlin (1)
  • Kubernetes (1)
  • Linux (33)
  • Mac (13)
  • Misc (45)
  • Mule (3)
  • PHP (11)
  • Play Framework (4)
  • Software Engineering (2)
  • Software testing (3)
  • VCS (8)
  • webMethods (4)
  • Windows (6)
  • Zend Framework (13)

Meta

  • Log in
  • Entries feed
  • Comments feed
  • WordPress.org

Copyright © 2026 Niklas Tech Blog | Powered by zBench and WordPress

↑ Top

We are using cookies to give you the best experience on our website.

You can find out more about which cookies we are using or switch them off in settings.

Accept Close GDPR Cookie Settings Niklas Tech Blog
  • Privacy Overview
  • Strictly Necessary Cookies
  • 3rd Party Cookies
Powered by GDPR Cookie Compliance Privacy Overview

This website uses cookies so that we can provide you with the best user experience possible. Cookie information is stored in your browser and performs functions such as recognising you when you return to our website and helping our team to understand which sections of the website you find most interesting and useful.

Strictly Necessary Cookies

Strictly Necessary Cookie should be enabled at all times so that we can save your preferences for cookie settings.

Enable or Disable Cookies

If you disable this cookie, we will not be able to save your preferences. This means that every time you visit this website you will need to enable or disable cookies again.

3rd Party Cookies

This website uses Google Analytics to collect anonymous information such as the number of visitors to the site, and the most popular pages.

Keeping this cookie enabled helps us to improve our website.

Enable or Disable Cookies

Please enable Strictly Necessary Cookies first so that we can save your preferences!

Enable All Save Settings

Tag » Activemq Javascript