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

[FEATURE] @Channel annotation should be able to target function in addition to class #75

Open
2 tasks done
azizabah opened this issue Dec 5, 2024 · 1 comment · May be fixed by #76
Open
2 tasks done

[FEATURE] @Channel annotation should be able to target function in addition to class #75

azizabah opened this issue Dec 5, 2024 · 1 comment · May be fixed by #76
Labels
enhancement New feature or request

Comments

@azizabah
Copy link

azizabah commented Dec 5, 2024

Why do we need this improvement?

When utilizing Spring Cloud Stream to create interactions with messaging services, it is common to have functions that create Beans that are then utilized for sending and receiving messages.

  @Bean
  fun consumeAlertEvent(
      alertEventProcessor: AlertEventProcessor,
      objectMapper: ObjectMapper,
  ): Consumer<Message<String>> {
      return Consumer<Message<String>> { message ->
          alertEventProcessor.processEvent(
              objectMapper.readValue(
                  message.payload,
                  AlertableEventMessage::class.java,
              ),
          )
      }
  }

How will this change help?

Currently to wrap this using this library, you have to create a wrapper class around it like this:

@Channel(
        bindings = ChannelBindings(amqp = ChannelBinding.AMQP(queue = ChannelBinding.AMQPQueue(name = "alerts"))),
        publish = Publish(message = AsyncApiMessage(AlertableEventMessage::class)),
        description = "Queue used to receive alerts.",
    )
    class ConsumeAlertEvent {
        @Bean
        fun consumeAlertEvent(
            alertEventProcessor: AlertEventProcessor,
            objectMapper: ObjectMapper,
        ): Consumer<Message<String>> {
            return Consumer<Message<String>> { message ->
                alertEventProcessor.processEvent(
                    objectMapper.readValue(
                        message.payload,
                        AlertableEventMessage::class.java,
                    ),
                )
            }
        }
    }

This is a lot of unnecessary verboseness in Spring Boot Kotlin.

Screenshots

No response

How could it be implemented/designed?

Adjusting this Target code to also allow for functions should resolve the issue.

🚧 Breaking changes

No

👀 Have you checked for similar open issues?

  • I checked and didn't find a similar issue

🏢 Have you read the Contributing Guidelines?

Are you willing to work on this issue?

Yes I am willing to submit a PR!

@azizabah azizabah added the enhancement New feature or request label Dec 5, 2024
Copy link

github-actions bot commented Dec 5, 2024

Welcome to AsyncAPI. Thanks a lot for reporting your first issue. Please check out our contributors guide and the instructions about a basic recommended setup useful for opening a pull request.
Keep in mind there are also other channels you can use to interact with AsyncAPI community. For more details check out this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
1 participant