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

Passing null value for a String @MessageHeader parameter in a @PubSubClient results in a "null" String literal on the receiver side #1236

Open
balapal opened this issue Nov 26, 2024 · 1 comment
Labels
info: good first issue Good for newcomers type: bug Something isn't working

Comments

@balapal
Copy link

balapal commented Nov 26, 2024

Expected Behavior

When passing in a null value in @MessageHeader parameter of a @PubSubCLient method I would expect a null value on the receiver side and not a "null" String literal.

Actual Behaviour

The receiver side has "null" String literal value instead of null

Steps To Reproduce

Send a message with by calling the below send method for example: client.send("message body goes here", null);

import io.micronaut.gcp.pubsub.annotation.PubSubClient;
import io.micronaut.gcp.pubsub.annotation.Topic;
import io.micronaut.messaging.annotation.MessageHeader;
import reactor.core.publisher.Mono;

@PubSubClient
public interface ExamplePubSubClient {
    @Topic("topic-name")
    Mono<String> send(String messageContent,
                      @MessageHeader("route") String route);
}
package micronaut.reproduce;

import com.google.pubsub.v1.PubsubMessage;
import io.micronaut.gcp.pubsub.annotation.Subscription;
import io.micronaut.messaging.Acknowledgement;
import io.micronaut.messaging.annotation.MessageBody;
import io.micronaut.messaging.annotation.MessageHeader;
import reactor.core.publisher.Mono;

@io.micronaut.gcp.pubsub.annotation.PubSubListener
public class PubSubListener {
    
    @Subscription("topic-name")
    Mono<Long> onMessage(
            @MessageBody PubsubMessage messageBody,
            @MessageHeader String route,
            Acknowledgement ack
            ) {
        // I need to add this null mapping to work properly and I think this is a bug
        route = "null".equals(route) ? null : route;
        // The issue manifests also when the value is extracted from the messageBody
        var route2 = messageBody.getAttributesOrDefault("route", null);
        route2 = "null".equals(route2) ? null : route2;
        return Mono.empty();
    }
}

Environment Information

JDK 21
Micronaut Parent version: 4.6.3

Example Application

No response

Version

4.6.3

@graemerocher graemerocher added type: bug Something isn't working info: good first issue Good for newcomers labels Nov 26, 2024
@balapal
Copy link
Author

balapal commented Nov 27, 2024

I suspect there is an issue with the client as both ways of reading the message header returns "null" String literal.

Also the version of listener works fine with the client that does not take (and therefore send) @MessageHeader("route") String route parameter.
Perhaps the header should be omitted by the client when the value is null (meaning it is not set)?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
info: good first issue Good for newcomers type: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants