Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

@KafkaListener containerPostProcessor SpEL expression is not being evaluated #3544

Closed
moiMeme opened this issue Oct 8, 2024 · 0 comments · Fixed by #3548
Closed

@KafkaListener containerPostProcessor SpEL expression is not being evaluated #3544

moiMeme opened this issue Oct 8, 2024 · 0 comments · Fixed by #3548

Comments

@moiMeme
Copy link

moiMeme commented Oct 8, 2024

Affects Version(s): 3.3.4

Describe the bug

The SpEL expression in the containerPostProcessor of @KafkaListener is not being evaluated correctly.

Details
I am using the @KafkaListener annotation with a containerPostProcessor, and I need to pass a Spring Expression Language (SpEL) expression like:

public interface RecordListener<R> extends Consumer {

    @RetryableTopic(kafkaTemplate = "kafkaTemplate",
            exclude =  NoRetryableException.class,
            dltStrategy = DltStrategy.FAIL_ON_ERROR,
            attempts = "#{__listener.getContext().numberOfRetries}",
            backoff = @Backoff(delay = 3000, multiplier = 2.0, maxDelay = 240000),
            topicSuffixingStrategy = TopicSuffixingStrategy.SUFFIX_WITH_INDEX_VALUE)
    @KafkaListener(id = "#{__listener.getContext().id}", topics = "#{__listener.getContext().topic}",
            groupId = "#{__listener.getContext().groupId}", containerPostProcessor = "#{__batchListener.getContext().containerPostProcessor}",
            properties = {"#{__listener.getContext().customProperties}"})
    void onMessage(ConsumerRecord<String, R> record, Acknowledgment ack);
}

public interface Consumer {
    ConsumerContext getContext();   
}

@Data
@AllArgsConstructor
@Builder
public class ConsumerContext {
    private String id;
    private String groupId;
    private String topicIn;
    private String topicOut;
    private Integer concurrency;
    private Boolean autoStartup;
    private ConsumerType consumerType;
    private String[] customProperties;
    private String containerPostProcessor;
}

However, it seems that the SpEL expression is not being evaluated. The application fails to resolve the containerPostProcessor bean, and it does not process the expression.

I got this error:
Consider defining a bean named '#{__batchListener.getContext().containerPostProcessor}' in your configuration

In KafkaListenerAnnotationBeanPostProcessor method 'processKafkaListenerAnnotation' all KafkaListener fileds are beeing resolved except containerPostProcessor

@sobychacko sobychacko self-assigned this Oct 8, 2024
@sobychacko sobychacko added this to the 3.3.0-RC1 milestone Oct 8, 2024
sobychacko added a commit to sobychacko/spring-kafka that referenced this issue Oct 8, 2024
…rocessor

Fixes: spring-projects#3544

spring-projects#3544

- Enhance resolveContainerPostProcessor method in KafkaListenerAnnotationBeanPostProcessor
  to evaluate SpEL expressions
- Verify containerPostProcessor property in KafkaListener annotation can be specified as a SpEL expression
spring-builds pushed a commit that referenced this issue Oct 9, 2024
Fixes: #3544

#3544

- Enhance resolveContainerPostProcessor method in KafkaListenerAnnotationBeanPostProcessor
  to evaluate SpEL expressions
- Verify containerPostProcessor property in KafkaListener annotation can be specified as a SpEL expression

(cherry picked from commit 3f45fc0)
artembilan pushed a commit that referenced this issue Oct 9, 2024
Fixes: #3544

#3544

- Enhance resolveContainerPostProcessor method in KafkaListenerAnnotationBeanPostProcessor
  to evaluate SpEL expressions
- Verify containerPostProcessor property in KafkaListener annotation can be specified as a SpEL expression

(cherry picked from commit 3f45fc0)

# Conflicts:
#	spring-kafka/src/main/java/org/springframework/kafka/annotation/KafkaListenerAnnotationBeanPostProcessor.java
# for free to join this conversation on GitHub. Already have an account? # to comment