首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Spring :流的意外结束

问Spring :流的意外结束
EN

Stack Overflow用户
提问于 2017-06-19 09:11:48
回答 3查看 8.8K关注 0票数 4

Redis 3.0.5

春季数据Redis 1.3.6

吉迪斯2.6.3

  • 我们的是web应用程序,它通过pub/sub接收来自redis的数据。
  • 还以键/值对的形式对redis上的数据执行读/写。
  • 读/写发生在侦听器线程、独立监视线程和http请求线程上。
  • 我们为侦听器和redis模板使用了相同的连接工厂。
  • 我们的redis服务器配置了"timeout=30“。
代码语言:javascript
复制
<bean id="jedisConnectionFactory"
    class="org.springframework.data.redis.connection.jedis.JedisConnectionFactory">
    <property name="hostName" value="nnnn"></property>
    <property name="port" value="nnnn"></property>
    <property name="password" value="****"></property>
</bean>
<bean id="redisTemplate" class="org.springframework.data.redis.core.StringRedisTemplate">
    <property name="connectionFactory" ref="jedisConnectionFactory" />
</bean>
<bean id="redisContainer"
    class="org.springframework.data.redis.listener.RedisMessageListenerContainer">
    <property name="connectionFactory" ref="jedisConnectionFactory" />
    <property name="messageListeners">
        <map>
            <entry key-ref="messageListener">
                <bean class="org.springframework.data.redis.listener.ChannelTopic">
                    <constructor-arg value="topic_name" />
                </bean>
            </entry>
        </map>
    </property>
    <property name="taskExecutor" ref="redisTaskExecutor" />
    <property name="subscriptionExecutor" ref="redisSubTaskExecutor" />
</bean>
<bean id="redisTaskExecutor"
    class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
    <property name="threadNamePrefix" value="RedisListenerThread"></property>
    <property name="corePoolSize" value="1" />
    <property name="maxPoolSize" value="1" />
</bean>
<bean id="redisSubTaskExecutor"
    class="org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor">
    <property name="threadNamePrefix" value="RedisSubscribeThread"></property>
    <property name="corePoolSize" value="1" />
    <property name="maxPoolSize" value="1" />
</bean>
<bean id="messageListener"
    class="org.springframework.data.redis.listener.adapter.MessageListenerAdapter">
    <constructor-arg index="0">
        <bean class="my.data.Receiver" />
    </constructor-arg>
    <constructor-arg index="1"><value>receive</value></constructor-arg>
</bean>

在数据读取过程中,我们偶尔会遇到以下生产问题。

org.springframework.data.redis.RedisConnectionFailureException:意料之外的流结束。嵌套异常是流的redis.clients.jedis.exceptions.JedisConnectionException:意外结束。在org.springframework.data.redis.connection.jedis.JedisExceptionConverter.convert(JedisExceptionConverter.java:47) at org.springframework.data.redis.connection.jedis.JedisExceptionConverter.convert(JedisExceptionConverter.java:36) at org.springframework.data.redis.PassThroughExceptionTranslationStrategy.translate(PassThroughExceptionTranslationStrategy.java:37) at org.springframework.data.redis.FallbackExceptionTranslationStrategy.translate(FallbackExceptionTranslationStrategy.java:37) at org.springframework.data.redis.connection.jedis.JedisConnection.convertJedisAccessException(JedisConnection.java:182)在org.springframework.data.redis.connection.jedis.JedisConnection.get(JedisConnection.java:1087) at org.springframework.data.redis.connection.DefaultStringRedisConnection.get(DefaultStringRedisConnection.java:276) at org.springframework.data.redis.core.DefaultValueOperations$1.inRedis(DefaultValueOperations.java:46) at org.springframework.data.redis.core.AbstractOperations$ValueDeserializingRedisCallback.doInRedis(AbstractOperations.java:50) at org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:190)在org.springframework.data.redis.core.RedisTemplate.execute(RedisTemplate.java:152) at org.springframework.data.redis.core.AbstractOperations.execute(AbstractOperations.java:84) at org.springframework.data.redis.core.DefaultValueOperations.get(DefaultValueOperations.java:43)

我读过其他线程,谈到使用单个线程进行读/写。但在我们的情况下,很难使用单线程。此外,根据RedisTemplate文档,它是线程安全的。这个问题是偶然的,我们无法在开发/测试/uat环境中进行复制。因此无法找到相同的确切原因。我们做错了什么?

EN

回答 3

Stack Overflow用户

回答已采纳

发布于 2017-07-12 05:02:15

我们已经能够复制这个问题,原因是"timeout=30“设置在Redis中。

场景

  1. 连接空闲30秒,Redis也会杀死相同的连接。
  2. 在应用程序中的"Redis连接工厂“检测到断开的连接之前,它将获得读写请求的分配。
  3. 代码尝试使用此连接,但由于连接中断,无法发送读/写命令。因此,我们得到了"JedisConnectionException:意想不到的流结束“异常。

解决方案

  1. 将Redis超时设置为零
  2. 使用自定义JedisPoolConfig将minEvictableIdleTimeMillis设置为所需的值。这将确保从Jedis连接池释放空闲连接。
票数 7
EN

Stack Overflow用户

发布于 2021-05-06 16:25:54

对于那些在码头上运行redis的人来说:不要忘记将它绑定到0.0.0.0而不是127.0.0.1。

票数 1
EN

Stack Overflow用户

发布于 2022-11-02 13:04:52

我张贴这个答案仅仅是为了了解,因为这是可能的情况之一

由于您正在使用Pub Sub机制,导致此错误的可能原因之一是应用程序的输入/输出缓冲区超过了redis应用程序的配置限制。

根据Redis 文档,redis有32 8mb的硬限制和8mb的软限制60秒。因此,通过改变配置,就可以在redis发布子机制中获得大量的数据吞吐量。

您只需更新以下键的配置值即可

客户端-输出-缓冲区-限制发布

更大的价值。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/44626474

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档