Skip to content

Commit

Permalink
Improve dev mode #314
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli committed Oct 23, 2019
1 parent 5ad2524 commit b5f967f
Show file tree
Hide file tree
Showing 8 changed files with 261 additions and 5 deletions.
1 change: 1 addition & 0 deletions examples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
<modules>
<module>observability</module>
<module>timer-log</module>
<module>timer-log-xml</module>
<module>rest-json</module>
</modules>

Expand Down
28 changes: 28 additions & 0 deletions examples/timer-log-xml/README.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
= timer-log-xml

This is a basic hello world example that use XML to set-up
a Camel timer that triggers every second and prints to the
log.

To run it:

[source,text]
----
$ mvn clean compile quarkus:dev -DnoDeps -Dcamel.main.xml-routes=file:$PWD/src/main/resources/routes/my-routes.xml
----
This compiles the project and starts the Quarkus tooling in the https://quarkus.io/guides/maven-tooling#development-mode[develpment mode].
Then look at the log output in the console. As we run the example
in Quarkus Dev Mode, you can edit the source code and have live updates.
For example try to change the logging output to be `Bye XML`.

== Native build

To build as native:

[source,text]
----
$ mvn package -Pnative
----

This requires having GraalVM and other tools installed.
See the https://quarkus.io/guides/building-native-image-guide[Quarkus Native Guide] for details.
108 changes: 108 additions & 0 deletions examples/timer-log-xml/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-bom</artifactId>
<version>0.2.1-SNAPSHOT</version>
<relativePath>../../poms/bom/pom.xml</relativePath>
</parent>

<modelVersion>4.0.0</modelVersion>

<artifactId>camel-quarkus-examples-timer-log</artifactId>
<name>Camel Quarkus :: Examples :: Timer Log XML</name>
<description>Camel Quarkus Example :: Timer to Log XML</description>

<properties>
<!-- to use docker build instead of native
<native-image.docker-build>true</native-image.docker-build>
<native-image.container-runtime>docker</native-image.container-runtime>
-->
</properties>

<dependencies>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-timer</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-log</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel.quarkus</groupId>
<artifactId>camel-quarkus-core-xml</artifactId>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<executions>
<execution>
<id>build</id>
<goals>
<goal>build</goal>
</goals>
</execution>
</executions>
<configuration>
<workingDir>${project.basedir}</workingDir>
</configuration>
</plugin>
</plugins>
</build>

<profiles>
<profile>
<id>native</id>
<activation>
<property>
<name>native</name>
</property>
</activation>
<build>
<plugins>
<plugin>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-maven-plugin</artifactId>
<executions>
<execution>
<id>native-image</id>
<goals>
<goal>native-image</goal>
</goals>
<configuration>
<enableServer>false</enableServer>
<cleanupServer>true</cleanupServer>
<disableReports>true</disableReports>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</profile>
</profiles>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
/**
* 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
* <p>
* http://www.apache.org/licenses/LICENSE-2.0
* <p>
* 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.acme.timer;

// Added to avoid quarkus-maven-plugin warning about empty source tree
28 changes: 28 additions & 0 deletions examples/timer-log-xml/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
## ---------------------------------------------------------------------------
## 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
#
quarkus.log.file.enable = false
quarkus.ssl.native=true

quarkus.log.category."org.apache.camel.main".level = DEBUG

#
# Camel
#
camel.context.name = quarkus-camel-example-timer-log-xml
27 changes: 27 additions & 0 deletions examples/timer-log-xml/src/main/resources/routes/my-routes.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
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.
-->
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns="http://camel.apache.org/schema/spring"
xsi:schemaLocation="
http://camel.apache.org/schema/spring
http://camel.apache.org/schema/spring/camel-spring.xsd">

<route id="xml-route">
<from uri="timer:from-xml?period=1s"/>
<log message="Hello XML!"/>
</route>

</routes>
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,10 @@ CamelRegistryBuildItem registry(
// to the camel context directly by extension so it does not make sense to
// instantiate them in this phase.
//
boolean blacklisted = si.path.endsWith("reactive-executor") || si.path.endsWith("platform-http");
boolean blacklisted = si.path.endsWith("reactive-executor")
|| si.path.endsWith("platform-http")
|| si.path.endsWith("properties-component-factory");

if (blacklisted) {
LOGGER.debug("Ignore service: {}", si);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,16 +16,58 @@
*/
package org.apache.camel.quarkus.core.deployment;

import java.util.Collections;
import java.util.List;
import java.util.stream.Collectors;
import java.util.stream.Stream;

import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.builditem.HotDeploymentWatchedFileBuildItem;
import org.apache.camel.quarkus.core.CamelConfig;
import org.eclipse.microprofile.config.ConfigProvider;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/*
* camel-main does not yet support filtering with pattern/glob so
* each entry of camel.main.xml-[routes|rests] is be a path thus
* can be safely added to the list of files to watch to trigger
* hot deployment.
*
* See https://issues.apache.org/jira/browse/CAMEL-14100
*/
class HotDeploymentProcessor {
private static final Logger LOGGER = LoggerFactory.getLogger(HotDeploymentProcessor.class);
private static final String[] EMPTY_STRING_ARRAY = new String[0];
private static final String FILE_PREFIX = "file:";

@BuildStep
List<HotDeploymentWatchedFileBuildItem> xmlRoutes() {
return locations("camel.main.xml-routes");
}

@BuildStep
List<HotDeploymentWatchedFileBuildItem> configFile(CamelConfig.Runtime config) {
return Collections.emptyList();
List<HotDeploymentWatchedFileBuildItem> xmlRests() {
return locations("camel.main.xml-rests");
}

private static List<HotDeploymentWatchedFileBuildItem> locations(String property) {
String[] locations = ConfigProvider.getConfig()
.getOptionalValue(property, String[].class)
.orElse(EMPTY_STRING_ARRAY);

List<HotDeploymentWatchedFileBuildItem> items = Stream.of(locations)
.filter(location -> location.startsWith(FILE_PREFIX))
.map(location -> location.substring(FILE_PREFIX.length()))
.distinct()
.map(HotDeploymentWatchedFileBuildItem::new)
.collect(Collectors.toList());

if (!items.isEmpty()) {
LOGGER.info("HotDeployment files ({}):", property);
for (HotDeploymentWatchedFileBuildItem item : items) {
LOGGER.info("- {}", item.getLocation());
}
}

return items;
}
}

0 comments on commit b5f967f

Please sign in to comment.