Skip to content

Commit

Permalink
Graceful shutdown strategy used as default one
Browse files Browse the repository at this point in the history
  • Loading branch information
JiriOndrusek authored and jamesnetherton committed Nov 22, 2021
1 parent 86f7cc8 commit 79b7a7a
Show file tree
Hide file tree
Showing 9 changed files with 200 additions and 1 deletion.
19 changes: 19 additions & 0 deletions docs/modules/ROOT/pages/migration-guide/2.6.0.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
= Camel Quarkus 2.6.0 Migration Guide

The following guide outlines how to adapt your code to changes that were made in Camel Quarkus 2.6.0 & Quarkus 2.6.0.Final.

== Graceful shutdown strategy is used by default

In previous releases, graceful shutdown strategy (default strategy in Camel, see https://camel.apache.org/manual/graceful-shutdown.html[documentation] ) wasn't used by default.
Shutdown wasn't controlled by any strategy.

This is no longer the case.
Graceful shutdown strategy is enabled by default (see https://camel.apache.org/manual/graceful-shutdown.html[documentation]) with one exception only.
If timeout for graceful shutdown is not set and application runs in a development mode, no shutdown strategy is used (behavior for the development mode without timeout for graceful timeout wasn't changed).

`DefaultShutdownStrategy` could be configured via `application.properties`.
For example:
```
#set graceful timeout to 15 seconds
camel.main.shutdownTimeout = 15
```
1 change: 1 addition & 0 deletions docs/modules/ROOT/pages/migration-guide/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ We do frequent releases, a release almost every month, and even though we strive

Listed here are guides on how to migrate between major versions and anything of significance to watch for when upgrading from minor versions.

* xref:migration-guide/2.6.0.adoc[Camel Quarkus 2.5.0 to Camel Quarkus 2.6.0 migration guide]
* xref:migration-guide/2.2.0.adoc[Camel Quarkus 2.1.0 to Camel Quarkus 2.2.0 migration guide]
* xref:migration-guide/2.1.0.adoc[Camel Quarkus 2.0.0 to Camel Quarkus 2.1.0 migration guide]
* xref:migration-guide/2.0.0.adoc[Camel Quarkus 1.x to Camel Quarkus 2.0.0 migration guide]
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,8 @@
import io.quarkus.arc.deployment.BeanContainerBuildItem;
import io.quarkus.arc.deployment.BeanDiscoveryFinishedBuildItem;
import io.quarkus.arc.deployment.SyntheticBeansRuntimeInitBuildItem;
import io.quarkus.deployment.IsDevelopment;
import io.quarkus.deployment.annotations.BuildProducer;
import io.quarkus.deployment.annotations.BuildStep;
import io.quarkus.deployment.annotations.Consume;
import io.quarkus.deployment.annotations.ExecutionTime;
Expand Down Expand Up @@ -102,6 +104,24 @@ CamelContextBuildItem context(
return new CamelContextBuildItem(context);
}

/**
* This step customizes camel context for development mode.
*
* @param recorder the recorder
* @param producer producer of context customizer build item
*/
@Record(ExecutionTime.STATIC_INIT)
@BuildStep(onlyIf = IsDevelopment.class)
public void devModeCamelContextCustomizations(
CamelContextRecorder recorder,
BuildProducer<CamelContextCustomizerBuildItem> producer) {
String val = CamelSupport.getOptionalConfigValue("camel.main.shutdownTimeout", String.class, null);
if (val == null) {
//if no graceful timeout is set in development mode, graceful shutdown is replaced with no shutdown
producer.produce(new CamelContextCustomizerBuildItem(recorder.createNoShutdownStrategyCustomizer()));
}
}

/**
* This build steps assembles the default implementation of a {@link CamelRuntime} responsible to bootstrap
* Camel.
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
/*
* 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.core.deployment;

import javax.inject.Inject;

import io.quarkus.test.QuarkusUnitTest;
import org.apache.camel.CamelContext;
import org.apache.camel.impl.engine.DefaultShutdownStrategy;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import static org.assertj.core.api.Assertions.assertThat;

public class CamelContextDefaultStrategyTest {
@RegisterExtension
static final QuarkusUnitTest CONFIG = new QuarkusUnitTest();

@Inject
CamelContext camelContext;

@Test
public void testRestConfiguration() {
assertThat(camelContext.getShutdownStrategy() instanceof DefaultShutdownStrategy);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,10 @@ public RuntimeValue<CamelRuntime> createRuntime(BeanContainer beanContainer, Run
return new RuntimeValue<>(runtime);
}

public RuntimeValue<CamelContextCustomizer> createNoShutdownStrategyCustomizer() {
return new RuntimeValue((CamelContextCustomizer) context -> context.setShutdownStrategy(new NoShutdownStrategy()));
}

public void addRoutes(RuntimeValue<CamelContext> context, String typeName) {
try {
addRoutes(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import org.apache.camel.impl.engine.DefaultComponentResolver;
import org.apache.camel.impl.engine.DefaultDataFormatResolver;
import org.apache.camel.impl.engine.DefaultLanguageResolver;
import org.apache.camel.impl.engine.DefaultShutdownStrategy;
import org.apache.camel.model.ModelCamelContext;
import org.apache.camel.spi.CamelBeanPostProcessor;
import org.apache.camel.spi.ClassResolver;
Expand Down Expand Up @@ -89,7 +90,7 @@ protected ManagementNameStrategy createManagementNameStrategy() {

@Override
protected ShutdownStrategy createShutdownStrategy() {
return new NoShutdownStrategy();
return new DefaultShutdownStrategy();
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
/*
* 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.main;

import java.io.IOException;
import java.io.StringWriter;
import java.io.Writer;
import java.util.Properties;

import io.quarkus.test.QuarkusDevModeTest;
import io.restassured.RestAssured;
import org.apache.camel.impl.engine.DefaultShutdownStrategy;
import org.hamcrest.Matchers;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.Asset;
import org.jboss.shrinkwrap.api.asset.StringAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.RegisterExtension;

import static org.assertj.core.api.Assertions.assertThat;

public class CamelContextDefaultShutdownStrategyDevModeTest {
@RegisterExtension
static final QuarkusDevModeTest TEST = new QuarkusDevModeTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
.addAsResource(applicationProperties(), "application.properties")
.addClass(CamelSupportResource.class));

public static Asset applicationProperties() {
Writer writer = new StringWriter();

Properties props = new Properties();
props.setProperty("camel.main.shutdownTimeout", "15");

try {
props.store(writer, "");
} catch (IOException e) {
throw new RuntimeException(e);
}

return new StringAsset(writer.toString());
}

@Test
public void test() throws IOException {
RestAssured.when().get("/test/getShutdownStrategy").then().assertThat()
.body(Matchers.is(DefaultShutdownStrategy.class.getSimpleName()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* 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.main;

import java.io.IOException;

import io.quarkus.test.QuarkusDevModeTest;
import io.restassured.RestAssured;
import org.apache.camel.quarkus.core.NoShutdownStrategy;
import org.hamcrest.Matchers;
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.assertj.core.api.Assertions.assertThat;

public class CamelContextNoShutdownStrategyDevModeTest {
@RegisterExtension
static final QuarkusDevModeTest TEST = new QuarkusDevModeTest()
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class)
.addClass(CamelSupportResource.class));

@Test
public void test() throws IOException {
RestAssured.when().get("/test/getShutdownStrategy").then().assertThat()
.body(Matchers.is(NoShutdownStrategy.class.getSimpleName()));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -45,4 +45,11 @@ public JsonObject describeMain() {
.add("routes", routes)
.build();
}

@Path("/getShutdownStrategy")
@GET
@Produces(MediaType.TEXT_PLAIN)
public String getShutdownStrategy() {
return context.getShutdownStrategy().getClass().getSimpleName();
}
}

0 comments on commit 79b7a7a

Please sign in to comment.