Skip to content

Commit faecba6

Browse files
committed
Allow null connection factory in Redis template constructors
When rqueue.backend=nats the new rqueueConfig factory leaves connectionFactory null. The downstream RqueueListenerBaseConfig's getMessageTemplate() still calls new RqueueMessageTemplateImpl(rqueueConfig.getConnectionFactory(), rqueueConfig.getReactiveRedisConnectionFactory()) which previously threw inside RedisTemplate.afterPropertiesSet() because the connection factory is required. The template bean isn't used on the NATS path (the broker SPI handles all message ops) but Spring still needs the bean type to satisfy autowires. Both the parent (RqueueRedisTemplate) and the child constructor now short-circuit on a null connection factory: redisTemplate stays null, the DefaultScriptExecutor isn't constructed, and any actual Redis operation will NPE loudly so a misconfiguration is easy to spot. This unblocks the NATS Spring Boot context from loading without forcing a Redis instance. Assisted-By: Claude Code
1 parent 4dda27e commit faecba6

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

rqueue-core/src/main/java/com/github/sonus21/rqueue/common/RqueueRedisTemplate.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,13 @@ public class RqueueRedisTemplate<V extends Serializable> {
3838
protected RedisTemplate<String, V> redisTemplate;
3939

4040
public RqueueRedisTemplate(RedisConnectionFactory redisConnectionFactory) {
41+
if (redisConnectionFactory == null) {
42+
// Permitted on the NATS backend path, where the template is constructed for type
43+
// satisfaction but never used for Redis operations. Leaving redisTemplate null fails
44+
// fast and obviously if anyone does try to use it.
45+
this.redisTemplate = null;
46+
return;
47+
}
4148
this.redisTemplate = RedisUtils.getRedisTemplate(redisConnectionFactory);
4249
this.redisTemplate.afterPropertiesSet();
4350
}

rqueue-core/src/main/java/com/github/sonus21/rqueue/core/impl/RqueueMessageTemplateImpl.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,9 @@ public RqueueMessageTemplateImpl(
6767
RedisConnectionFactory redisConnectionFactory,
6868
ReactiveRedisConnectionFactory reactiveRedisConnectionFactory) {
6969
super(redisConnectionFactory);
70-
this.scriptExecutor = new DefaultScriptExecutor<>(redisTemplate);
70+
// On the NATS backend path the connection factory is null and the Redis-script executors
71+
// are never invoked; leaving them null fails fast if anyone does try to use them.
72+
this.scriptExecutor = redisTemplate == null ? null : new DefaultScriptExecutor<>(redisTemplate);
7173
if (reactiveRedisConnectionFactory != null) {
7274
this.reactiveRedisTemplate =
7375
new ReactiveRqueueRedisTemplate<>(reactiveRedisConnectionFactory);

0 commit comments

Comments
 (0)