Untitled

 avatar
unknown
plain_text
2 months ago
1.2 kB
3
Indexable
package com.hdfc.epi.lib.controller;

import com.hdfc.epi.lib.service.SSEService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

@Slf4j
@RestController
public class SSEController {

    @Autowired
    private SSEService sseService;

    // Endpoint to start the SSE stream for a specific client
    @GetMapping("/stream")
    public SseEmitter stream(@RequestParam String ulId) {
        log.info("Starting SSE stream for client with ulId: {}", ulId);
        return sseService.handler(ulId);
    }

    // Endpoint to send a callback with a status to the specific client
    @GetMapping("/callback")
    public String callback(@RequestParam String ulId, @RequestParam String status) {
        log.info("Received callback for client with ulId: {}, status: {}", ulId, status);
        sseService.publishToEmitter(ulId, status);
        return "Callback sent to client with ulId: " + ulId;
    }
}
Editor is loading...
Leave a Comment