Skip to content

feat: CDI-managed Lettuce beans with Vert.x event loop integration#2

Open
vchomakov wants to merge 2 commits into
lettuce-shared-event-loopsfrom
lettuce-cdi-beans
Open

feat: CDI-managed Lettuce beans with Vert.x event loop integration#2
vchomakov wants to merge 2 commits into
lettuce-shared-event-loopsfrom
lettuce-cdi-beans

Conversation

@vchomakov

Copy link
Copy Markdown
Collaborator

CDI-managed Lettuce beans with Vert.x event loop integration

Builds on top of the Lettuce + Vert.x foundation from the previous PR to provide seamless CDI injection of Lettuce Redis beans.

What this PR adds

Deployment processor (LettuceProcessor) with two build steps:

  • detectLettuceUsage — scans injection points for Lettuce types (RedisClient, StatefulRedisConnection, ClientResources) and emits build items only for clients that are actually needed
  • init — registers synthetic CDI beans per client name via the recorder

Runtime recorder (LettuceRecorder) that manages the full lifecycle:

  • Creates shared ClientResources backed by Vert.x event loops
  • Creates per-client RedisClient and StatefulRedisConnection instances
  • Handles shutdown in correct order: connections → clients → resources
  • Supports checkActive guards for clear error messages on misconfigured clients

Lettuce-specific build item (RequestedLettuceClientBuildItem) to isolate Lettuce bean creation from other Redis processors (Vert.x Redis, Redis Cache, OIDC Redis). This prevents Lettuce from attempting connections for non-Lettuce clients.

Usage

// Default client
@Inject
StatefulRedisConnection<String, String> connection;

// Named client
@Inject
@RedisClientName("my-redis")
StatefulRedisConnection<String, String> connection;

Tests

  • Default client injection + SET/GET operations
  • Named client with @RedisClientName
  • Multiple clients (default + two named) sharing ClientResources
  • Inactive client (active=false) produces clear InactiveBeanException
  • Missing hosts produces clear InactiveBeanException

@vchomakov vchomakov force-pushed the lettuce-cdi-beans branch from 0ed4675 to 8f15dcb Compare April 6, 2026 17:02
@vchomakov vchomakov marked this pull request as ready for review April 7, 2026 10:28
@vchomakov vchomakov self-assigned this May 13, 2026
@vchomakov vchomakov requested review from Dgramada and tishun May 26, 2026 09:44
vchomakov added 2 commits July 2, 2026 14:20
Add deployment processor and runtime recorder to register Lettuce
RedisClient, StatefulRedisConnection, and ClientResources as CDI
synthetic beans, sharing Vert.x event loops via the foundation
classes added in the previous PR.

- LettuceProcessor: build-time processor that scans for Lettuce
  injection points and registers synthetic beans per client name
- LettuceRecorder: runtime recorder managing lifecycle of Lettuce
  clients with proper shutdown ordering
- RequestedLettuceClientBuildItem: Lettuce-specific build item to
  isolate Lettuce bean creation from other Redis processors

Tests covering default client, named clients, inactive clients,
missing hosts, and multiple client coexistence.
…s client stack

Address review feedback on the CDI bean wiring:

- Do not produce RequestedRedisClientBuildItem from the Lettuce processor. That
  item drives the Vert.x processors, so every Lettuce injection was also creating
  a parallel Vert.x Redis client and a Vert.x-backed RedisDataSource. Add a test
  asserting a Lettuce-only application produces no Vert.x Redis or data source beans.
- Use ConcurrentHashMap for the recorder's factory/connection maps, which are
  populated lazily at runtime via computeIfAbsent.
- Adapt to the renamed LettuceClientResources#clientResources() accessor.
@vchomakov vchomakov force-pushed the lettuce-cdi-beans branch from 8f15dcb to d8f4961 Compare July 2, 2026 11:59
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants