Spring Data Redis(Redis Messaging/PubSub)

Spring Boot 2.x基础教程:使用Redis的发布订阅功能 通过前面一篇集中式缓存的使用教程,我们已经了解了Redis的核心功能:作为K、V存储的高性能缓存。 接下来我们会分几篇来继续讲讲Redis的一些其他强大用法!如果你对此感兴趣,一定要关注收藏我哦! 发布订阅模式 如果你看过之前我写的关于MQ的相关文章,那么对于发布订阅功能应该不会陌生。如果没看过,那也不要紧,这里先做一个简单介绍,已经了解的可以跳过直接看下一节内容。 什么是发布订阅模式? 在发布订阅模式中有个重要的角色,一个是发布者Publisher,另一个订阅者Subscriber。本质上来说,发布订阅模 阅读详情

Redis Messaging/PubSub

Spring Data为 Redis提供了专用的消息传送集成,与Spring 框架集成JMS有相似的功能和命名方式;实际上,对Spring 支持的JMS 熟悉的用户,则很容易对Redis 的消息传送上手。

Redis messaging在功能上可以粗略的分为两个部分:生产/发布 和 消费/订阅,因此简称pubsub(Publish/Subscribe)。RedisTemplate这个类是用来生产消息的。对于异步接收,与JavaEE的消息驱动bean风格很相似,Spring Data提供了一个专用的消息监听容器,用来创建消息驱动POJOs(MDPs);对于同步接收,则由RedisConnecton contract。

对于使用Redis messaging 提供了核心的功能的类或接口,都在下面这两个包内:org.springframework.data.redis.connection 和 org.springframework.data.redis.listener 。

1. Sending/Publishing messages
发送/发布消息

要发布一个消息,你可以像其他操作一样,使用底层的RedisConnection 或高级别的RedisTemplate 。两个实体都提供了发布的方法,方法需要传递参数:要发送的消息和目的地通道。然而,RedisConnetion 需要传递的消息类型是原生的数据(字节数组),而RedisTemplate 则允许任意的 objects。

伪代码示例:

// send message through connection RedisConnection con = ...
byte[] msg = ...
byte[] channel = ...
con.publish(msg, channel); // send message through RedisTemplate
RedisTemplate template = ...
template.convertAndSend("hello!", "world");

2. Receiving/Subscribing for messages
接收/订阅消息

在接收端,你可以订阅一个或多个通道,通过直接命名或使用模式匹配。使用模式匹配的方式是相当有用的,它不仅仅可以用一个命令创建多个订阅,还可以监听在订阅的时候还没有创建的通道,只要它们匹配模式即可。

在底层,RedisConnection 提供了subscribe 和pSubscribe 方法,来对应Redis 的订阅命令,并由各自的模式来匹配各个通道。注意,大多数的通道或模式都被作为参数传递使用的。要改变一个连接的订阅,或者简单的查询是不是被订阅了,可以使用RedisConnection 的getSubscription 和isSubscribed 方法。

在Spring Data Redis 中订阅的命令是阻塞的。就是说,在一个连接上调用subscribe 方法,会阻塞当前线程来等待消息,否则只有在该订阅被取消的情况下该线程才会被释放,取消订阅必须由另外一个线程在同一个连接上调用unsubscribe 或者pUnsubscribe方法。要解决上面的问题需要查看下面的消息监听容器章节。

像上面提到的一样,一旦订阅了一个连接开始等待消息,在该连接上将不会调用其他命令,除了添加新的订阅 或 修改/取消一个存在的订阅。就是说,除了subscribe、pSubscribe、unsubscribe或者 pUnsubscribe,调用任何其他命令都是非法的,将抛出一个异常。

为了订阅消息,你需要实现MessageListener callback:每当一个新消息到了后,这个callbakc 将会被调用,在onMessage 方法中的用户的代码将会被执行。通过这个接口可以访问到:真实的消息、接收消息的通道、让订阅来匹配通道的模式(如果有的话)。这些信息可以供调用者来区分各式各样的消息,不仅仅可以通过内容还可以通过数据来进行。

