package com.iqser.red.service.persistence.management.v1.processor.service.websocket;

import org.springframework.messaging.simp.SimpMessagingTemplate;

import com.fasterxml.jackson.databind.ObjectMapper;

import lombok.RequiredArgsConstructor;
import lombok.SneakyThrows;

@RequiredArgsConstructor
public class RedisPubsubReceiver {

    private final SimpMessagingTemplate websocketTemplate;
    private final ObjectMapper mapper;

    @SneakyThrows
    public void receiveMessage(String message) {
        var data = mapper.readValue(message, WebSocketMessage.class);
        websocketTemplate.convertAndSend(data.getTopic(), data.getMessage());
    }

}