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

Fix Vert.x event bus codec registration #29446

Merged
merged 1 commit into from
Nov 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public void registerCodecs(

final IndexView index = beanArchiveIndexBuildItem.getIndex();
Collection<AnnotationInstance> consumeEventAnnotationInstances = index.getAnnotations(CONSUME_EVENT);
Map<Type, DotName> codecByTypes = new HashMap<>();
Map<DotName, DotName> codecByTypes = new HashMap<>();
for (AnnotationInstance consumeEventAnnotationInstance : consumeEventAnnotationInstances) {
AnnotationTarget typeTarget = consumeEventAnnotationInstance.target();
if (typeTarget.kind() != AnnotationTarget.Kind.METHOD) {
Expand All @@ -59,7 +59,7 @@ public void registerCodecs(
if (codecTargetFromParameter == null) {
throw new IllegalStateException("Invalid `codec` argument in @ConsumeEvent - no parameter");
}
codecByTypes.put(codecTargetFromParameter, codec.asClass().asClassType().name());
codecByTypes.put(codecTargetFromParameter.name(), codec.asClass().asClassType().name());
} else if (codecTargetFromParameter != null) {
// Codec is not set, check if we have a built-in codec
if (!hasBuiltInCodec(codecTargetFromParameter)) {
Expand All @@ -70,24 +70,24 @@ public void registerCodecs(
"The generic message codec can only be used for local delivery,"
+ ", implement your own event bus codec for " + codecTargetFromParameter.name()
.toString());
} else if (!codecByTypes.containsKey(codecTargetFromParameter)) {
} else if (!codecByTypes.containsKey(codecTargetFromParameter.name())) {
LOGGER.infof("Local Message Codec registered for type %s",
codecTargetFromParameter.toString());
codecByTypes.put(codecTargetFromParameter, LOCAL_EVENT_BUS_CODEC);
codecByTypes.put(codecTargetFromParameter.name(), LOCAL_EVENT_BUS_CODEC);
}
}
}

if (codecTargetFromReturnType != null && !hasBuiltInCodec(codecTargetFromReturnType)
&& !codecByTypes.containsKey(codecTargetFromReturnType)) {
&& !codecByTypes.containsKey(codecTargetFromReturnType.name())) {

LOGGER.infof("Local Message Codec registered for type %s", codecTargetFromReturnType.toString());
codecByTypes.put(codecTargetFromReturnType, LOCAL_EVENT_BUS_CODEC);
codecByTypes.put(codecTargetFromReturnType.name(), LOCAL_EVENT_BUS_CODEC);
}
}

// Produce the build items
for (Map.Entry<Type, DotName> entry : codecByTypes.entrySet()) {
for (Map.Entry<DotName, DotName> entry : codecByTypes.entrySet()) {
messageCodecs.produce(new MessageCodecBuildItem(entry.getKey().toString(), entry.getValue().toString()));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

import static org.assertj.core.api.Assertions.assertThat;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;

Expand Down Expand Up @@ -73,6 +77,11 @@ String getMessage() {
}
}

@Retention(RetentionPolicy.CLASS)
cescoffier marked this conversation as resolved.
Show resolved Hide resolved
@Target(ElementType.TYPE_USE)
@interface NonNull {
}

static class MyBean {
@ConsumeEvent("person")
public CompletionStage<Greeting> hello(Person p) {
Expand All @@ -83,6 +92,12 @@ public CompletionStage<Greeting> hello(Person p) {
public CompletionStage<Greeting> hello(Pet p) {
return CompletableFuture.completedFuture(new Greeting("Hello " + p.getName()));
}

// presence of this method is enough to verify that type annotation
// on the message type doesn't cause failure
@ConsumeEvent("message-type-with-type-annotation")
void messageTypeWithTypeAnnotation(@NonNull Person person) {
}
}

static class MyNonLocalBean {
Expand Down