Message Listener Containers

由于它具有阻塞的本性,低层次的订阅并不被人所关注,因为对于每个单独的监听都需要管理连接和线程。为了缓和这个问题,Spring Data提供了RedisMessageListenerContainer ,它代替用户做了所有的繁重的工作,熟悉EJB 和JMS 的用户可能会理解这个观念,它被设计的尽可能的被Spring 框架和它的消息驱动POJOs(MDPs)支持。

RedisMessageListenerContainer 作为一个消息监听容器;它被用来从Redis 通道接收消息,驱动所有注入到它里面的MessageListener。这个监听容器负责所有消息接收,然后发送到监听器进行处理。一个消息监听容器是一个MDP和一个消息提供者的中间媒介,它关心的是注册接收消息、资源的获取和释放、异常的转换等类似的事情。这允许应用开发者专心去写涉及到接收消息的业务逻辑(可能很复杂),让框架来关注Redis 底层的基础。

此外,为了最小化应用程序的内存占用,RedisMessageListenerContainer 允许一个连接和一个线程可以被多个监听器共享,即使它们不共享一个订阅都可以。因此无论一个应用有多少个监听器或通道,在它的生命周期内运行时的内存消耗都是一样的。此外,容器允许在运行的时候对配置信息进行修改,所以当应用运行中可以添加或删除监听器,而不用重启应用。加之容器还使用了懒订阅的方式,因此只有在需要的时候才使用RedisConnection ,如果所有的监听器都没有被订阅,会自动执行清除,释放掉所有的线程。

为了处理异步方式的消息,容器需要一个 java.util.concurrent.Executor ( 或者Spring 的TaskExecutor)来发送消息。依据机器的负载、监听器的数量或运行时的环境,你应该通过修改或设置执行器使它能更好的服务。尤其是在托管的环境下(像app服务),强烈的建议选择一个适当的TaskExecutor,使其在运行时能充分的发挥作用。

The MessageListenerAdapter

MessageListenerAdapter 这个类是Spring 异步消息发送支持的最后一个组件:简单的说,它允许你将几乎任何一个类转化为一个MDP(当然也有一些限制)。

考虑以下接口的定义。注意尽管这个接口不能继承MessageListener 接口,但它通过使用MessageListenerAdapter 这个类仍可以作为一个MDP。还要注意,依据可以接收和处理的各种消息类型的内容,各种消息的处理方法是如何强化类型的。此外,消息发送使用的通道或模式,以String类型作为第二个参数传入方法。

代码示例如下:

public interface MessageDelegate {
  void handleMessage(String message);
  void handleMessage(Map message); void handleMessage(byte[] message);
  void handleMessage(Serializable message);
  // pass the channel/pattern as well
  void handleMessage(Serializable message, String channel);
 }
public class DefaultMessageDelegate implements MessageDelegate {
  // implementation elided for clarity...
}

特别应该注意的是,上面的MessageDelegate 接口的实现类(如DefaultMessageDelegate )已经完全不依赖于Redis了。它只是一个POJO,我们将通过下面的配置将它变成一个MDP。

配置如下:

<?xml version="1.0" encoding="UTF-8"?>
 <beans xmlns="http://www.springframework.org/schema/beans"
   xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
   xmlns:redis="http://www.springframework.org/schema/redis"
   xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
   http://www.springframework.org/schema/redis http://www.springframework.org/schema/redis/spring-redis.xsd">

<!-- the default ConnectionFactory -->
<redis:listener-container>
  <!-- the method attribute can be skipped as the default method name is "handleMessage" -->
  <redis:listener ref="listener" method="handleMessage" topic="chatroom" />
</redis:listener-container>

<bean id="listener" class="redisexample.DefaultMessageDelegate"/>
 ...
<beans>
The listener topic can be either a channel (e.g. topic="chatroom") or a pattern (e.g. topic="*room")
监听器的主题可以是一个通道或一个模式。

