Skip to content

Commit c6d4cb8

Browse files
committed
Add RedisBackendCondition for Spring conditional bean wiring
Portable Spring Condition that matches when rqueue.backend resolves to REDIS (default when the property is absent or unparseable). Companion to the existing rqueue-spring NatsBackendCondition; lives in rqueue-core so both Boot and non-Boot modules can reuse it without crossing module boundaries. Per-bean gating (applying @conditional(RedisBackendCondition.class) to every Redis-shaped bean factory) is staged separately; this commit adds only the condition class itself. Assisted-By: Claude Code
1 parent 3c98eba commit c6d4cb8

1 file changed

Lines changed: 39 additions & 0 deletions

File tree

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Copyright (c) 2024-2026 Sonu Kumar
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* You may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*/
10+
11+
package com.github.sonus21.rqueue.config;
12+
13+
import org.springframework.context.annotation.Condition;
14+
import org.springframework.context.annotation.ConditionContext;
15+
import org.springframework.core.type.AnnotatedTypeMetadata;
16+
17+
/**
18+
* Spring {@link Condition} that matches when the active rqueue backend is {@link Backend#REDIS}.
19+
* Reads the {@code rqueue.backend} property; absent or unparseable values default to REDIS so the
20+
* existing behavior is preserved.
21+
*/
22+
public class RedisBackendCondition implements Condition {
23+
@Override
24+
public boolean matches(ConditionContext ctx, AnnotatedTypeMetadata md) {
25+
return resolveBackend(ctx) == Backend.REDIS;
26+
}
27+
28+
static Backend resolveBackend(ConditionContext ctx) {
29+
String raw = ctx.getEnvironment().getProperty("rqueue.backend");
30+
if (raw == null || raw.isBlank()) {
31+
return Backend.REDIS;
32+
}
33+
try {
34+
return Backend.valueOf(raw.trim().toUpperCase());
35+
} catch (IllegalArgumentException ex) {
36+
return Backend.REDIS;
37+
}
38+
}
39+
}

0 commit comments

Comments
 (0)