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

AOT support for multiple binders #2655

Closed
kartik-kaushik opened this issue Feb 21, 2023 · 15 comments · Fixed by #2689
Closed

AOT support for multiple binders #2655

kartik-kaushik opened this issue Feb 21, 2023 · 15 comments · Fixed by #2689
Assignees

Comments

@kartik-kaushik
Copy link

I am trying to run a springboot3 native app with spring-cloud-stream-binder-rabbit dependency. Our application has multiple binders (e.g. usersevent, emailevent).
The normal application is working fine as expected but in native or aot-mode I am facing following issue.
When I tried with spring boot 3.0.0 and 3.0.2. the application is always taking the binder name as rabbit and connecting to localhost and not connecting to the url or binders defined in my property file
When I tried with spring boot 3.0.3-SNAPSHOT. The build failed with error

Pre-creating binder child context (AOT) for rabbit
Exception in thread "main" java.lang.IllegalArgumentException: Code generation is not supported for bean definitions declaring an instance supplier callback : Root bean: class [org.springframework.integration.config.MessagingAnnotationPostProcessor]; scope=singleton; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodNames=null; destroyMethodNames=null
at org.springframework.beans.factory.aot.BeanDefinitionMethodGenerator.(BeanDefinitionMethodGenerator.java:82)

Can someone please help in this regards.
Thanks

@magnus-larsson
Copy link

I think this problem also applies when only one binder is used.
To reproduce the error with 3.0.3-SNAPSHOT:

git clone https://github.com/spring-projects/spring-aot-smoke-tests.git
cd spring-aot-smoke-tests
./gradlew :cloud:cloud-stream-kafka:build
./gradlew :cloud:cloud-stream-rabbit:build

Both build commands will fail with the above error.

Changing to 3.0.3 in gradle.properties does not help.

Build status of spring-aot-smoke-tests can be monitored here: https://github.com/spring-projects/spring-aot-smoke-tests/blob/main/STATUS.adoc#cloud

@olegz
Copy link
Contributor

olegz commented Mar 1, 2023

@onobc referring to you as an AOT expert in streams. . . can you please take a look at that

@onobc
Copy link
Contributor

onobc commented Mar 1, 2023

Digging...

@onobc
Copy link
Contributor

onobc commented Mar 2, 2023

Some facts

The fix...

  • is to remove the instance suppliers from SI.
  • is in progress and should be in for a PR in the next 24hrs.
  • will be officially available in the 6.1.0-M2 release on 2023-03-22
  • will be available in a snapshot in the next 24-48hrs

@artembilan
Copy link
Contributor

... and Spring Integration 6.0.4 same date.

onobc added a commit to onobc/spring-integration that referenced this issue Mar 2, 2023
* Remove the use of instance suppliers on bean definitions
that are processed during the AOT phase.

* The remaining areas that use instance suppliers do so
at runtime and do not use reflection, but instead
are passed the configured bean to register.

See spring-cloud/spring-cloud-stream#2655
onobc added a commit to onobc/spring-integration that referenced this issue Mar 2, 2023
* Remove the use of instance suppliers on bean definitions
that are processed during the AOT phase.

* The remaining areas that use instance suppliers do so
at runtime and do not use reflection, but instead
are passed the configured bean to register.

See spring-cloud/spring-cloud-stream#2655
artembilan pushed a commit to spring-projects/spring-integration that referenced this issue Mar 3, 2023
* Remove the use of instance suppliers on bean definitions
that are processed during the AOT phase.

* The remaining areas that use instance suppliers do so
at runtime and do not use reflection, but instead
are passed the configured bean to register.

See spring-cloud/spring-cloud-stream#2655

**Cherry-pick to `6.0.x`**
artembilan pushed a commit to spring-projects/spring-integration that referenced this issue Mar 3, 2023
* Remove the use of instance suppliers on bean definitions
that are processed during the AOT phase.

* The remaining areas that use instance suppliers do so
at runtime and do not use reflection, but instead
are passed the configured bean to register.

See spring-cloud/spring-cloud-stream#2655

**Cherry-pick to `6.0.x`**
@patpatpat123
Copy link

adding myself here

@magnus-larsson
Copy link

It seems like the problem is resolved now, using Spring Boot 3.0.5-SNAPSHOT. Both https://github.com/spring-projects/spring-aot-smoke-tests/blob/main/STATUS.adoc#cloud and https://ci.spring.io/teams/spring-aot-smoke-tests/pipelines/spring-aot-smoke-tests-1.0.x/jobs/integration-app-test are green now!

@kartik-kaushik
Copy link
Author

Using versions as below:
springboot:3.0.5-SNAPSHOT
cloud:2022.0.1
java:17
spring-cloud-stream-binder-rabbit:4.0.1
spring-cloud-stream:4.0.1