上面示例使用Redis的命名空间声明了消息的监听器容器,并自动将POJOs注册为一个监听器。beans的定义展示如下:

<bean id="messageListener" class="org.springframework.data.redis.listener.adapter.MessageListenerAdapter">
  <constructor-arg>
    <bean class="redisexample.DefaultMessageDelegate"/>
  </constructor-arg>
</bean>

<bean id="redisContainer" class="org.springframework.data.redis.listener.RedisMessageListenerContainer">
  <property name="connectionFactory" ref="connectionFactory"/>
  <property name="messageListeners">
    <map>
      <entry key-ref="messageListener">
        <bean class="org.springframework.data.redis.listener.ChannelTopic">
          <constructor-arg value="chatroom">
        </bean>
      </entry>
    </map>
  </property>
</bean>

每收到一个消息,这个适配器会自动的执行转化(使用配置的RedisSerializer),显示的将低级的格式转化为需要的对象类型,或反之。方法调用引起的任何异常,将会被容器捕获并处理。

Spring Boot集成Redis实现keyevent监听 | Spring Cloud 33 Spring Boot集成Redis实现Key事件监听。 阅读详情

相关推荐

可变形卷积(Deformable Conv)原理解析与torch代码实现

图6为可变形卷积示意图。图1所示为普通卷积在输入特征图上进行卷积计算的过程,卷积核大小为3*3,在输入特征图尺寸为7*7上进行卷积,将卷积核权重与输入特征图对应位置元素相乘并求和得到输出特征图元素,按一定方式滑动窗口就能计算得到整张输出特征图。图6所示,在input feature map上普通卷积操作对应卷积采样区域是一个卷积核大小的正方形(绿框),而可变形卷积对应的卷积采样区域为一些蓝框表示的点,这就是可变形卷积与普通卷积的区别。先来一张图感受一下,图3为标准卷积与可变形卷积的卷积示例。

panghuzhenbang的博客 5万+

java.lang.NoClassDefFoundError: org/springframework/data/redis/connection/SubscriptionListener

报错如下图,从图中明显可以看到服务已经启动成功,测试redis链接,请求都是正常的。但在启动后有一次发布链接超时,从报错信息上看 是订阅读取超时。研究了一番,发现是包有冲突的问题导致的。将引用的包拆分,不在使用redisson-spring-boot-starter,redisson 这个包是我项目中通过redis的延时关单机制,使用到的。redis发布订阅只需要用到常规的spring-data-redis包。

aayygg1234的专栏 2100

如何使用Dify 搭建一个用自然语言查询数据库的 Agent?

这样就会发布完毕。

AI Agent 首席体验官 1707

解决SpringBoot启动报错:NoClassDefFoundError: org/springframework/data/redis/connection/RedisStreamCommands

22

dengchao1013的博客 1万+

安鸾渗透测试平台-CTF系列-bash

工具Xshell 公网VPS接收反弹shell Xshell新手的下载及安装教程(超详细)_新手程序员攀爬之路的博客-CSDN博客_xshell使用教程 Xshell连接后 #!/bin/bash cat ${0} while : do echo "$" read input output=`$input` 显示了一个文件,不过咋做呢?这里可能考察的是linux的语法 方法 输入bash 获得shell cat ${0} while : do .

AAAAAAAAAAAA66的博客 2692

Imputation Methods for scRNA Sequencing Data

越来越多的研究者使用单细胞RNA测序(scRNA-seq)技术来表征单细胞水平的转录图谱。他们用它来研究复杂组织的异质性、转录组动力学和未知生物的多样性。然而,在基因表达模式随机性的scRNA-seq数据中普遍存在许多技术和生物学上的噪音。这些数据通常具有高维、稀疏和大量“dropout”值的特点,并且受批处理效应的影响。scRNA-seq数据中大量的“dropout”值严重掩盖了基因之间的重要关系,阻碍了下游分析。因此,scRNA-seq数据dropout值的估算就显得尤为重要。

qq_34179307的博客 548

解决java.lang.NoClassDefFoundError: org/springframework/data/redis/connection/RedisStreamCommands

