Skip to content
New issue

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

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

Already on GitHub? Sign in to your account

Support inject a list of values in expression language #10928

Open
yibo-long opened this issue Jun 27, 2024 · 0 comments
Open

Support inject a list of values in expression language #10928

yibo-long opened this issue Jun 27, 2024 · 0 comments
Labels
type: enhancement New feature or request

Comments

@yibo-long
Copy link

Feature description

I am looking for a way to inject an array of String with the expression language. My main goal is to manage the Kafka subscription in a more structural way with the expression language, but when I almost hit my goal I realized it could only resolve to a single string.

I would be able to construct the topics with the following beans:

@Context
@Singleton
class SubscribedTopics(
    val topics: List<SubscribedTopic>,
) {
    fun constructTopics(): List<String> {
        val values = topics.map { it.getTopic() }
        return values
    }
}

@EachProperty("application.topics")
data class SubscribedTopic @ConfigurationInject constructor(
    @Parameter val name: String,
    val id1: Int,
    val id2: Int,
) {
    fun getTopic(): String = "topic_v${id1}_t$id2"
}

and then use the following for creating the Kafka listener:

@KafkaListener
class KafkaConsumer {
    @Topic("#{ ctx[SubscribedTraits].constructTopics() }")
    fun consumeTraitMessage(
        @KafkaKey resourceId: String,
        message: ByteArray,
    ) {
      // run
    }
}

however the logs indicate the properties are resolved into a single string instead of an array of strings:

20:56:04.333 [Test worker] INFO  o.a.k.clients.consumer.KafkaConsumer - [Consumer clientId=foo-consumer, groupId=foo] Subscribed to topic(s): [topic_v1_t22, topic_v1_t18, topic_v1_t19, topic_v1_t3]
20:56:04.333 [Test worker] INFO  i.m.c.k.p.KafkaConsumerProcessor - Kafka listener [KafkaTraitConsumer#consumeTraitMessage] subscribed to topics: [[topic_v1_t22, topic_v1_t18, topic_v1_t19, topic_v1_t3]]

I checked micronaut-kafka is resolving it as stringValues. Is there any way for the expression language to support resolving from List to stringValues?

@graemerocher graemerocher added the type: enhancement New feature or request label Aug 6, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants