Skip to content

Commit

Permalink
Merge pull request #29446 from Ladicek/fix-eventbus-codec-registration
Browse files Browse the repository at this point in the history
Fix Vert.x event bus codec registration
  • Loading branch information
cescoffier authored Nov 24, 2022
2 parents df6cad8 + bba49af commit d3e22a0
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
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)
@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

0 comments on commit d3e22a0

Please sign in to comment.