Armeria Documentation
repository·main·Indexed 26 days ago
https://github.com/line/armeriaArmeria is a reactive microservice framework for building high-performance microservices that support multiple protocols, including gRPC, Thrift, and HTTP/2. The project includes a DocService web client and a comprehensive Gradle-based build system for managing multi-project Java setups, dependency catalogs via dependencies.toml, and benchmarking tools using ghz and JMH.
What's inside Armeria
- Armeria is a reactive microservice framework designed to build microservices using various technologies. It supports protocols and frameworks such as gRPC, Thrift, Kotlin, Retrofit, Reactive Streams, Spring Boot, and Dropwizard. It is open-sourced by the creators of Netty and LINE Corporation.
Overview of Armeria features
mainArmeria is a microservice framework designed to support various technologies including gRPC, Thrift, Kotlin, Retrofit, Reactive Streams, Spring Boot, and Dropwizard.
Key capabilities include:
- HTTP/2 Support: Supports both TLS and cleartext, protocol upgrades (preface and traditional HTTP/1 upgrade), and integrated PROXY protocol support for load balancers like HAProxy and AWS ELB.
- gRPC and Thrift Integration: Run existing gRPC or Thrift implementations without modification. Supports gRPC-Web and various protocol combinations (gRPC/Thrift over HTTP/1 or HTTP/2).
- Microservice Essentials: Provides metrics, circuit breakers, client-side health-checks, load-balancing, service discovery (DNS, ZooKeeper), and distributed tracing via Zipkin.
- Interactive Debugging: Includes
DocServicefor browsing RPC operations and invoking them via a web form. - Asynchronous/Reactive Architecture: Built on Reactive Streams and Java 8
CompletableFuturewith asynchronous connection pooling and domain name resolution. - Java EE Compatibility: Can run Java EE applications (like Spring Boot) on the same TCP/IP port, enabling them to speak HTTP/2.
- Linux Performance: Optimized via JNI-based socket I/O and BoringSSL-based TLS connections.
Overview of Armeria gRPC features
mainArmeria extends standard gRPC-Java capabilities by supporting additional protocols and serialization formats. Key features include:
Supported Protocols
- HTTP/1.1
- HTTP/2
Supported Serialization Formats
Framed:
- gRPC protobuf:
application/grpc+proto - gRPC JSON:
application/grpc+json - gRPC Web:
application/grpc-web+proto - gRPC Web JSON:
application/grpc-web+json - gRPC Web Text:
application/grpc-web-text+proto
Unframed:
- Protobuf:
application/protobuf - JSON:
application/json
Additional Capabilities
- HTTP level decorators for gRPC services
- Richer error handling
- HTTP-to-JSON transcoding
- Customizing service method paths
- gRPC documentation service
- gRPC status monitoring with
MetricCollectingService
Understand Armeria's xDS proxyless approach
mainArmeria provides a proxyless implementation of the xDS APIs. Unlike a traditional service mesh that uses a sidecar proxy (like Envoy) to intercept traffic, Armeria's xDS module implements the data plane directly within the application's networking framework.
Key Characteristics of Proxyless Armeria:
- Direct request path: Requests do not traverse separate client-side or server-side proxy processes, potentially reducing latency.
- No traffic-interception infrastructure: Works on containers, VMs, or bare metal without requiring sidecar injection or transparent redirection.
- Reduced overhead: Avoids the memory and CPU costs of running an additional proxy process per instance.
- Deployment: The data-plane implementation is versioned and deployed as an application dependency rather than a separate fleet.
Trade-offs to consider:
- Framework dependency: Requires xDS support within the application's runtime (Armeria provides this for HTTP, gRPC, and Thrift).
- Release coupling: Upgrading the data-plane implementation requires redeploying the application.
- Feature subset: A proxyless implementation may support fewer Envoy resources, fields, and filters compared to a full Envoy sidecar.
Key Armeria features and API updates
mainRecent versions of Armeria have introduced several significant features:
- HTTP/JSON-to-gRPC transcoding: Enables transcoding similar to Google's approach without requiring an API gateway server.
- GraphQL support: Integration with
GraphQL JavaandSangria. - Immutable Cookie API: A redesigned
Cookietype focused on usability. - OAuth 2.0: A fully asynchronous module.
- Reactive multipart streaming: A new API for multipart streaming.
- WebClient Redirects:
WebClientcan now follow redirects using highly customizable redirect rules. - Stream Transformation: New APIs such as
map,concat,recover, andcollectfor stream manipulation. - Dynamic Reconfiguration: Use
Server#reconfigure()to reconfigure servers dynamically. - Scala Integration: Native support for Scala developers.
Understand the xDS Threading Model
mainArmeria separates xDS resource management from request processing using two distinct thread types to ensure that updates do not block the request path:
- xDS Event Loop: By default, a single dedicated thread named
xds-common-workerhandles all communication with the control plane, resource parsing, and snapshot updates. This thread is shared across allXdsBootstrapinstances. You can provide a custom executor via the builder. - Application Thread: Request processing (filter execution, routing, load balancing) runs on the existing threads used by the client or server.
Updates are passed via a thread-safe, lock-free handoff. When a new snapshot is published, it becomes visible to all subsequent requests immediately.
- xDS Event Loop: By default, a single dedicated thread named
Understand xDS Snapshots
mainA snapshot is an immutable, point-in-time view of the xDS resource tree (comprising
ListenerSnapshot,RouteSnapshot,ClusterSnapshot, andEndpointSnapshot).Snapshots provide the following guarantees:
- Complete: A snapshot is only published once all dependent resources (routes, clusters, endpoints) are fully resolved.
- Error-free: If any resource in the tree fails to load, the snapshot is not published, and the application continues using the last successful snapshot.
- Immutable: Once published, a snapshot never changes and can be read on any thread without synchronization.
New features in Armeria 1.24.0 to 1.26.4
mainRecent versions of Armeria (between 1.24.0 and 1.26.4) introduced several key features:
- WebSocket support: Native support for WebSocket protocols.
- Unix domain socket support: Ability to use Unix domain sockets for communication.
- GraalVM native image configuration: Out-of-the-box support for building native images using GraalVM.
- gRPC Richer Error Model support: Support for enhanced error reporting in gRPC using
GoogleGrpcExceptionHandlerFunction.
Understand the Armeria Threading Model
mainArmeria uses a non-blocking I/O model based on Netty. Understanding the different thread pools is critical to prevent performance degradation and deadlocks caused by blocking the event loop.
Thread Pool Roles
Pool Purpose Thread Name Pattern Default Size bossGroup Accepts incoming TCP connections (1 per server port). armeria-boss-{protocol}-{addr}1 per port workerGroup Handles socket I/O (reads/writes) and non-blocking service logic. armeria-common-worker-*2 * CPU cores(NIO/epoll/kqueue) orCPU cores(io_uring)serviceWorkerGroup (Optional) Dedicated EventLoopGroup for service execution to isolate logic from socket I/O. User-defined Falls back to workerGroupblockingTaskExecutor Runs long-running or blocking operations (DB, File I/O, sync APIs). armeria-common-blocking-tasks-*200 Request Flow
- bossGroup: Accepts TCP connection and hands it to
workerGroup. - workerGroup: Reads bytes and decodes frames.
- Execution:
- Non-blocking service: Runs directly on the event loop thread.
- @Blocking / useBlockingTaskExecutor(true): Dispatched to
blockingTaskExecutor. - serviceWorkerGroup configured: Service runs on a dedicated event loop.
- bossGroup: Accepts TCP connection and hands it to
Understand Armeria xDS Architecture
mainArmeria implements the xDS protocol directly within the application, eliminating the need for a sidecar proxy. The architecture consists of two main layers managed by a Control Plane:
- xDS Inbound (XdsServerPlugin): Manages incoming connections, including mTLS, filter chains, and HTTP filter policies.
- xDS Outbound (Preprocessor): Manages outgoing requests, including endpoint discovery, load balancing, retries, timeouts, and mTLS.
Both layers receive configuration from the control plane at runtime, allowing for policy updates without application redeployment.
xDS Server Lifecycle and Ordering
mainStartup Behavior
The server blocks during startup until the first complete xDS snapshot arrives. The default timeout is 30 seconds. If a subsequent update fails, the last successful snapshot remains active.
Connection-time Binding
Filter chains (including TLS config and HTTP filter decorators) are determined at the moment of connection establishment. Once a connection is established, it maintains that policy for its entire lifetime, even if the xDS snapshot updates. New connections will use the latest snapshot.
Decorator Ordering
xDS decorators are the outermost layer. The execution order is:
[xDS filters] → [user's service decorators] → serviceUnderstand Armeria's Thread Pool Architecture
mainArmeria uses four distinct thread pools to manage I/O and service execution. Understanding these roles is critical to avoid blocking event loop threads, which can cause latency and deadlocks.
Pool Role Default Size bossGroup Accepts incoming TCP connections (one per server port) 1 per port workerGroup Handles socket I/O and non-blocking service logic 2 × CPU cores serviceWorkerGroup (Optional) Dedicated event loop group for service execution to isolate logic from socket I/O User-defined (falls back to workerGroup)blockingTaskExecutor Runs blocking operations (DB calls, file I/O, legacy sync APIs) 200 threads