Bridge Demo

The purpose of this project is to demonstrate a natively compiled Java app where a bean’s method parameters are always null regardless of what is passed.

Background

Spring Cloud Task will emit messages to a stream (RabbitMQ Exchange, Kafka Topic) upon task startup and shutdown when the Spring Cloud Stream Starter is included in the dependencies. When using a traditional compilation or when Spring-AOT is enabled the application behaves as expected. However, when the application is natively compiled the application throws an NPE.

What is being observed

In this sample you should see a task-events and howdy exchange created in RabbitMQ. The task-events exchange should receive a TaskExecution message and the howdy exchange will receive a message of hello. In its current state you will see an NPE thrown here. This is because the result parameter is null. However, when I checked the value for the resultMessage that is used for parameter 0 (result) prior to it be being called here, the value was populated. However when it is received by Spring Cloud Function here it is null. If you disable the Spring Cloud Task event feature by setting spring.cloud.task.events.enabled=false in the jvm args at compile time, the howdy exchange is created and a message of hello is sent. This can be done by uncommenting the following lines here then natively compiling the sample.

The question

Why is the parameter being passed in null when nativily compiled but populated when the JVM and JVM+AOT are functioning?

Requirements:

  • Java 17 or Above

Build:

Traditional JVM Build

./mvnw clean package

Native Build

./mvnw -Pnative clean package

Setup:

You will need an instance of RabbitMQ running. You can use the following to start a simple Rabbitmq instance.

docker run -d --hostname my-rabbit --name manager-rabbit -p 15672:15672 -p 5672:5672 rabbitmq:3-management

Execution:

Traditional Execution

java -jar target/bridgedemo-0.0.1-SNAPSHOT.jar

AOT Execution

java -Dspring.aot.enabled=true -jar target/bridgedemo-0.0.1-SNAPSHOT.jar

Native Execution

./target/bridgedemo