Spring Community provides two complementary ways to interact with event chat messages. The REST endpoint (Documentation Index
Fetch the complete documentation index at: https://mintlify.com/CristianRR94/springCommunity/llms.txt
Use this file to discover all available pages before exploring further.
GET /api/eventos/{eventoId}/mensajes) lets you fetch the full persisted history of messages for a given event — useful on initial page load or when reconnecting after a network drop. The WebSocket endpoint (/ws-chat, STOMP protocol) delivers messages in real time as participants send them, keeping all connected clients in sync without polling. Both mechanisms use the same HistorialMensajesDTO shape for the message payload, so you can render history and live messages with a single component.
REST — Get Chat History
Fetches all persisted messages for a specific event in chronological order. This endpoint is the recommended way to populate a chat view on load before the WebSocket connection is established.GET /api/eventos/{eventoId}/mensajes
Authentication: Bearer ACCESS token required in theAuthorization header.
Path parameters
The numeric ID of the event whose chat history you want to retrieve.
Response fields
The endpoint returns an array ofHistorialMensajesDTO objects.
Unique identifier of the persisted message record.
The text content of the message. Maximum 1 000 characters.
ID of the participant who sent the message.
Display name of the sender at the time the message was stored.
ISO 8601 datetime string recording when the message was persisted, e.g.
2025-06-01T14:30:00. Derived from the LocalDateTime stored on the
Mensaje entity via TimestampEntity.Response example
Error responses
| Status | Condition |
|---|---|
401 Unauthorized | Token is missing, expired (ExpiredJwtException), or has an invalid signature (SignatureException / MalformedJwtException). |
404 Not Found | No event exists with the given eventoId (EventoNotFoundException). |
curl
WebSocket — Send and Receive Messages in Real Time
The real-time chat layer is built on STOMP over WebSocket. Clients connect to the/ws-chat endpoint, subscribe to a per-event topic, and publish messages to an application destination. The server persists each incoming message via MensajeService.guardarMensaje and immediately broadcasts the stored HistorialMensajesDTO to all subscribers of that event’s topic.
WebSocket endpoint: ws://localhost:8080/ws-chat (STOMP)
Subscribe to receive messages: /topic/evento/{eventoId}
Publish to send a message: /app/chat/{eventoId}
Authentication
Send the bearer token as a header in the STOMP CONNECT frame:connectHeaders in the STOMP.js client (see example below).
Sending a message — MensajeDTO fields
Publish a JSON-serialisedMensajeDTO to /app/chat/{eventoId}.
The text content of the message. Must not be blank. Maximum 1 000 characters.
Validated server-side with
@NotBlank and @Size(max=1000); a violation
returns a 400 Bad Request error frame.Display name of the sending participant. Used for display purposes within the
broadcast payload.
ID of the participant sending the message.
ID of the event this message belongs to. Should match the
{eventoId} in the
destination path.Broadcast payload
After the server persists the message it broadcasts aHistorialMensajesDTO to /topic/evento/{eventoId}. All clients subscribed to that topic receive it immediately. The shape is identical to the REST history response:
| Field | Type | Description |
|---|---|---|
id | Long | Auto-generated ID of the persisted message. |
texto | string | Message content. |
participanteId | Long | ID of the sender’s participant record. |
nombreParticipante | string | Display name of the sender. |
fechaEnvio | string | ISO 8601 datetime when the message was saved. |
JavaScript example (STOMP.js)
The following example uses the@stomp/stompjs library to connect, subscribe to event 1, and publish a message.
Replace
<accessToken> with the JWT string obtained from the authentication
flow. The eventoId in the subscribe path and the destination path must
match the event whose chat you want to join. Subscribing to
/topic/evento/1 will not deliver messages published to /app/chat/2.Error handling
| Scenario | Behaviour |
|---|---|
| Expired or invalid token at connect time | JwtChannelInterceptor rejects the CONNECT frame; the WebSocket connection is closed. |
texto blank or over 1 000 characters | Server returns a STOMP ERROR frame with a 400 Bad Request message derived from the @NotBlank / @Size constraint annotations on MensajeDTO. |
Unknown eventoId | EventoNotFoundException is thrown server-side; the message is not persisted and not broadcast. |