All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.github.rexsheng.springboot.faster.system.notice.adapter.NoticeSSE Maven / Gradle / Ivy

The newest version!
package com.github.rexsheng.springboot.faster.system.notice.adapter;

import com.github.rexsheng.springboot.faster.logging.RequestLog;
import com.github.rexsheng.springboot.faster.sse.SseServer;
import com.github.rexsheng.springboot.faster.system.notice.application.NoticeService;
import com.github.rexsheng.springboot.faster.system.utils.AuthenticationUtil;
import jakarta.annotation.Resource;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Lazy;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;

import java.io.IOException;
import java.util.UUID;

@RestController
@RequestMapping("/sys/notice")
@ConditionalOnProperty(prefix = "app.module.notice",name = "sse",havingValue = "true",matchIfMissing = false)
public class NoticeSSE {

    @Resource
    @Lazy
    private NoticeService noticeService;

    @Resource
    @Lazy
    private SseServer sseServer;

    @GetMapping("/connect")
//    @GetMapping(path="/connect",produces = {MediaType.TEXT_EVENT_STREAM_VALUE})
    @RequestLog(enabled = false)
    public SseEmitter connect() throws IOException {
        return sseServer.createConnect(AuthenticationUtil.currentUserId()+"_"+UUID.randomUUID().toString());
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy