Skip to content

Commit

Permalink
fix: create new methods in BindingFactory instead of changing the exi…
Browse files Browse the repository at this point in the history
…sting ones, move bean ref logic to KafkaBeanRefHelper, implement BindingContext for passing Method and Class context to factories
  • Loading branch information
ruskaof committed Dec 2, 2024
1 parent 4033a98 commit 9f32935
Show file tree
Hide file tree
Showing 9 changed files with 9 additions and 51 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,19 +11,22 @@
import java.util.Map;

public interface BindingFactory<T> {
@Deprecated // maintainer note: replaced by #getChannelId(T, BindingContext)

// maintainer note: replaced by #getChannelId(T, BindingContext)
default String getChannelId(T annotation) {
return ReferenceUtil.toValidId(getChannelName(annotation));
}

@Deprecated // maintainer note: replaced by #getChannelName(T, BindingContext)
// maintainer note: replaced by #getChannelName(T, BindingContext)
String getChannelName(T annotation);

default String getChannelId(T annotation, BindingContext bindingContext) {
return ReferenceUtil.toValidId(getChannelName(annotation, bindingContext));
return getChannelId(annotation);
}

String getChannelName(T annotation, BindingContext bindingContext);
default String getChannelName(T annotation, BindingContext bindingContext) {
return getChannelName(annotation);
}

Map<String, ChannelBinding> buildChannelBinding(T annotation);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import io.github.springwolf.core.asyncapi.components.examples.walkers.DefaultSchemaWalker;
import io.github.springwolf.core.asyncapi.components.examples.walkers.json.ExampleJsonValueGenerator;
import io.github.springwolf.core.asyncapi.scanners.bindings.BindingFactory;
import io.github.springwolf.core.asyncapi.scanners.bindings.common.BindingContext;
import io.github.springwolf.core.asyncapi.scanners.common.channel.SpringAnnotationChannelService;
import io.github.springwolf.core.asyncapi.scanners.common.headers.AsyncHeadersNotDocumented;
import io.github.springwolf.core.asyncapi.scanners.common.headers.HeaderClassExtractor;
Expand Down Expand Up @@ -296,11 +295,6 @@ public String getChannelName(TestClassListener annotation) {
return CHANNEL;
}

@Override
public String getChannelName(TestClassListener annotation, BindingContext bindingContext) {
return CHANNEL;
}

@Override
public Map<String, ChannelBinding> buildChannelBinding(TestClassListener annotation) {
return defaultChannelBinding;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
import io.github.springwolf.core.asyncapi.components.examples.walkers.DefaultSchemaWalker;
import io.github.springwolf.core.asyncapi.components.examples.walkers.json.ExampleJsonValueGenerator;
import io.github.springwolf.core.asyncapi.scanners.bindings.BindingFactory;
import io.github.springwolf.core.asyncapi.scanners.bindings.common.BindingContext;
import io.github.springwolf.core.asyncapi.scanners.common.channel.SpringAnnotationChannelService;
import io.github.springwolf.core.asyncapi.scanners.common.headers.AsyncHeadersNotDocumented;
import io.github.springwolf.core.asyncapi.scanners.common.headers.HeaderClassExtractor;
Expand Down Expand Up @@ -316,11 +315,6 @@ public String getChannelName(TestChannelListener annotation) {
return CHANNEL;
}

@Override
public String getChannelName(TestChannelListener annotation, BindingContext bindingContext) {
return CHANNEL;
}

@Override
public Map<String, ChannelBinding> buildChannelBinding(TestChannelListener annotation) {
return defaultChannelBinding;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@
@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")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import io.github.springwolf.asyncapi.v3.bindings.OperationBinding;
import io.github.springwolf.asyncapi.v3.model.schema.SchemaObject;
import io.github.springwolf.core.asyncapi.scanners.bindings.BindingFactory;
import io.github.springwolf.core.asyncapi.scanners.bindings.common.BindingContext;
import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.Exchange;
import org.springframework.amqp.core.Queue;
Expand Down Expand Up @@ -39,16 +38,6 @@ public String getChannelId(RabbitListener annotation) {
return RabbitListenerUtil.getChannelId(annotation, stringValueResolver);
}

@Override
public String getChannelId(RabbitListener annotation, BindingContext bindingContext) {
return BindingFactory.super.getChannelId(annotation, bindingContext);
}

@Override
public String getChannelName(RabbitListener annotation, BindingContext bindingContext) {
return RabbitListenerUtil.getChannelName(annotation, stringValueResolver);
}

@Override
public Map<String, ChannelBinding> buildChannelBinding(RabbitListener annotation) {
return RabbitListenerUtil.buildChannelBinding(annotation, stringValueResolver, context);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import io.github.springwolf.asyncapi.v3.bindings.OperationBinding;
import io.github.springwolf.asyncapi.v3.model.schema.SchemaObject;
import io.github.springwolf.core.asyncapi.scanners.bindings.BindingFactory;
import io.github.springwolf.core.asyncapi.scanners.bindings.common.BindingContext;
import lombok.RequiredArgsConstructor;
import org.springframework.util.StringValueResolver;

Expand All @@ -22,11 +21,6 @@ public String getChannelName(SqsListener annotation) {
return SqsListenerUtil.getChannelName(annotation, stringValueResolver);
}

@Override
public String getChannelName(SqsListener annotation, BindingContext bindingContext) {
return SqsListenerUtil.getChannelName(annotation, stringValueResolver);
}

@Override
public Map<String, ChannelBinding> buildChannelBinding(SqsListener annotation) {
return SqsListenerUtil.buildChannelBinding(annotation, stringValueResolver);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import io.github.springwolf.asyncapi.v3.bindings.OperationBinding;
import io.github.springwolf.asyncapi.v3.model.schema.SchemaObject;
import io.github.springwolf.core.asyncapi.scanners.bindings.BindingFactory;
import io.github.springwolf.core.asyncapi.scanners.bindings.common.BindingContext;
import io.github.springwolf.plugins.stomp.asyncapi.scanners.common.MessageMappingUtil;
import io.github.springwolf.plugins.stomp.configuration.properties.SpringwolfStompConfigProperties;
import lombok.RequiredArgsConstructor;
Expand All @@ -25,11 +24,6 @@ public String getChannelName(MessageMapping annotation) {
return properties.getEndpoint().getApp() + MessageMappingUtil.getChannelName(annotation, stringValueResolver);
}

@Override
public String getChannelName(MessageMapping annotation, BindingContext bindingContext) {
return properties.getEndpoint().getApp() + MessageMappingUtil.getChannelName(annotation, stringValueResolver);
}

@Override
public Map<String, ChannelBinding> buildChannelBinding(MessageMapping annotation) {
return MessageMappingUtil.buildChannelBinding();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import io.github.springwolf.asyncapi.v3.bindings.OperationBinding;
import io.github.springwolf.asyncapi.v3.model.schema.SchemaObject;
import io.github.springwolf.core.asyncapi.scanners.bindings.BindingFactory;
import io.github.springwolf.core.asyncapi.scanners.bindings.common.BindingContext;
import io.github.springwolf.plugins.stomp.asyncapi.scanners.common.SendToUtil;
import io.github.springwolf.plugins.stomp.configuration.properties.SpringwolfStompConfigProperties;
import lombok.RequiredArgsConstructor;
Expand All @@ -25,11 +24,6 @@ public String getChannelName(SendTo annotation) {
return properties.getEndpoint().getApp() + SendToUtil.getChannelName(annotation, stringValueResolver);
}

@Override
public String getChannelName(SendTo annotation, BindingContext bindingContext) {
return properties.getEndpoint().getApp() + SendToUtil.getChannelName(annotation, stringValueResolver);
}

@Override
public Map<String, ChannelBinding> buildChannelBinding(SendTo annotation) {
return SendToUtil.buildChannelBinding();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import io.github.springwolf.asyncapi.v3.bindings.OperationBinding;
import io.github.springwolf.asyncapi.v3.model.schema.SchemaObject;
import io.github.springwolf.core.asyncapi.scanners.bindings.BindingFactory;
import io.github.springwolf.core.asyncapi.scanners.bindings.common.BindingContext;
import io.github.springwolf.plugins.stomp.asyncapi.scanners.common.SendToUserUtil;
import io.github.springwolf.plugins.stomp.asyncapi.scanners.common.SendToUtil;
import io.github.springwolf.plugins.stomp.configuration.properties.SpringwolfStompConfigProperties;
Expand All @@ -26,11 +25,6 @@ public String getChannelName(SendToUser annotation) {
return properties.getEndpoint().getUser() + SendToUserUtil.getChannelName(annotation, stringValueResolver);
}

@Override
public String getChannelName(SendToUser annotation, BindingContext bindingContext) {
return properties.getEndpoint().getUser() + SendToUserUtil.getChannelName(annotation, stringValueResolver);
}

@Override
public Map<String, ChannelBinding> buildChannelBinding(SendToUser annotation) {
return SendToUserUtil.buildChannelBinding();
Expand Down

0 comments on commit 9f32935

Please sign in to comment.