Use meta-annotation for @EnableBinding
Now user can specify transport via the main annotation:
@EnableBinding(value=Sink, transport="rabbit")
@Log
class App {
@ServiceActivator(inputChannel=Sink.INPUT)
void loggerSink(Object payload) {
log.info("Received: " + payload)
}
}
This commit is contained in:
@@ -23,6 +23,7 @@ import java.lang.annotation.RetentionPolicy;
|
||||
import java.lang.annotation.Target;
|
||||
|
||||
import org.springframework.cloud.cli.compiler.StreamRabbitCompilerAutoConfiguration;
|
||||
import org.springframework.core.annotation.AliasFor;
|
||||
|
||||
/**
|
||||
* Pseudo annotation used to trigger {@link StreamRabbitCompilerAutoConfiguration} and
|
||||
@@ -34,6 +35,7 @@ import org.springframework.cloud.cli.compiler.StreamRabbitCompilerAutoConfigurat
|
||||
@org.springframework.cloud.stream.annotation.EnableBinding
|
||||
public @interface EnableBinding {
|
||||
|
||||
@AliasFor(annotation=org.springframework.cloud.stream.annotation.EnableBinding.class, attribute="value")
|
||||
Class<?>[]value() default {};
|
||||
|
||||
String transport() default "redis";
|
||||
|
||||
@@ -0,0 +1,69 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.cloud.cli.compiler;
|
||||
|
||||
import org.codehaus.groovy.ast.AnnotationNode;
|
||||
import org.codehaus.groovy.ast.ClassNode;
|
||||
import org.codehaus.groovy.ast.expr.Expression;
|
||||
import org.codehaus.groovy.control.CompilationFailedException;
|
||||
import org.codehaus.groovy.control.customizers.ImportCustomizer;
|
||||
import org.springframework.boot.cli.compiler.AstUtils;
|
||||
import org.springframework.boot.cli.compiler.CompilerAutoConfiguration;
|
||||
import org.springframework.boot.cli.compiler.autoconfigure.SpringIntegrationCompilerAutoConfiguration;
|
||||
import org.springframework.util.PatternMatchUtils;
|
||||
import org.springframework.util.SystemPropertyUtils;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public abstract class BaseStreamCompilerAutoConfiguration extends CompilerAutoConfiguration {
|
||||
|
||||
private SpringIntegrationCompilerAutoConfiguration integration = new SpringIntegrationCompilerAutoConfiguration();
|
||||
|
||||
@Override
|
||||
public boolean matches(ClassNode classNode) {
|
||||
boolean annotated = AstUtils.hasAtLeastOneAnnotation(classNode, "EnableBinding");
|
||||
return annotated && isTransport(classNode, getTransport());
|
||||
}
|
||||
|
||||
protected abstract String getTransport();
|
||||
|
||||
static boolean isTransport(ClassNode node, String type) {
|
||||
for (AnnotationNode annotationNode : node.getAnnotations()) {
|
||||
String annotation = "EnableBinding";
|
||||
if (PatternMatchUtils.simpleMatch(annotation,
|
||||
annotationNode.getClassNode().getName())) {
|
||||
Expression expression = annotationNode.getMembers().get("transport");
|
||||
String transport = expression == null ? "redis" : expression.getText();
|
||||
if (transport != null) {
|
||||
transport = SystemPropertyUtils.resolvePlaceholders(transport);
|
||||
}
|
||||
return transport.equals(type);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyImports(ImportCustomizer imports) throws CompilationFailedException {
|
||||
this.integration.applyImports(imports);
|
||||
imports.addImports("org.springframework.boot.groovy.cloud.EnableBinding");
|
||||
imports.addStarImports("org.springframework.cloud.stream.annotation",
|
||||
"org.springframework.cloud.stream.messaging");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,23 +15,18 @@
|
||||
*/
|
||||
package org.springframework.cloud.cli.compiler;
|
||||
|
||||
import org.codehaus.groovy.ast.ClassNode;
|
||||
import org.codehaus.groovy.control.CompilationFailedException;
|
||||
import org.codehaus.groovy.control.customizers.ImportCustomizer;
|
||||
import org.springframework.boot.cli.compiler.AstUtils;
|
||||
import org.springframework.boot.cli.compiler.CompilerAutoConfiguration;
|
||||
import org.springframework.boot.cli.compiler.DependencyCustomizer;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class StreamKafkaCompilerAutoConfiguration extends CompilerAutoConfiguration {
|
||||
public class StreamKafkaCompilerAutoConfiguration
|
||||
extends BaseStreamCompilerAutoConfiguration {
|
||||
|
||||
@Override
|
||||
public boolean matches(ClassNode classNode) {
|
||||
boolean annotated = AstUtils.hasAtLeastOneAnnotation(classNode, "EnableBinding");
|
||||
return annotated && StreamRedisCompilerAutoConfiguration.isTransport(classNode, "kafka");
|
||||
protected String getTransport() {
|
||||
return "kafka";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -42,11 +37,4 @@ public class StreamKafkaCompilerAutoConfiguration extends CompilerAutoConfigurat
|
||||
.add("spring-cloud-starter-stream-kafka");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyImports(ImportCustomizer imports) throws CompilationFailedException {
|
||||
imports.addImports("org.springframework.boot.groovy.cloud.EnableBinding");
|
||||
imports.addStarImports("org.springframework.cloud.stream.annotation",
|
||||
"org.springframework.cloud.stream.messaging");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,23 +15,18 @@
|
||||
*/
|
||||
package org.springframework.cloud.cli.compiler;
|
||||
|
||||
import org.codehaus.groovy.ast.ClassNode;
|
||||
import org.codehaus.groovy.control.CompilationFailedException;
|
||||
import org.codehaus.groovy.control.customizers.ImportCustomizer;
|
||||
import org.springframework.boot.cli.compiler.AstUtils;
|
||||
import org.springframework.boot.cli.compiler.CompilerAutoConfiguration;
|
||||
import org.springframework.boot.cli.compiler.DependencyCustomizer;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class StreamRabbitCompilerAutoConfiguration extends CompilerAutoConfiguration {
|
||||
public class StreamRabbitCompilerAutoConfiguration
|
||||
extends BaseStreamCompilerAutoConfiguration {
|
||||
|
||||
@Override
|
||||
public boolean matches(ClassNode classNode) {
|
||||
boolean annotated = AstUtils.hasAtLeastOneAnnotation(classNode, "EnableBinding");
|
||||
return annotated && StreamRedisCompilerAutoConfiguration.isTransport(classNode, "rabbit");
|
||||
protected String getTransport() {
|
||||
return "rabbit";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -42,11 +37,4 @@ public class StreamRabbitCompilerAutoConfiguration extends CompilerAutoConfigura
|
||||
.add("spring-cloud-starter-stream-rabbit");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyImports(ImportCustomizer imports) throws CompilationFailedException {
|
||||
imports.addImports("org.springframework.boot.groovy.cloud.EnableBinding");
|
||||
imports.addStarImports("org.springframework.cloud.stream.annotation",
|
||||
"org.springframework.cloud.stream.messaging");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,43 +15,18 @@
|
||||
*/
|
||||
package org.springframework.cloud.cli.compiler;
|
||||
|
||||
import org.codehaus.groovy.ast.AnnotationNode;
|
||||
import org.codehaus.groovy.ast.ClassNode;
|
||||
import org.codehaus.groovy.ast.expr.Expression;
|
||||
import org.codehaus.groovy.control.CompilationFailedException;
|
||||
import org.codehaus.groovy.control.customizers.ImportCustomizer;
|
||||
import org.springframework.boot.cli.compiler.AstUtils;
|
||||
import org.springframework.boot.cli.compiler.CompilerAutoConfiguration;
|
||||
import org.springframework.boot.cli.compiler.DependencyCustomizer;
|
||||
import org.springframework.util.PatternMatchUtils;
|
||||
import org.springframework.util.SystemPropertyUtils;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class StreamRedisCompilerAutoConfiguration extends CompilerAutoConfiguration {
|
||||
public class StreamRedisCompilerAutoConfiguration
|
||||
extends BaseStreamCompilerAutoConfiguration {
|
||||
|
||||
@Override
|
||||
public boolean matches(ClassNode classNode) {
|
||||
boolean annotated = AstUtils.hasAtLeastOneAnnotation(classNode, "EnableBinding");
|
||||
return annotated && isTransport(classNode, "redis");
|
||||
}
|
||||
|
||||
static boolean isTransport(ClassNode node, String type) {
|
||||
for (AnnotationNode annotationNode : node.getAnnotations()) {
|
||||
String annotation = "EnableBinding";
|
||||
if (PatternMatchUtils.simpleMatch(annotation,
|
||||
annotationNode.getClassNode().getName())) {
|
||||
Expression expression = annotationNode.getMembers().get("transport");
|
||||
String transport = expression == null ? "redis" : expression.getText();
|
||||
if (transport != null) {
|
||||
transport = SystemPropertyUtils.resolvePlaceholders(transport);
|
||||
}
|
||||
return transport.equals(type);
|
||||
}
|
||||
}
|
||||
return false;
|
||||
protected String getTransport() {
|
||||
return "redis";
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -61,12 +36,4 @@ public class StreamRedisCompilerAutoConfiguration extends CompilerAutoConfigurat
|
||||
"org.springframework.cloud.stream.binder.redis.config.RedisServiceAutoConfiguration")
|
||||
.add("spring-cloud-starter-stream-redis");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void applyImports(ImportCustomizer imports) throws CompilationFailedException {
|
||||
imports.addImports("org.springframework.boot.groovy.cloud.EnableBinding");
|
||||
imports.addStarImports("org.springframework.cloud.stream.annotation",
|
||||
"org.springframework.cloud.stream.messaging");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user