This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch init-bean in repository https://gitbox.apache.org/repos/asf/camel.git
commit c0cc5d2a45f26726da26d88bdb6122593f2294f0 Author: Claus Ibsen <[email protected]> AuthorDate: Wed Sep 27 09:28:23 2023 +0200 CAMEL-19808: camel-core-model - Add init and destroy method to <bean> --- .../apache/camel/catalog/schemas/camel-spring.xsd | 2 + .../src/main/docs/java-xml-io-dsl.adoc | 38 +++++++ .../camel-yaml-dsl/src/main/docs/yaml-dsl.adoc | 111 ++++++++------------- 3 files changed, 80 insertions(+), 71 deletions(-) diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd index 66af7a0e9f2..602d7c3ba08 100644 --- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd +++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd @@ -13603,6 +13603,8 @@ org.apache.camel.builder.RouteBuilder. </xs:sequence> <xs:attribute name="name" type="xs:string" use="required"/> <xs:attribute name="type" type="xs:string" use="required"/> + <xs:attribute name="initMethod" type="xs:string"/> + <xs:attribute name="destroyMethod" type="xs:string"/> <xs:attribute name="factoryMethod" type="xs:string"/> <xs:attribute name="factoryBean" type="xs:string"/> </xs:complexType> diff --git a/dsl/camel-xml-io-dsl/src/main/docs/java-xml-io-dsl.adoc b/dsl/camel-xml-io-dsl/src/main/docs/java-xml-io-dsl.adoc index f96371e8a0f..b985c67c4df 100644 --- a/dsl/camel-xml-io-dsl/src/main/docs/java-xml-io-dsl.adoc +++ b/dsl/camel-xml-io-dsl/src/main/docs/java-xml-io-dsl.adoc @@ -222,6 +222,44 @@ public class MyHelper { NOTE: The factory method must be `public static`. +=== Using init and destroy methods on beans + +Sometimes beans need to do some initialization and cleanup work before a bean is ready to be used. +For this you can use `initMethod` and `destroyMethod` that Camel triggers accordingly. + +Those methods must be public void and have no arguments, as shown below: + +[source,java] +---- +public class MyBean { + + public void initMe() { + // do init work here + } + + public void destroyMe() { + // do cleanup work here + } + +} +---- + +You then have to declare those methods in XML DSL as follows: + +[source,xml] +---- + <bean name="myBean" type="com.acme.MyBean" + initMethod="initMe" destroyMethod="destroyMe"> + <constructors> + <constructor index="0" value="true"/> + <constructor index="1" value="Hello World"/> + </constructors> + </bean> +---- + +The init and destroy methods are optional, so a bean does not have to have both, +for example you may only have destroy methods. + == See Also diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/docs/yaml-dsl.adoc b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/docs/yaml-dsl.adoc index 71fd6f385e6..f52b67e8016 100644 --- a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/docs/yaml-dsl.adoc +++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/main/docs/yaml-dsl.adoc @@ -267,6 +267,45 @@ public class MyHelper { NOTE: The factory method must be `public static`. +=== Using init and destroy methods on beans + +Sometimes beans need to do some initialization and cleanup work before a bean is ready to be used. +For this you can use `initMethod` and `destroyMethod` that Camel triggers accordingly. + +Those methods must be public void and have no arguments, as shown below: + +[source,java] +---- +public class MyBean { + + public void initMe() { + // do init work here + } + + public void destroyMe() { + // do cleanup work here + } + +} +---- + +You then have to declare those methods in YAML DSL as follows: + +[source,yaml] +---- +- beans: + - name: myBean + type: com.acme.MyBean + initMethod: initMe + destroyMethod: destroyMe + constructors: + 0: true + 1: "Hello World" +---- + +The init and destroy methods are optional, so a bean does not have to have both, +for example you may only have destroy methods. + == Configuring options on languages Some xref:components:languages:index.adoc[Languages] have additional configurations @@ -325,74 +364,4 @@ which demonstrate creating Camel Routes with YAML. Another way to find examples of YAML DSL is to look in https://github.com/apache/camel-kamelets[Camel Kamelets] where each Kamelet is defined using YAML. -== Supported EIPs - -The following set of high level EIPs are supported in the yaml DSL language. For full details on their expected configuration, please refer to the https://github.com/apache/camel/blob/main/dsl/camel-yaml-dsl/camel-yaml-dsl/src/generated/resources/schema/camelYamlDsl.json[Camel YAML DSL specification]. - -- Aggregate -- Bean -- Do Catch -- Do Try -- Do Finally -- Choice -- Circuit Breaker -- Claim Check -- Convert Body To -- Delay -- Dynamic Router -- Enrich -- Error Handler -- Filter -- From -- Idempotent Consumer -- Intercept -- Intercept From -- Intercept Send To Endpoint -- Load Balance -- Log -- Loop -- Marshal -- Multicast -- On Completion -- On Exception -- On Fallback -- Otherwise -- Pausable -- Pipeline -- Policy -- Poll Enrich -- Process -- Recipient List -- Remove Header -- Remove Headers -- Remove Property -- Remove Properties -- Resequence -- Resumable -- REST DSL -- Rollback -- Routing Slip -- Saga -- Sample -- Script -- Service Call -- Set Body -- Set Exchange Pattern -- Set Header -- Set Property -- Sort -- Split -- Step -- Stop -- Threads -- Throttle -- Throw Exception -- To -- To Dynamic -- Transacted -- Transform -- Unmarshal -- Validate -- When -- When Skip Send To Endpoint -- Wire Tap +