Main Class:
@SpringBootApplication
public class SpringStreamApplication {   public static void main(String[] args) {
    SpringApplication.run(SpringStreamApplication.class, args);
  }   @bean
  public Function<String, String> service() {
    return v -> v;
  } }
 
application.yaml
server:
  port: 8090
management.endpoint.health.show-details: always
management.endpoints.web.exposure.include: "*"
spring:
  cloud:
    stream:
      rabbit:
        bindings:
          emailevent:
            producer:
              routingKeyExpression: events.in
              exchangeType: direct
              use-confirm-header: true
          audit:
            producer:
              exchangeType: fanout
              use-confirm-header: true
      default-binder: emaileventrmq
      binders:
        userrmq:
          type: rabbit
          environment:
            spring:
              rabbitmq:
                virtual-host: vents
                host: dev.com
                port: 5672
                username: user
                password: pass
                ssl:
                  enabled: false
                publisher-confirms: true
                publisher-returns: true
                publisher-confirm-type: correlated
                template:
                  retry:
                    max-attempts: 4
                    maxInterval: 600000
                    initialInterval: 120000
        emaileventrmq:
          type: rabbit
          environment:
            spring:
              rabbitmq:
                virtual-host: sdp
                host: dev.com
                port: 5672
                username: user
                password: pass
                ssl:
                  enabled: false
                publisher-confirms: true
                publisher-returns: true
                publisher-confirm-type: correlated
                template:
                  retry:
                    max-attempts: 4
                    maxInterval: 600000
                    initialInterval: 120000
      bindings:
        audit:
          producer:
            error-channel-enabled: true
          binder: userrmq
          destination: e.user.events
        emailevent:
          binder: emaileventrmq
          destination: e.events
         
         
We are still getting the binder name as default rabbit and not the one provided in the application.yml file. The same is working fine as non-native but still natively the issue persists. Please highlight if we are missing something.
Thanks!          
 

@kartik-kaushik
Copy link
Author

@onobc any update on the above?

@onobc
Copy link
Contributor

onobc commented Mar 31, 2023

@kartik-kaushik I have not had a chance to look at this since your report. I will try to get to it today though.

@onobc
Copy link
Contributor

onobc commented Mar 31, 2023

@kartik-kaushik do. you mind bumping up to the following and trying again:

  • springboot: 3.0.5
  • cloud: 2022.0.2
  • spring-cloud-stream-binder-rabbit: 4.0.2
  • spring-cloud-stream: 4.0.2

A few questions as well:

  • Are you using buildpacks or GraalVM build tools to build the native image?
  • If build tools, what version of GraalVM are you using?
  • Are you using Gradle or Maven? If you can give me the steps you are using to build that may be helpful.

Thanks

@kartik-kaushik
Copy link
Author

@onobc it didn't worked with the above as well.
Below are the response for your need:

Are you using buildpacks or GraalVM build tools to build the native image?
-> GraalVM build tools

If build tools, what version of GraalVM are you using?
-> graalvm-ce-java17-22.3.0

Are you using Gradle or Maven? If you can give me the steps you are using to build that may be helpful.
-> Maven.
Building native image using command
mvn -Pnative native:compile

@onobc
Copy link
Contributor

onobc commented Apr 1, 2023

I have reproduced the issue locally (using Kafka and multiple binders). I will now try to figure out the cause @kartik-kaushik . I should have some info by the end of the weekend.

@onobc
Copy link
Contributor

onobc commented Apr 3, 2023

@kartik-kaushik I will be submitting a PR in the next few hours.

onobc added a commit to onobc/spring-cloud-stream that referenced this issue Apr 3, 2023
- Adds support for AOT child context generation
  for user-declared binder configurations.
@onobc
Copy link
Contributor

onobc commented Apr 3, 2023

PR submitted - here is the cause summarized:

The underlying cause of this issue was two-fold.

  1. At AOT-build time: The generated binder child contexts were not taking the user-declared binder configs into consideration: GH-2655: AOT support user declared binders #2689 (comment)

  2. At AOT/native run time: The initialized child contexts were not taking the user-declared binder configs into consideration: GH-2655: AOT support user declared binders #2689 (comment)

onobc added a commit to onobc/spring-cloud-stream that referenced this issue Apr 3, 2023
- Adds support for AOT child context generation
  for user-declared binder configurations.

Fixes spring-cloud#2655
@onobc onobc changed the title Aot support for multiple binders for RMQ AOT support for multiple binders for RMQ Apr 3, 2023
@onobc onobc changed the title AOT support for multiple binders for RMQ AOT support for multiple binders Apr 3, 2023
sobychacko pushed a commit that referenced this issue Apr 5, 2023
- Adds support for AOT child context generation
  for user-declared binder configurations.

Fixes #2655
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

6 participants