这是在 springboot 中使用 redisson 时,因为引入的依赖为 <dependency> <groupId>org.redisson</groupId> <artifactId>redisson-spring-boot-starter</artifactId> <version>3.14.0</version> </dependency> 这个...

哇哇哇,真的学到了!!! 1万+

【如何学习CAN总线测试】——AUTOSAR网络管理自动化测试(CAPL源码)

上一章介绍的是AUTOSAR网络管理如何测试、用例设计,对于不满足手工测试的同学,本章就介绍AUTOSAR网络管理自动化测试。

测试领域技术分享 6255

RedisCache工具类

package com.kejin.utils.redis; import java.util.ArrayList; import java.util.Collection; import java.util.HashSet; import java.util.Iterator; import java.util.List; import java.util.Map; import java.u...

u013008898的博客 4450

基于STM32设计的遥控小车(手机APP+GPS+温湿度+ESP8266)

一、环境介绍 小车主控MCU: STM32F103ZET6 STM32程序开发IDE: keil5 STM32程序风格: 采用寄存器方式开发,注释齐全,执行效率高,方便移植 手机APP: 采用QT设计,程序支持跨平台编译运行(Android、IOS、Windows、Linux都可以编译运行,对应平台上QT的环境搭建,之前博客已经发了文章讲解) 硬件包含: 淘宝购买的完整一套4轮遥控小车(采用STM32F103ZET6作为主控板)、DHT11温湿度传感器、中科微GPS模块、ESP8266 ...

6万+

15 君正IPC库开发总结

在前面的章节中,我们介绍了君正ISP、视频采集、音频采集、音频播放、云台电机、移动侦测算法、人形侦测算法、移动跟踪算法等的封装。那么,应用层如何使用这些封装好的接口呢?根据设计模式中的依赖倒置原则:高层次的模块不应该依赖于低层次的模块,它们都应该依赖于抽象。因此,应用层应当只能感知到我们封装的接口类,而不应当感知到其对应的具体实现类。

hope_wisdom的技术博客 1670

springboot连接redis出现org.springframework.data.redis。RedisConnectionFailureException异常

org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to 192.168.36.129:6379 如果你的springboot连接redis异常跟我一样,也是无法连接,请往下接着看。 一、 查看application资源

m0_67393828的博客 1万+

深度学习工具包 DeepLearningToolbox

