package com.zt.plat.module.qms.iot.tcpserver.cluster;

import lombok.extern.slf4j.Slf4j;
import org.redisson.api.RTopic;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import tech.zzjc.tio.server.ServerTioConfig;

import static com.zt.plat.module.qms.iot.tcpserver.cluster.TioServerMessageConfig.SERVER_CLUSTER_TOPIC_CHANNEL;

@Service
@Slf4j
public class TioServerMessagePublisher {

    @Autowired
    private RedissonClient redissonClient;
    @Autowired
    private InstanceIdProvider instanceIdProvider; // 注入实例ID提供者



    public void publish(TioServerMessageVo message) {
        message.setSenderInstanceId(instanceIdProvider.getInstanceId());
        RTopic topic = redissonClient.getTopic(SERVER_CLUSTER_TOPIC_CHANNEL);
        topic.publish(message);
        log.error("[Publisher] 已发布消息: " + message);


    }


}
