-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: create new methods in BindingFactory instead of changing the exi…
…sting ones, move bean ref logic to KafkaBeanRefHelper, implement BindingContext for passing Method and Class context to factories
- Loading branch information
Showing
26 changed files
with
289 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
...main/java/io/github/springwolf/core/asyncapi/scanners/bindings/common/BindingContext.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package io.github.springwolf.core.asyncapi.scanners.bindings.common; | ||
|
||
import java.lang.reflect.Method; | ||
|
||
public record BindingContext(Class<?> annotatedClass, Method annotatedMethod) { | ||
public BindingContext { | ||
if (annotatedClass == null && annotatedMethod == null) { | ||
throw new IllegalArgumentException("Either annotatedClass or annotatedMethod must be non-null"); | ||
} | ||
} | ||
|
||
public Class<?> getClassContext() { | ||
if (annotatedClass != null) { | ||
return annotatedClass; | ||
} | ||
if (annotatedMethod != null) { | ||
return annotatedMethod.getDeclaringClass(); | ||
} | ||
|
||
throw new IllegalStateException("Either annotatedClass or annotatedMethod must be non-null"); | ||
} | ||
|
||
public static BindingContext ofAnnotatedMethod(Method annotatedMethod) { | ||
return new BindingContext(null, annotatedMethod); | ||
} | ||
|
||
public static BindingContext ofAnnotatedClass(Class<?> annotatedClass) { | ||
return new BindingContext(annotatedClass, null); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
.../main/java/io/github/springwolf/examples/kafka/consumers/ExampleBeanRefKafkaListener.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
// SPDX-License-Identifier: Apache-2.0 | ||
package io.github.springwolf.examples.kafka.consumers; | ||
|
||
import io.github.springwolf.examples.kafka.dtos.AnotherPayloadDto; | ||
import io.github.springwolf.examples.kafka.dtos.ExamplePayloadDto; | ||
import io.github.springwolf.examples.kafka.producers.AnotherProducer; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.kafka.annotation.KafkaListener; | ||
import org.springframework.kafka.support.KafkaHeaders; | ||
import org.springframework.messaging.handler.annotation.Header; | ||
import org.springframework.messaging.handler.annotation.Payload; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.List; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class ExampleBeanRefKafkaListener { | ||
|
||
@SuppressWarnings("unused") | ||
public final String TOPIC_NAME = "example-topic-from-bean-ref"; | ||
|
||
private final AnotherProducer anotherProducer; | ||
|
||
@KafkaListener(topics = "#{myListener.TOPIC_NAME}", beanRef = "myListener") | ||
public void receiveExamplePayload( | ||
@Header(KafkaHeaders.RECEIVED_KEY) String key, | ||
@Header(KafkaHeaders.OFFSET) Integer offset, | ||
@Payload ExamplePayloadDto payload) { | ||
log.info("Received new message in example-topic: {}", payload.toString()); | ||
|
||
AnotherPayloadDto example = new AnotherPayloadDto(); | ||
example.setExample(payload); | ||
example.setFoo("foo"); | ||
|
||
anotherProducer.sendMessage(example); | ||
} | ||
|
||
@KafkaListener(topicPattern = "another-topic", groupId = "example-group-id", batch = "true") | ||
public void receiveAnotherPayloadBatched(List<AnotherPayloadDto> payloads) { | ||
log.info("Received new message in another-topic: {}", payloads.toString()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.