What is the major difference between SimpMessageHeaderAccessor vs StompHeaderAccessor Spring + java

May 2024 · 2 minute read

What is the major difference between SimpMessageHeaderAccessor vs StompHeaderAccessor Web Socket Spring?

Please explain elaborately if you know about this?

0

2 Answers

This has a simple answer: SimpMessageHeaderAccessor is the parent of StompHeaderAccessor.

That is, StompHeaderAccessor is used exclusively for STOMP headers while SimpMessageHeaderAccessor is used for all messaging protocol headers, including STOMP.

STOMP is one of the simpler types of messaging protocol - it's text based, making it a little similar to how HTTP works and allows for communication using multiple languages and platforms. But it cannot be used for queuing and topics.

Further reading:

  • http://jmesnil.net/stomp-websocket/doc/
  • https://blogs.vmware.com/vfabric/2013/02/choosing-your-messaging-protocol-amqp-mqtt-or-stomp.html
  • Its important to understand the STOMP protocol, its design and format to better understand the API and the classes related.

    STOMP´s interoperable wire format allows clients to communicate with number of message brokers. Since its language agnostic, clients and brokers developed in different languages can send and receive messages to each other.

    STOMP complient message brokers are here.

    STOMP is text-based and does not use binary protocols. It supports a range of core enterprise messaging features, such as authentication, messaging models like P2P & publish and subscribe, message acknowledgement, transactions, message headers & properties, etc.,

    So while you use Spring Messaging framework to build client and server side Messaging platforms and applications, the package org.springframework.messaging.simp has generic support for Simple message protocols, STOMP is ONE of them.

    As a base class of StompHeaderAccessor, can use SimpMessageHeaderAccessor for generic message header properties and use StompHeaderAccessor for STOMP specific properties like ContentLength, createForHeartbeat(), isHeartbeat() etc., and STOMP messaging API specific methods like updateStompCommandAsClientMessage(), updateStompCommandAsServerMessage(), wrap(Message<?> message).

    Good examples on using StompHeaderAccessor can be found here. A good working example of using both SimpMessageHeaderAccessor and StompHeaderAccessor is available in this blog.

    ncG1vNJzZmirpJawrLvVnqmfpJ%2Bse6S7zGiorp2jqbawutJoa29pY22FdH2OsJ%2BarF2ewG7Ax55kppmapL9usMifnZ6qlaOwpnnBnquwnZWjerS1zKmknqujlrSmtMSam56qkZiwpr%2FSqKlmrqNiwLW7zKmfnpmUmr%2Bir8I%3D