Quantcast
Channel: Active questions tagged redis+java - Stack Overflow
Viewing all articles
Browse latest Browse all 2204

Lettuce subscriber doesn't keep thread up

$
0
0

I'm trying to use Lettuce reactive api for creating subscriber which will be listening forever for messages from some predefined Redis topics

I've created a spring bean which contains logic of creating subscription/handling messages:

@PostConstructpublic void init() {        StatefulRedisPubSubConnection<String, String> statefulRedisPubSubConnection = redisClient.connectPubSub();        RedisPubSubReactiveCommands<String, String> redisCommands = statefulRedisPubSubConnection.reactive();        redisCommands.subscribe(topicNames).subscribe();        redisCommands.observeChannels()                .doOnNext(channelMessage -> //do something)                .doOnError(err -> //handle error)                .subscribe();}

Unfortunately, the code above doesn't keep the thread up. So, Spring Boot just shut down application right away after startup.
If I add some trick to keep main thread alive(like adding forever 'for' loop), then subscriber works perfectly. It receives messages from Redis topic.
How can I keep the application up forever with more elegant solution?


Viewing all articles
Browse latest Browse all 2204

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>