forked from apache/camel-quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Improve Kafka integration with Quarkus dev services
Fixes apache#3121
- Loading branch information
1 parent
15f6215
commit f7d9d4e
Showing
7 changed files
with
219 additions
and
0 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
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
49 changes: 49 additions & 0 deletions
49
...ava/org/apache/camel/quarkus/component/kafka/deployment/KafkaDevServicesDisabledTest.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,49 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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.apache.camel.quarkus.component.kafka.deployment; | ||
|
||
import javax.inject.Inject; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import org.apache.camel.CamelContext; | ||
import org.apache.camel.component.kafka.KafkaComponent; | ||
import org.apache.camel.component.kafka.KafkaConfiguration; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import static org.junit.jupiter.api.Assertions.*; | ||
|
||
public class KafkaDevServicesDisabledTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest CONFIG = new QuarkusUnitTest() | ||
.withConfigurationResource("application-configuration-devservices-disabled.properties") | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)); | ||
|
||
@Inject | ||
CamelContext context; | ||
|
||
@Test | ||
public void camelKafkaComponentBrokersConfigurationNull() { | ||
KafkaComponent component = context.getComponent("kafka", KafkaComponent.class); | ||
KafkaConfiguration configuration = component.getConfiguration(); | ||
assertNotNull(configuration); | ||
assertNull(configuration.getBrokers()); | ||
} | ||
} |
66 changes: 66 additions & 0 deletions
66
...java/org/apache/camel/quarkus/component/kafka/deployment/KafkaDevServicesEnabledTest.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,66 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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.apache.camel.quarkus.component.kafka.deployment; | ||
|
||
import javax.inject.Inject; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
import org.apache.camel.CamelContext; | ||
import org.apache.camel.ConsumerTemplate; | ||
import org.apache.camel.ProducerTemplate; | ||
import org.apache.camel.component.kafka.KafkaComponent; | ||
import org.apache.camel.component.kafka.KafkaConfiguration; | ||
import org.eclipse.microprofile.config.inject.ConfigProperty; | ||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
|
||
public class KafkaDevServicesEnabledTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest CONFIG = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)); | ||
|
||
@Inject | ||
CamelContext context; | ||
|
||
@Inject | ||
ProducerTemplate producerTemplate; | ||
|
||
@Inject | ||
ConsumerTemplate consumerTemplate; | ||
|
||
@ConfigProperty(name = "kafka.bootstrap.servers") | ||
String bootstrapServers; | ||
|
||
@Test | ||
public void camelKafkaComponentBrokersConfigurationIsDevServicesBroker() { | ||
KafkaComponent component = context.getComponent("kafka", KafkaComponent.class); | ||
KafkaConfiguration configuration = component.getConfiguration(); | ||
assertNotNull(configuration); | ||
assertEquals(bootstrapServers, configuration.getBrokers()); | ||
|
||
String payload = "Hello World"; | ||
producerTemplate.sendBody("kafka:test?autoOffsetReset=earliest", payload); | ||
String result = consumerTemplate.receiveBody("kafka:test?autoOffsetReset=earliest", 5000, String.class); | ||
assertEquals(payload, result); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
...a/deployment/src/test/resources/application-configuration-devservices-disabled.properties
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,17 @@ | ||
## --------------------------------------------------------------------------- | ||
## Licensed to the Apache Software Foundation (ASF) under one or more | ||
## contributor license agreements. See the NOTICE file distributed with | ||
## this work for additional information regarding copyright ownership. | ||
## The ASF licenses this file to You 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. | ||
## --------------------------------------------------------------------------- | ||
quarkus.kafka.devservices.enabled=false |
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,9 @@ | ||
=== Quarkus Kafka Dev Services | ||
|
||
Camel Quarkus Kafka can take advantage of https://quarkus.io/guides/kafka-dev-services[Quarkus Kafka Dev services] to simplify development and testing with a local containerized Kafka broker. | ||
|
||
Kafka Dev Services is enabled by default in dev & test mode. | ||
The Camel Kafka component is automatically configured so that the `brokers` component option is set to point at the local containerized Kafka broker. | ||
Meaning that there's no need to configure this option yourself. | ||
|
||
This functionality can be disabled with the configuration property `quarkus.kafka.devservices.enabled=false`. |
36 changes: 36 additions & 0 deletions
36
...ka/runtime/src/main/java/org/apache/camel/quarkus/component/kafka/CamelKafkaRecorder.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,36 @@ | ||
/* | ||
* Licensed to the Apache Software Foundation (ASF) under one or more | ||
* contributor license agreements. See the NOTICE file distributed with | ||
* this work for additional information regarding copyright ownership. | ||
* The ASF licenses this file to You 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.apache.camel.quarkus.component.kafka; | ||
|
||
import io.quarkus.runtime.RuntimeValue; | ||
import io.quarkus.runtime.annotations.Recorder; | ||
import org.apache.camel.component.kafka.KafkaComponent; | ||
import org.apache.camel.component.kafka.KafkaConfiguration; | ||
|
||
@Recorder | ||
public class CamelKafkaRecorder { | ||
|
||
public RuntimeValue<KafkaComponent> createKafkaComponentForDevServices(String brokers) { | ||
KafkaConfiguration configuration = new KafkaConfiguration(); | ||
configuration.setBrokers(brokers); | ||
|
||
KafkaComponent component = new KafkaComponent(); | ||
component.setConfiguration(configuration); | ||
|
||
return new RuntimeValue<>(component); | ||
} | ||
} |