Ferromax ERP publishes real-time stock update events over WebSocket using the STOMP protocol with SockJS fallback. The frontend ERP dashboard subscribes to these events to refresh stock alerts and KPIs without polling — whenever a sale is completed or stock is adjusted, every connected client receives a lightweight event describing what changed. The server is built with Spring WebSocket (Documentation Index
Fetch the complete documentation index at: https://mintlify.com/DragonesMagicos/ferromax_v0.8/llms.txt
Use this file to discover all available pages before exploring further.
@EnableWebSocketMessageBroker) and an in-memory simple broker.
Connection Details
| Property | Value |
|---|---|
| SockJS endpoint | http://localhost:8081/api/ws |
| Protocol | STOMP over SockJS |
| Topic prefix | /topic |
| Application destination prefix | /app |
| Server port | 8081 (configured via server.port) |
| Context path | /api (configured via server.servlet.context-path) |
Subscribing to Stock Updates
Use the@stomp/stompjs client (v7) with sockjs-client to connect and subscribe to the /topic/stock-update destination. The onConnect callback fires after the STOMP handshake completes — subscribe to topics only inside this callback.
useEffect cleanup):
Stock Update Event Shape
Each message published to/topic/stock-update carries a StockUpdateEvent serialized as JSON. The event is intentionally minimal — it identifies the product and its new stock level so subscribers can decide locally whether to re-fetch alert data.
The unique ID of the product whose stock changed.
The product’s SKU code, e.g.
"TALAD-BOSCH-500". Useful for correlating the event with locally cached catalog data without an extra lookup.The product’s stock quantity after the triggering operation was applied.
The event carries the post-operation stock value only. If you need the previous stock level (e.g. to animate a decrement counter), store the last known value in your component state and compare on receipt.
When Events Are Published
AStockUpdateEvent is broadcast to /topic/stock-update whenever any of the following operations mutate product stock:
- Sale registered — a call to
POST /api/ventascompletes successfully and stock is decremented for each sold item. - Stock adjustment applied — a call to
POST /api/ajustes-stockis processed (manual correction by an admin or employee). - Remito confirmed — an admin confirms a supplier delivery note via
PATCH /api/recepciones-remito/{id}/confirmar, increasing stock for received items. - Direct goods receipt processed — a call to
POST /api/recepcionregisters a direct inventory intake.
stockActual in the event is the durable value.
Allowed Origins
TheWebSocketConfig registers the /ws SockJS endpoint. The allowed origins are controlled by the app.websocket.allowed-origins property in application.properties. The default development configuration permits:
application.properties:
WebSocketConfig.java to read the property instead of using the wildcard pattern:
Authentication
The WebSocket SockJS endpoint (/api/ws) is currently public — no JWT token is required to establish a connection. Topic subscriptions are also public: StockUpdateEvent messages are broadcast to all connected clients regardless of their authentication status.
This is intentional for the Tienda storefront (which needs real-time availability updates without requiring a login), but means internal stock data is visible to any connected browser tab.
If you need to restrict stock events to authenticated ERP users only, add a ChannelInterceptor to the inbound channel that validates the Authorization STOMP header against the JWT filter chain. See the Spring Security WebSocket documentation for implementation guidance.