package com.unis.crk.mq.pub;

import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 发布服务
 *
 * @author ybw
 * @version V1.0
 * @className PublishService
 * @date 2024/5/9
 **/
@Service
public class PublishService {
    @Resource
    private RedisTemplate<String, Object> redisTemplate;


    /**
     * 发送消息到指定频道
     *
     * @param topic   主题
     * @param message 消息
     * @methodName: sendMessage
     * @return: void
     * @author: ybw
     * @date: 2024/5/9
     **/
    public void sendMessage(String topic, Object message) {
        // 发送消息到指定topic
        redisTemplate.convertAndSend(topic, message);
    }

    public void setKey(String key, Object value) {
        redisTemplate.opsForValue().set(key, value);
    }

    public Object getKey(String key) {
        return redisTemplate.opsForValue().get(key);
    }
}
