Skip to content

Commit 00c23c2

Browse files
committed
Merge branch 'master' into reloading-features
# Conflicts: # src/main/docs/guide/reloading/jrebel.adoc # src/main/docs/guide/reloading/springloaded.adoc # src/main/docs/guide/toc.yml
2 parents ac43931 + a019d50 commit 00c23c2

File tree

238 files changed

+10906
-529
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

238 files changed

+10906
-529
lines changed

aop/src/main/java/io/micronaut/aop/MethodInvocationContext.java

+9
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@
1818

1919
import io.micronaut.inject.ExecutableMethod;
2020

21+
import javax.annotation.Nonnull;
22+
2123
/**
2224
* Extended version of {@link InvocationContext} for {@link MethodInterceptor} instances.
2325
*
@@ -28,4 +30,11 @@
2830
* @since 1.0
2931
*/
3032
public interface MethodInvocationContext<T, R> extends InvocationContext<T, R>, ExecutableMethod<T, R> {
33+
34+
/**
35+
* The underlying {@link ExecutableMethod} reference.
36+
*
37+
* @return The underlying method reference.
38+
*/
39+
@Nonnull ExecutableMethod<T, R> getExecutableMethod();
3140
}

aop/src/main/java/io/micronaut/aop/chain/MethodInterceptorChain.java

+7
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
import io.micronaut.core.type.ReturnType;
2323
import io.micronaut.inject.ExecutableMethod;
2424

25+
import javax.annotation.Nonnull;
2526
import java.lang.reflect.Method;
2627

