Netflix Zuul

repository·master·Indexed 12 days ago

https://github.com/netflix/zuul

An L7 application gateway for microservices architectures providing dynamic routing, monitoring, resiliency, and security. It acts as an edge service to manage incoming traffic, featuring a Netty-based server with support for various transport types including io_uring, epoll, kqueue, and NIO.

Tokens
868
Snippets
1
Records
4
Agent score
46%

What's inside Zuul

  1. What is Zuul?

    master

    Zuul is an L7 (Layer 7) application gateway. It is designed to provide essential edge service capabilities for microservices architectures, including:

    • Dynamic Routing: Directing requests to appropriate backend services.
    • Monitoring: Observing traffic patterns and health.
    • Resiliency: Implementing patterns like retries and circuit breaking to handle failures.
    • Security: Providing a centralized point for authentication and authorization.
    • And more: Extending functionality through various filters and configurations.
  2. Configure Zuul Netty transport types via properties

    master

    Zuul automatically detects the best available transport (e.g., io_uring, epoll, kqueue, or standard NIO). You can override this behavior using the following configuration properties:

    • zuul.server.netty.socket.force_nio: If set to true, the server will bypass autodetect and use the default Java NIO transport.
    • zuul.server.netty.socket.force_io_uring: If set to true, the server will attempt to use io_uring if available.
    • zuul.server.netty.socket.epoll: (Deprecated) Used to manually toggle Epoll. Note that Epoll is enabled automatically if available unless FORCE_NIO is used.
    • zuul.server.netty.manual.discovery.status: If true, the server manually manages its status via the ServerStatusManager (e.g., setting status to UP just before binding and DOWN during shutdown).
  3. Initialize and manage the Zuul Netty Server

    master

    The com.netflix.zuul.netty.server.Server class is the primary entrypoint for starting a Zuul Netty server. It manages the lifecycle of the server, including binding to multiple socket addresses, managing event loops, and handling graceful shutdowns.

    To use the Server, you should provide a Registry for metrics, a ServerStatusManager for lifecycle status, a map of NamedSocketAddress to ChannelInitializer for defining how connections are handled on specific ports, a ClientConnectionsShutdown handler, EventLoopGroupMetrics for monitoring, and an EventLoopConfig for tuning thread counts and backlog sizes.

    Key lifecycle methods:

    • start(): Initializes the transport, sets up event loops, and binds to the requested addresses. It also registers a JVM shutdown hook by default.
    • stop(): Shuts down the server group and stops accepting new connections.
    • awaitTermination(): Blocks until all bound channels have closed.
    • getListeningAddresses(): Returns a list of the addresses the server is currently listening on.
    Server server = new Server(
        registry,
        serverStatusManager,
        addressesToInitializers,
        clientConnectionsShutdown,
        eventLoopGroupMetrics,
        eventLoopConfig
    );
    
    server.start();
    // ... run server ...
    server.awaitTermination();
  4. Customize Event Loop creation in Zuul Server

    master

    You can hook into the server lifecycle to perform actions after the event loops (acceptor and worker pools) have been created. To do this, extend the Server class and override the postEventLoopCreationHook method.

    public class MyCustomServer extends Server {
        public MyCustomServer(...) { super(...); }
    
        @Override
        public void postEventLoopCreationHook(
                EventLoopGroup clientToProxyBossPool, 
                EventLoopGroup clientToProxyWorkerPool) {
            // Perform custom logic with the event loops here
        }
    }