深度学习工具包Deprecation notice.-----This toolbox is outdated and no longer maintained.There are much better tools available for deep learning than this toolbox, e.g. [Theano](http://deeplearning.net/software/theano/), [torch](http://torch.ch/) or [tensorflow](http://www.tensorflow.org/)I would suggest you use one of the tools mentioned above rather than use this toolbox.Best, Rasmus.DeepLearnToolbox================A Matlab toolbox for Deep Learning.Deep Learning is a new subfield of machine learning that focuses on learning deep hierarchical models of data.It is inspired by the human brain's apparent deep (layered, hierarchical) architecture.A good overview of the theory of Deep Learning theory is[Learning Deep Architectures for AI](http://www.iro.umontreal.ca/~bengioy/papers/ftml_book.pdf)For a more informal introduction, see the following videos by Geoffrey Hinton and Andrew Ng.* [The Next Generation of Neural Networks](http://www.youtube.com/watch?v=AyzOUbkUf3M) (Hinton, 2007)* [Recent Developments in Deep Learning](http://www.youtube.com/watch?v=VdIURAu1-aU) (Hinton, 2010)* [Unsupervised Feature Learning and Deep Learning](http://www.youtube.com/watch?v=ZmNOAtZIgIk) (Ng, 2011)If you use this toolbox in your research please cite [Prediction as a candidate for learning deep hierarchical models of data](http://www2.imm.dtu.dk/pubdb/views/publication_details.php?id=6284)```@MASTERSTHESIS\{IMM2012-06284, author = "R. B. Palm", title = "Prediction as a candidate for learning deep hierarchical models of data", year = "2012",}```Contact: rasmusbergpalm at gmail dot comDirectories included in the toolbox-----------------------------------`NN/` - A library for Feedforward Backpropagation Neural Networks`CNN/` - A library for Convolutional Neural Networks`DBN/` - A library for Deep Belief Networks`SAE/` - A library for Stacked Auto-Encoders`CAE/` - A library for Convolutional Auto-Encoders`util/` - Utility functions used by the libraries`data/` - Data used by the examples`tests/` - unit tests to verify toolbox is workingFor references on each library check REFS.mdSetup-----1. Download.2. addpath(genpath('DeepLearnToolbox'));Example: Deep Belief Network---------------------```matlabfunction test_example_DBNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit RBM and visualize its weightsrand('state',0)dbn.sizes = [100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);figure; visualize(dbn.rbm{1}.W'); % Visualize the RBM weights%% ex2 train a 100-100 hidden unit DBN and use its weights to initialize a NNrand('state',0)%train dbndbn.sizes = [100 100];opts.numepochs = 1;opts.batchsize = 100;opts.momentum = 0;opts.alpha = 1;dbn = dbnsetup(dbn, train_x, opts);dbn = dbntrain(dbn, train_x, opts);%unfold dbn to nnnn = dbnunfoldtonn(dbn, 10);nn.activation_function = 'sigm';%train nnopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.10, 'Too big error');```Example: Stacked Auto-Encoders---------------------```matlabfunction test_example_SAEload mnist_uint8;train_x = double(train_x)/255;test_x = double(test_x)/255;train_y = double(train_y);test_y = double(test_y);%% ex1 train a 100 hidden unit SDAE and use it to initialize a FFNN% Setup and train a stacked denoising autoencoder (SDAE)rand('state',0)sae = saesetup([784 100]);sae.ae{1}.activation_function = 'sigm';sae.ae{1}.learningRate = 1;sae.ae{1}.inputZeroMaskedFraction = 0.5;opts.numepochs = 1;opts.batchsize = 100;sae = saetrain(sae, train_x, opts);visualize(sae.ae{1}.W{1}(:,2:end)')% Use the SDAE to initialize a FFNNnn = nnsetup([784 100 10]);nn.activation_function = 'sigm';nn.learningRate = 1;nn.W{1} = sae.ae{1}.W{1};% Train the FFNNopts.numepochs = 1;opts.batchsize = 100;nn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.16, 'Too big error');```Example: Convolutional Neural Nets---------------------```matlabfunction test_example_CNNload mnist_uint8;train_x = double(reshape(train_x',28,28,60000))/255;test_x = double(reshape(test_x',28,28,10000))/255;train_y = double(train_y');test_y = double(test_y');%% ex1 Train a 6c-2s-12c-2s Convolutional neural network %will run 1 epoch in about 200 second and get around 11% error. %With 100 epochs you'll get around 1.2% errorrand('state',0)cnn.layers = { struct('type', 'i') %input layer struct('type', 'c', 'outputmaps', 6, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %sub sampling layer struct('type', 'c', 'outputmaps', 12, 'kernelsize', 5) %convolution layer struct('type', 's', 'scale', 2) %subsampling layer};cnn = cnnsetup(cnn, train_x, train_y);opts.alpha = 1;opts.batchsize = 50;opts.numepochs = 1;cnn = cnntrain(cnn, train_x, train_y, opts);[er, bad] = cnntest(cnn, test_x, test_y);%plot mean squared errorfigure; plot(cnn.rL);assert(er<0.12, 'Too big error');```Example: Neural Networks---------------------```matlabfunction test_example_NNload mnist_uint8;train_x = double(train_x) / 255;test_x = double(test_x) / 255;train_y = double(train_y);test_y = double(test_y);% normalize[train_x, mu, sigma] = zscore(train_x);test_x = normalize(test_x, mu, sigma);%% ex1 vanilla neural netrand('state',0)nn = nnsetup([784 100 10]);opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samples[nn, L] = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.08, 'Too big error');%% ex2 neural net with L2 weight decayrand('state',0)nn = nnsetup([784 100 10]);nn.weightPenaltyL2 = 1e-4; % L2 weight decayopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex3 neural net with dropoutrand('state',0)nn = nnsetup([784 100 10]);nn.dropoutFraction = 0.5; % Dropout fraction opts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex4 neural net with sigmoid activation functionrand('state',0)nn = nnsetup([784 100 10]);nn.activation_function = 'sigm'; % Sigmoid activation functionnn.learningRate = 1; % Sigm require a lower learning rateopts.numepochs = 1; % Number of full sweeps through dataopts.batchsize = 100; % Take a mean gradient step over this many samplesnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex5 plotting functionalityrand('state',0)nn = nnsetup([784 20 10]);opts.numepochs = 5; % Number of full sweeps through datann.output = 'softmax'; % use softmax outputopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, train_x, train_y, opts);[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');%% ex6 neural net with sigmoid activation and plotting of validation and training error% split training data into training and validation datavx = train_x(1:10000,:);tx = train_x(10001:end,:);vy = train_y(1:10000,:);ty = train_y(10001:end,:);rand('state',0)nn = nnsetup([784 20 10]); nn.output = 'softmax'; % use softmax outputopts.numepochs = 5; % Number of full sweeps through dataopts.batchsize = 1000; % Take a mean gradient step over this many samplesopts.plot = 1; % enable plottingnn = nntrain(nn, tx, ty, opts, vx, vy); % nntrain takes validation set as last two arguments (optionally)[er, bad] = nntest(nn, test_x, test_y);assert(er < 0.1, 'Too big error');```[![Bitdeli Badge](https://d2weczhvl823v0.cloudfront.net/rasmusbergpalm/deeplearntoolbox/trend.png)](https://bitdeli.com/free "Bitdeli Badge")

Redis(spring data redis) 发布订阅 pub/sub

Spring Data为Redis提供了专用的消息集成,功能类似,并命名为Spring Framework中的JMS集成。 Redis消息大致可分为两个功能区域: 发布或生产消息 订阅或消费消息 通常被称为发布/订阅模式。RedisTemplate类是用来生产消息的。对于类似于Java EE的消息驱动bean形式的异步接收,Spring Data提供了一个专用的消息监听器容器...

top_explore的博客 870

怀旧版电脑GBC模拟器

再现原版GBC掌机的界面,电脑运行连游戏界面都一样大小,很怀旧,很真实,(英文版)强烈推荐,很小的文件,很难才找到的。

老版QQ原生表情gif动态

这是老版的QQ表情,不过全是动态的的,Windows照片查看器是不会动的,可以右击用浏览器打开查看,再说一遍是老版的,只是分享给宁愿用老版也要动态的人。

redis连接失败报错 org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Red

无法远程连接虚拟机redis 报错org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis;

miai_345的博客 4836

Devexpress16.2.6破解工具

Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具Devexpress16.2.6破解工具

Spring Data Redis—Pub/Sub(附Web项目源码)

一、发布和订阅机制   当一个客户端通过 PUBLISH 命令向订阅者发送信息的时候,我们称这个客户端为发布者(publisher)。   而当一个客户端使用 SUBSCRIBE 或者 PSUBSCRIBE 命令接收信息的时候,我们称这个客户端为订阅者(subscriber)。 为了解耦发布者(publisher)和订阅者(subscriber)之间的关系,Redis 使用了 ch...

acy29712的博客 245

springboot项目整合springDataRedis实现消息对列的pub/sub

众所周知,redis是nosql数据库,因此大多数情况下,在我们的项目中都是用于数据信息的缓存(例如:商城项目中缓存商品的基本信息),以便于提高数据响应效率,同时又可减少对关系型数据库的压力。 然而redis非关系型数据库的另一个很重要的功能,往往会被大多数人忽略,这个功能就是“消息队列”功能,一般用于电商项目的红包过期通知,或一些项目的日志过滤处理等。 Redis 发布订阅(pub/sub)是一...

qq_38041579的博客 545

Springboot-Redis - 10.Redis 消息 (Pub/Sub)

Redis 支持发布/订阅模式,允许客户端订阅指定的频道并收到发送到这些频道的消息。在 Spring Data Redis 中,你可以使用来处理消息的订阅和接收。

yueerba126的博客 993

SpringBoot 集成Redis PubSub发布订阅/Stream消息队列

SpringBoot 集成Redis PubSub发布订阅/Stream消息队列

qq_41902662的博客 2378

java redis sub_基于Spring+redis实现pub/sub

基于Spring+redis实现pub/subPub / Sub(publisher/subcriber发布和订阅)消息是许多软件架构的重要组成部分。消息传递解决方案提供了高性能,可扩展性,队列持久性和耐用性,故障转移支持等,以及许多更漂亮具备的功能,在Java世界中大多总是使用JMS实现。后来使用Apache ActiveMQ的,有时只是需要简单的排队支持,而Apache ActiveMQ显得过...

weixin_29837797的博客 444

spring boot + redis 实现信息的发送和接收(pub/sub)

redis本身就带有发送接收的功能,用redis来发送接收的方法如下: 1.redis侦听的方法 2.redis发送信息的方法 3.刚才1中的画面中应该能看到如下内容 从以上看来redis-cli带有发送接收信息的功能,但是用spring-data-redis如何来实现呢,其实比较简单,可以有两个方法,一个方法通过实现MessageListener接口类实现,但是他有一个问题,在侦听信息需...

lin000_0的博客 5476

org.springframework.data.redis.RedisConnectionFailureException异常解决

记录一下自己做项目的时候遇到的这个redis异常 场景描述: 我安装的是windows版本的redis,点击登录功能的时候将用户密码存到redis中结果报出异常: org.springframework.data.redis.RedisConnectionFailureException: Unable to connect to Redis; nested exception is io.lettuce.core.RedisConnectionException: Unable to connect to

Sexycool的博客 8668

Spring-data-redis

官方推荐两个都启用,如果对数据不敏感,可以选单独用RDB,不建议单独用 AOF,因为可能会出现Bug如果只是做纯内存缓存,可以都不用。

yyd686874的博客 1486

使用redis实现发布订阅功能及问题

通过接口调用时,请求只能打到服务B的一个pod上,而我们想要的是服务B的每个pod都能收到服务A发送的请求数据,所以使用redis的发布订阅来实现。提示就是加载SubscriptionListener这个类失败了,找不到,搜一圈之后各种尝试,然后找到了解决办法。服务A通过接口操作服务B,实现相应逻辑。生产环境上,服务A有两个pod,服务B有3个pod。1)redis配置类中,增加消息监听的逻辑。代码咔咔写完了,然后就是启动服务测试逻辑了。说是redis包的问题,项目中用的是。我们的data是个实体。

panying941206的博客 654

Spring整合Redis(八)----发布/订阅消息

Spring Data为Redis提供了专用的消息集成,在功能和命名方面与Spring Framework中的JMS集成类似。这是一个通常称为发布/订阅(简称Pub/Sub)的模式示例。RedisTemplate类用于消息生成。对于类似于Java EE的消息驱动bean风格的异步接收,Spring Data提供了一个专用的消息监听器容器,用于创建消息驱动的POJO(MDP),对于同步接收,还提供RedisConnection。

爱看技术博客 768

Spring Data Redis

5.9. Redis Messaging/PubSubSpring Data 提供 dedicated messaging 整合 for Redis, very similar in functionality and naming to the JMS integration in Spring Framework; in fact, users familiar with the JMS sup

沈林楠的专栏 792
上一篇: Spring Data Redis(Hash mapping)
下一篇: Spring Data Redis(Redis Transactions)
架构师的清醒
博客等级 码龄14年 291粉丝 397原创
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

个

红包个数最小为10个

元

红包金额最低5元

当前余额3.43元 前往充值 >
需支付:10.00元
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付元
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值
⌂ 换网址