2728
/**
@@ -79,4 +80,10 @@ public Class<T> getDeclaringType() {
7980
public String toString() {
8081
return executionHandle.toString();
8182
}
83+
84+
@Nonnull
85+
@Override
86+
public ExecutableMethod<T, R> getExecutableMethod() {
87+
return executionHandle;
88+
}
8289
}

bom/build.gradle

+6-4
Original file line numberDiff line numberDiff line change
@@ -59,10 +59,12 @@ publishing {
5959

6060
def versionExpr = "\${${dep.key}.version}"
6161

62-
mkp.dependency {
63-
mkp.groupId info.group
64-
mkp.artifactId info.name
65-
mkp.version versionExpr
62+
if (info.name) {
63+
mkp.dependency {
64+
mkp.groupId info.group
65+
mkp.artifactId info.name
66+
mkp.version versionExpr
67+
}
6668
}
6769
if(info.modules) {
6870
for(m in info.modules) {

build.gradle

+10
Original file line numberDiff line numberDiff line change
@@ -94,6 +94,16 @@ ext {
9494
group : 'io.micrometer',
9595
name : 'micrometer-registry-statsd'
9696
],
97+
'mongo' : [
98+
version: mongoVersion,
99+
group: 'org.mongodb',
100+
modules: ['mongodb-driver-async', 'mongo-java-driver']
101+
],
102+
'mongo.reactive': [
103+
version: '1.8.0',
104+
group: 'org.mongodb',
105+
name: 'mongodb-driver-reactivestreams'
106+
],
97107
neo4j: [
98108
version: neo4jVersion,
99109
group:'org.neo4j.test',

configurations/kafka/build.gradle

+32
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
dependencies {
2+
compile project(":messaging")
3+
compile 'org.apache.kafka:kafka-clients:1.1.0'
4+
5+
compileOnly project(":management")
6+
compileOnly 'org.apache.kafka:kafka_2.12:1.1.0'
7+
compileOnly 'org.apache.kafka:kafka-clients:1.1.0:test'
8+
compileOnly 'org.apache.kafka:kafka_2.12:1.1.0:test'
9+
10+
compileOnly project(":inject-java")
11+
12+
testCompile dependencyVersion("reactor")
13+
testCompile project(":management")
14+
testCompile project(":inject-groovy")
15+
testCompile project(":inject-java")
16+
testCompile 'org.apache.kafka:kafka-clients:1.1.0:test'
17+
testCompile 'org.apache.kafka:kafka_2.12:1.1.0'
18+
testCompile 'org.apache.kafka:kafka_2.12:1.1.0:test'
19+
}
20+
//tasks.withType(Test) {
21+
// testLogging {
22+
// showStandardStreams = true
23+
// }
24+
// beforeTest {
25+
// System.out.println("STARTING: ${it.className}.$it.name")
26+
// System.out.flush()
27+
// }
28+
// afterTest {
29+
// System.out.println("FINISHED: ${it.className}.$it.name")
30+
// System.out.flush()
31+
// }
32+
//}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2017-2018 original authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.micronaut.configuration.kafka;
18+
19+
20+
/**
21+
* Defines an interface that can be injected into {@link io.micronaut.configuration.kafka.annotation.KafkaListener} beans so that offsets can be manually committed.
22+
*
23+
* @author graemerocher
24+
* @since 1.0
25+
*/
26+
public interface Acknowledgement {
27+
/**
28+
* Acknowledge the last {@link org.apache.kafka.clients.consumer.ConsumerRecord} synchronously.
29+
*/
30+
void ack();
31+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
/*
2+
* Copyright 2017-2018 original authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.micronaut.configuration.kafka;
18+
19+
import org.apache.kafka.clients.consumer.KafkaConsumer;
20+
21+
import javax.annotation.Nonnull;
22+
23+
/**
24+
* Interface for {@link io.micronaut.configuration.kafka.annotation.KafkaListener} instances to implement
25+
* if they wish to obtain a reference to the underlying {@link org.apache.kafka.clients.consumer.KafkaConsumer}.
26+
*
27+
* @param <K> The key type
28+
* @param <V> The value type
29+
* @author Graeme Rocher
30+
* @since 1.0
31+
*/
32+
public interface KafkaConsumerAware<K, V> {
33+
34+
/**
35+
* Called when the underlying {@link KafkaConsumer} is created.
36+
*
37+
* @param consumer The consumer
38+
*/
39+
void setKafkaConsumer(@Nonnull KafkaConsumer<K, V> consumer);
40+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/*
2+
* Copyright 2017-2018 original authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.micronaut.configuration.kafka;
18+
19+
import io.micronaut.configuration.kafka.config.AbstractKafkaConsumerConfiguration;
20+
import io.micronaut.context.annotation.Factory;
21+
import io.micronaut.context.annotation.Parameter;
22+
import io.micronaut.context.annotation.Prototype;
23+
import io.micronaut.context.exceptions.ConfigurationException;
24+
import org.apache.kafka.clients.consumer.KafkaConsumer;
25+
import org.apache.kafka.common.serialization.Deserializer;
26+
27+
import java.util.Optional;
28+
import java.util.Properties;
29+
30+
/**
31+
* A factory class for creating Kafka {@link org.apache.kafka.clients.consumer.Consumer} instances.
32+
*
33+
* @author Graeme Rocher
34+
* @since 1.0
35+
*/
36+
@Factory
37+
public class KafkaConsumerFactory {
38+
39+
/**
40+
* Creates a new {@link KafkaConsumer} for the given configuration.
41+
*
42+
* @param consumerConfiguration The consumer configuration
43+
* @param <K> The key type
44+
* @param <V> The value type
45+
* @return The consumer
46+
*/
47+
@Prototype
48+
public <K, V> KafkaConsumer<K, V> createConsumer(
49+
@Parameter AbstractKafkaConsumerConfiguration<K, V> consumerConfiguration) {
50+
51+
Optional<Deserializer<K>> keyDeserializer = consumerConfiguration.getKeyDeserializer();
52+
Optional<Deserializer<V>> valueDeserializer = consumerConfiguration.getValueDeserializer();
53+
Properties config = consumerConfiguration.getConfig();
54+
55+
if (keyDeserializer.isPresent() && valueDeserializer.isPresent()) {
56+
return new KafkaConsumer<>(
57+
config,
58+
keyDeserializer.get(),
59+
valueDeserializer.get()
60+
);
61+
} else if (keyDeserializer.isPresent() || valueDeserializer.isPresent()) {
62+
throw new ConfigurationException("Both the [keyDeserializer] and [valueDeserializer] must be set when setting either");
63+
} else {
64+
return new KafkaConsumer<>(
65+
config
66+
);
67+
}
68+
69+
}
70+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
/*
2+
* Copyright 2017-2018 original authors
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package io.micronaut.configuration.kafka;
18+
19+
import io.micronaut.core.convert.ArgumentConversionContext;
20+
import io.micronaut.core.convert.ConversionService;
21+
import io.micronaut.messaging.MessageHeaders;
22+
23+
import java.util.*;
24+
import java.util.stream.Collectors;
25+
26+
import org.apache.kafka.common.header.Header;
27+
import org.apache.kafka.common.header.Headers;
28+
29+
/**
30+
* A {@link MessageHeaders} implementation for Kafka.
31+
*
32+
* @author Graeme Rocher
33+
* @since 1.0
34+
*/
35+
public class KafkaHeaders implements MessageHeaders {
36+
37+
private final Headers headers;
38+
39+
/**
40+
* Constructs a new instance for the given headers.
41+
*
42+
* @param headers The kafka headers
43+
*/
44+
public KafkaHeaders(Headers headers) {
45+
Objects.requireNonNull(headers, "Argument [headers] cannot be null");
46+
this.headers = headers;
47+
}
48+
49+
@Override
50+
public List<String> getAll(CharSequence name) {
51+
return null;
52+
}
53+
54+
@Override
55+
public String get(CharSequence name) {
56+
Header header = headers.lastHeader(name.toString());
57+
if (header != null) {
58+
return new String(header.value());
59+
}
60+
return null;
61+
}
62+
63+
@Override
64+
public Set<String> names() {
65+
return Arrays.stream(headers.toArray()).map(Header::key).collect(Collectors.toSet());
66+
}
67+
68+
@Override
69+
public Collection<List<String>> values() {
70+
return names().stream().map(name -> {
71+
Iterable<Header> headers = KafkaHeaders.this.headers.headers(name);
72+
List<String> values = new ArrayList<>();
73+
for (Header header : headers) {
74+
values.add(new String(header.value()));
75+
}
76+
return values;
77+
}).collect(Collectors.toList());
78+
}
79+
80+
@Override
81+
public <T> Optional<T> get(CharSequence name, ArgumentConversionContext<T> conversionContext) {
82+
String v = get(name);
83+
if (v != null) {
84+
return ConversionService.SHARED.convert(v, conversionContext);
85+
}
86+
return Optional.empty();
87+
}
88+
}

0 commit comments

Comments
 (0)