Implementing a Netty Cluster Long‑Connection Service with Redis Pub/Sub for Message Forwarding

This article explains how to build a high‑concurrency Netty long‑connection server cluster using Redis publish/subscribe to forward messages across nodes, detailing the background, technology choices, architecture, and implementation steps for a microservice‑based backend system.

Selected Java Interview Questions
Selected Java Interview Questions
Selected Java Interview Questions
Implementing a Netty Cluster Long‑Connection Service with Redis Pub/Sub for Message Forwarding

Background – The company needed to develop its own long‑connection server for a social project’s audio/video features, choosing SpringBoot + Netty within a microservice architecture to ensure high concurrency and reliable connections.

Netty Long‑Connection – Netty, an asynchronous NIO framework, can serve as a long‑connection server using the WebSocket protocol, supporting roughly ten thousand connections per instance. In a cluster, client channels may reside on different nodes, requiring node‑aware message routing.

Technology Options – For inter‑node message forwarding, the team considered Zookeeper, MQ, and Redis. Since MQ and Redis were already in use, they evaluated both: MQ offers high reliability but is heavyweight and asynchronous; Redis provides lightweight, low‑latency, high‑concurrency pub/sub with lower reliability. Given the real‑time nature of live‑stream messages, Redis pub/sub was selected.

Architecture – When the service starts, each node registers itself in Redis and subscribes to a specific channel. After a client connects, the node binds the user’s session to its identifier in Redis. When a message arrives, the node checks if the target user is on the same node; if not, it retrieves the target node’s info from Redis and publishes the message to the appropriate channel, where the target node delivers it to the client.

Implementation Overview – The article includes diagrams (omitted here) and describes the key steps: node registration and listener setup, subscription handling, channel listener processing, and a message‑forwarding sender component.

Conclusion – Using Redis pub/sub with a Netty cluster enables automatic node registration and seamless message forwarding across newly added nodes, offering strong scalability. The author also notes ongoing learning of advanced Redis 5 features for further business scenarios.

Original Source

Signed-in readers can open the original source through BestHub's protected redirect.

Sign in to view source
Republication Notice

This article has been distilled and summarized from source material, then republished for learning and reference. If you believe it infringes your rights, please contactadmin@besthub.devand we will review it promptly.

MicroservicesNettylong-connectionpub/subMessage Forwarding
Selected Java Interview Questions
Written by

Selected Java Interview Questions

A professional Java tech channel sharing common knowledge to help developers fill gaps. Follow us!

0 followers
Reader feedback

How this landed with the community

Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.