Consuming WebSocket messages from the web page

With everything configured on the server, it's time to wire things up in the client. Because JavaScript has a WebSocket API, and we aren't using subprotocols such as Simple (or Streaming) Text Oriented Message Protocol (STOMP), we don't need any extra libraries.

So we can augment our Thymeleaf template, index.html. It's important to point out that our template is in the images microservice, not the chat microservice we just created. Add the following chunk of code toward the bottom of the HTML:

    <script th:inline="javascript"> 
        /*<![CDATA[*/ 
        (function() { 
            ... custom JavaScript code here... 
        })(); 
        /*]]>*/ 
    </script> 

This preceding chunk of code can be explained as follows:

  • The HTML <script> tag ...

Get Learning Spring Boot 2.0 - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.