您现在的位置是:Instagram刷粉絲, Ins買粉絲自助下單平台, Ins買贊網站可微信支付寶付款 >
02 redis發布訂閱常用命令(三分鐘讀懂redis數據庫)
Instagram刷粉絲, Ins買粉絲自助下單平台, Ins買贊網站可微信支付寶付款2024-05-06 10:17:09【】0人已围观
简介>常見操作命令如下表:如果客戶端希望知道自身消費到第幾條數據了,那么就需要記錄一下當前消費的消息ID,下次再次消費的時候就從上次消費的消息ID開始讀取數據即可。消費組中多了一個游標last_deliv
如果客戶端希望知道自身消費到第幾條數據了,那么就需要記錄一下當前消費的消息ID,下次再次消費的時候就從上次消費的消息ID開始讀取數據即可。
消費組中多了一個游標 last_delivered_id ,表示當前消費到了哪一條數據。同時所有的數據都是待處理消息( PEL ),只有消費者處理完畢之后使用 ack 指令告知redis服務器,數據才會從 PEL 中移除,確認后的消息就無法再次消費。
如果接收到的消息比較多,為了避免Stream過長,可以選擇指定Stream的最大長度,一旦到達了最大長度,就會從最早的消息開始清除,保證Stream中最新的消息。
spring-redis 發布訂閱模式:發布一條消息收到了兩條,重復監聽
當你看到這個文章時,想必已經了解了一些關于spring-redis發布訂閱方面的知識,如果你也遇到同樣的問題
那么請考慮spring在啟動時有沒有重復的加載配置文件
具體的方式可以在 AbstractApplicationContext 的 refresh() 方法中打斷點,如果走了兩次,說明配置文件加載了兩遍
而配置文件加載兩遍的原因是因為web.xml中DispatcherServlet和ContextLoaderLinistener 共用了 某些配置文件導致的。
Spring Boot使用Redis進行消息的發布訂閱 原創
/
*** Redis 相關的配置,包含推送,以及對象編碼的定義
*/
@Configuration
public class RedisConfig {
public @Bean
RedisTemplate redisTemplate(RedisConnectionFactory 買粉絲nnectionFactory) {
RedisTemplate template = new RedisTemplate>();
template.setConnectionFactory(買粉絲nnectionFactory);
template.setDefaultSerializer(new GenericJackson2JsonRedisSerializer());
template.setKeySerializer(new StringRedisSerializer());
template.setHashKeySerializer(new GenericJackson2JsonRedisSerializer());
template.setValueSerializer(new GenericJackson2JsonRedisSerializer());
return template;
}
@Bean
ChannelTopic topic() {
return new ChannelTopic("messageQueue");
}
@Bean
RedisMessageListenerContainer 買粉絲ntainer(RedisConnectionFactory 買粉絲nnectionFactory,
MessageListenerAdapter listenerAdapter) {
RedisMessageListenerContainer 買粉絲ntainer = new RedisMessageListenerContainer();
買粉絲ntainer.setConnectionFactory(買粉絲nnectionFactory);
買粉絲ntainer.addMessageListener(listenerAdapter, new PatternTopic("messageQueue"));
return 買粉絲ntainer;
}
@Bean
MessageListenerAdapter listenerAdapter(Receiver receiver) {
return new MessageListenerAdapter(receiver, "receiveMessage");
}
}
public enum BusinessTypeEnum {
//修改SystemConfig緩存
UPDATE_SYSTEM_CONFIG;
}
//發布者接口
public interface MessagePublisher {
void publish(String message);
}
@Component
public class RedisMessagePublisher implements MessagePublisher{
private final static Logger logger = LoggerFactory.getLogger(RedisMessagePublisher.class);
@Autowired
private RedisTemplate redisTemplate;
@Autowired
private ChannelTopic topic;
@Override
public void publish(String message) {
logger.info("推送信息:"+message);
redisTemplate.買粉絲nvertAndSend(topic.getTopic(), message);
}
}
public interface Receiver { void receiveMessage(String message); }
@Component
public class MessageReceiver implements Receiver {
private final static Logger logger = LoggerFactory.getLogger(MessageReceiver.class);
@Autowired
private ISystemConfigService systemConfigService;
@Override
public void receiveMessage(String message) {
logger.info("消息接收:"+message);
JSONObject object = JSONObject.parseObject(message);
String businessType = object.getString("businessType");
logger.info("處理業務類型:businessType="+businessType);
if(BusinessTypeEnum.UPDATE_SYSTEM_CONFIG.toString().equals(businessType)){ //處理SystemConfig緩存
String jsonStr = object.getString("jsonStr");
if(jsonStr!=null&&!"".equals(jsonStr)){
JSONObject json = JSONObject.parseObject(object.getString("jsonStr"));
for(String key:json.keySet()){
String value = json.getString(key);
SystemConfig systemConfig = SystemConfigContainer.instance().getSystemConfig(key);
if(systemConfig!=null){
systemConfig.setKeyValue(value);
SystemConfigContainer.instance().uptSystemConfig(systemConfig);
}else{
systemConfig = systemConfigService.selectByPrimaryJianMing(key);
systemConfig.setKeyValue(value);
SystemConfigContainer.instance().uptSystemConfig(systemConfig);
}
}
}
}
}
}
redis頻道收到發布者信息后可以只推信息給一個訂閱者嗎
Redis 的 SUBSCRIBE 命令可以讓客戶端訂閱任意數量的頻道, 每當有新信息發送到被訂閱的頻道時, 信息就會被發送給所有訂閱指定頻道的客戶端。
作為例子, 下圖展示了頻道 channel1 , 以及訂閱這個頻道的三個客戶端 —— client2 、 client5 和 client1 之間的關系:
很赞哦!(3)
相关文章
- 01 youtube music love songs 80s with(杰西麥卡特尼Jesse McCartney 資料)
- 01 泉州兒童醫院買粉絲怎么查門診清單(泉州市兒童醫院的各項專科)
- 01 youtube music premium apk downloader官網(如何在youtubemusic中創建快捷指令)
- 01 法國十大貿易伙伴國家排名(世界貿易大國前十名)
- 01 youtube music r and b 80(來推薦點好聽的Rap吧`)
- 01 泉州海外交通博物館電話多少(泉州海外交通史博物館評論+地址+交通+電話)
- 01 youtube music on the app store apple(Apple Scheme URL Reference)
- 01 法國巴黎高等對外貿易學院(法國巴黎第一大學申請條件?)
- 01 youtube music premium apk cracked download(如何讓YTmusic在后臺播放)
- 01 youtube music premium download pc版官方下載(今日新聞淺談:Youtube Music 也加入串流音樂服務大混戰)
Instagram刷粉絲, Ins買粉絲自助下單平台, Ins買贊網站可微信支付寶付款的名片
职业:程序员,设计师
现居:内蒙古包头石拐区
工作室:小组
Email:[email protected]
热门文章
站长推荐
01 法國本土和海外領土(曾經強大的英國海外領土都紛紛獨立,為何法國海外領土還能保留這么多)
01 youtube music mod for pc(如何讓YTmusic在后臺播放)
01 youtube music pc app下載安裝大全(如何在youtubemusic中創建快捷指令)
01 法國在大洋洲的海外屬地(法國有哪些海外領地?)
01 youtube music pc ログイン(求幾首好聽的日語歌)
01 youtube music premium apk 2023 1.5.5(今日新聞淺談:Youtube Music 也加入串流音樂服務大混戰)
01 泉州佳萬貿易有限公司(2016年度福建十大杰出的青年企業家?)
01 油管和tiktok在國外哪個更火(油管和tiktok在國外哪個更火)