Skip to content

Commit 3c98eba

Browse files
committed
Use single Backend enum; drop AUTO
Replaces the rqueue-spring-local Backend enum {AUTO, REDIS, NATS} with the canonical com.github.sonus21.rqueue.config.Backend {REDIS, NATS}. @EnableRqueue.backend() now defaults to REDIS; setting NATS pulls in RqueueNatsListenerConfig alongside the legacy RqueueListenerConfig. The runtime backend is independently bound from the rqueue.backend property onto RqueueConfig — that is the source of truth for what broker is active, regardless of which @configuration classes get imported here. ConditionalNatsConfig and the spring-local Backend.java are deleted; the import selector now branches on REDIS vs NATS only. Assisted-By: Claude Code
1 parent 9c7ab89 commit 3c98eba

4 files changed

Lines changed: 24 additions & 88 deletions

File tree

rqueue-spring/src/main/java/com/github/sonus21/rqueue/spring/Backend.java

Lines changed: 0 additions & 29 deletions
This file was deleted.

rqueue-spring/src/main/java/com/github/sonus21/rqueue/spring/ConditionalNatsConfig.java

Lines changed: 0 additions & 29 deletions
This file was deleted.

rqueue-spring/src/main/java/com/github/sonus21/rqueue/spring/EnableRqueue.java

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -16,33 +16,33 @@
1616

1717
package com.github.sonus21.rqueue.spring;
1818

19+
import com.github.sonus21.rqueue.config.Backend;
1920
import java.lang.annotation.ElementType;
2021
import java.lang.annotation.Retention;
2122
import java.lang.annotation.RetentionPolicy;
2223
import java.lang.annotation.Target;
2324
import org.springframework.context.annotation.Import;
2425

2526
/**
26-
* This annotation can be used to auto configure Rqueue library by providing some sample
27-
* configuration like by just providing
28-
* {@link org.springframework.data.redis.connection.RedisConnectionFactory}.
29-
*
30-
* <p>All other beans would be created automatically. Though other components of library can be
31-
* configured as well using
32-
* {@link com.github.sonus21.rqueue.config.SimpleRqueueListenerContainerFactory}. Even it can be
33-
* configured at very fine-grained level by creating all individual beans created in
34-
* {@link RqueueListenerConfig}
27+
* Auto-configure Rqueue when {@link
28+
* org.springframework.data.redis.connection.RedisConnectionFactory} (or, when {@link
29+
* #backend()} is {@link Backend#NATS}, an {@link io.nats.client.Connection}-derived
30+
* {@code MessageBroker}) is available. All other beans are created automatically; further
31+
* customization happens through {@link
32+
* com.github.sonus21.rqueue.config.SimpleRqueueListenerContainerFactory} or by directly defining
33+
* the beans created in {@link RqueueListenerConfig}.
3534
*/
3635
@Target(ElementType.TYPE)
3736
@Retention(RetentionPolicy.RUNTIME)
3837
@Import({RqueueBackendImportSelector.class})
3938
public @interface EnableRqueue {
4039

4140
/**
42-
* Backend to use. Defaults to {@link Backend#AUTO} which keeps the existing Redis behavior
43-
* unless the jnats client is on the classpath and {@code rqueue.backend=nats} is set.
44-
*
45-
* @return the chosen backend selector
41+
* Backend to wire. Defaults to {@link Backend#REDIS}. Set to {@link Backend#NATS} to import the
42+
* NATS / JetStream listener configuration. The {@code rqueue.backend} property is independently
43+
* read by {@link com.github.sonus21.rqueue.config.RqueueConfig} and remains the source of truth
44+
* for the runtime backend; this attribute controls only which {@code @Configuration} class is
45+
* pulled into the context.
4646
*/
47-
Backend backend() default Backend.AUTO;
47+
Backend backend() default Backend.REDIS;
4848
}

rqueue-spring/src/main/java/com/github/sonus21/rqueue/spring/RqueueBackendImportSelector.java

Lines changed: 10 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,26 +15,23 @@
1515
*/
1616
package com.github.sonus21.rqueue.spring;
1717

18-
import java.util.ArrayList;
19-
import java.util.List;
18+
import com.github.sonus21.rqueue.config.Backend;
2019
import org.springframework.context.annotation.ImportSelector;
2120
import org.springframework.core.type.AnnotationMetadata;
2221

2322
/**
2423
* Selects the listener configuration classes to import based on {@link EnableRqueue#backend()}.
2524
*
2625
* <ul>
27-
* <li>{@link Backend#REDIS} — only the legacy {@code RqueueListenerConfig}</li>
28-
* <li>{@link Backend#NATS} — base config plus {@code RqueueNatsListenerConfig} unconditionally
29-
* <li>{@link Backend#AUTO} — base config; the NATS config is gated by
30-
* {@link NatsBackendCondition} so it activates only when jnats is on the classpath
31-
* <em>and</em> {@code rqueue.backend=nats} is set.
26+
* <li>{@link Backend#REDIS} (default) — only {@code RqueueListenerConfig}.</li>
27+
* <li>{@link Backend#NATS} — both {@code RqueueListenerConfig} and {@code
28+
* RqueueNatsListenerConfig}.</li>
3229
* </ul>
3330
*/
3431
public class RqueueBackendImportSelector implements ImportSelector {
3532
@Override
3633
public String[] selectImports(AnnotationMetadata importingClassMetadata) {
37-
Backend backend = Backend.AUTO;
34+
Backend backend = Backend.REDIS;
3835
Object raw =
3936
importingClassMetadata.getAnnotationAttributes(EnableRqueue.class.getName()) == null
4037
? null
@@ -47,17 +44,14 @@ public String[] selectImports(AnnotationMetadata importingClassMetadata) {
4744
try {
4845
backend = Backend.valueOf(raw.toString());
4946
} catch (IllegalArgumentException ignored) {
50-
// keep AUTO
47+
// keep default
5148
}
5249
}
53-
List<String> imports = new ArrayList<>();
54-
imports.add(RqueueListenerConfig.class.getName());
5550
if (backend == Backend.NATS) {
56-
imports.add(RqueueNatsListenerConfig.class.getName());
57-
} else if (backend == Backend.AUTO) {
58-
// Conditionally registered via @Conditional in a thin wrapper.
59-
imports.add(ConditionalNatsConfig.class.getName());
51+
return new String[] {
52+
RqueueListenerConfig.class.getName(), RqueueNatsListenerConfig.class.getName()
53+
};
6054
}
61-
return imports.toArray(new String[0]);
55+
return new String[] {RqueueListenerConfig.class.getName()};
6256
}
6357
}

0 commit comments

Comments
 (0)