You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2022/02/21 20:37:02 UTC

[camel-examples] branch main updated: Fix and simplify the example spring-pulsar (#79)

This is an automated email from the ASF dual-hosted git repository.

davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel-examples.git


The following commit(s) were added to refs/heads/main by this push:
     new 81831ab  Fix and simplify the example spring-pulsar (#79)
81831ab is described below

commit 81831abd691db5e945bb3a90314ed6be1d47be3f
Author: Nicolas Filotto <es...@users.noreply.github.com>
AuthorDate: Mon Feb 21 21:36:56 2022 +0100

    Fix and simplify the example spring-pulsar (#79)
---
 examples/spring-pulsar/README.adoc                 | 17 ++--
 examples/spring-pulsar/pom.xml                     | 28 +++----
 .../camel/example/pulsar/client/CamelClient.java   | 23 +++---
 .../example/pulsar/client/CamelClientEndpoint.java | 80 -------------------
 .../TypeConverters.java => common/Beans.java}      | 22 ++++--
 .../pulsar/{server => common}/TypeConverters.java  | 11 ++-
 .../resources/META-INF/spring/camel-server.xml     | 41 +---------
 .../src/main/resources/camel-client.xml            | 38 +--------
 .../{camel-client.xml => camel-common.xml}         | 31 ++------
 .../src/main/resources/camel.properties            | 18 -----
 .../camel/example/SpringJmsClientServerTest.java   | 91 ----------------------
 .../org/apache/camel/example/SpringPulsarTest.java | 72 +++++++++++++++++
 12 files changed, 140 insertions(+), 332 deletions(-)

diff --git a/examples/spring-pulsar/README.adoc b/examples/spring-pulsar/README.adoc
index ef38dd5..27cb4e3 100644
--- a/examples/spring-pulsar/README.adoc
+++ b/examples/spring-pulsar/README.adoc
@@ -10,20 +10,18 @@ received message.
 You can run the Pulsar cluster through docker:
 
 ----
-$ docker run -it \
+$ docker run --rm -it \
   -p 6650:6650 \
   -p 8080:8080 \
-  -v $PWD/data:/pulsar/data \
-  apachepulsar/pulsar:latest \
+  -v $PWD/target/data:/pulsar/data \
+  apachepulsar/pulsar \
   bin/pulsar standalone
 ----
 
-The Server is required to be running when you try the clients.
+The Server is required to be running when you try the client.
 
-And for the Client we have a total of three flavors: NB only 1st one
-working at the moment - Normal use the ProducerTemplate ala Spring
-Template style - Using Spring Remoting for powerful "Client doesn’t
-know at all it's a remote call" - And using the Message Endpoint pattern using the neutral Camel API
+And for the Client we use the ProducerTemplate ala Spring
+Template style.
 
 === Build
 
@@ -48,9 +46,6 @@ $ mvn exec:java -PCamelServer
 ----
 $ mvn exec:java -PCamelClient
 ----
-//Below don't work yet
-//mvn exec:java -PCamelClientRemoting
-//mvn exec:java -PCamelClientEndpoint
 
 To stop the example hit ctrl+c
 
diff --git a/examples/spring-pulsar/pom.xml b/examples/spring-pulsar/pom.xml
index 6835fcf..768a71f 100644
--- a/examples/spring-pulsar/pom.xml
+++ b/examples/spring-pulsar/pom.xml
@@ -30,7 +30,6 @@
     <description>An example using Spring XML to talk to the Pulsar server from different kind of client techniques</description>
 
     <properties>
-        <skipTests>true</skipTests>
         <category>Messaging</category>
     </properties>
 
@@ -98,7 +97,18 @@
             <artifactId>camel-test-spring-junit5</artifactId>
             <scope>test</scope>
         </dependency>
-
+        <dependency>
+            <groupId>org.testcontainers</groupId>
+            <artifactId>pulsar</artifactId>
+            <version>${testcontainers-version}</version>
+            <scope>test</scope>
+        </dependency>
+        <dependency>
+            <groupId>org.testcontainers</groupId>
+            <artifactId>junit-jupiter</artifactId>
+            <version>${testcontainers-version}</version>
+            <scope>test</scope>
+        </dependency>
     </dependencies>
 
     <profiles>
@@ -117,20 +127,6 @@
                 <target.main.class>org.apache.camel.example.pulsar.client.CamelClient</target.main.class>
             </properties>
         </profile>
-        <profile>
-            <id>CamelClientRemoting</id>
-            <properties>
-                <!-- we start using our own class to control what we do in the main -->
-                <target.main.class>org.apache.camel.example.pulsar.client.CamelClientRemoting</target.main.class>
-            </properties>
-        </profile>
-        <profile>
-            <id>CamelClientEndpoint</id>
-            <properties>
-                <!-- we start using our own class to control what we do in the main -->
-                <target.main.class>org.apache.camel.example.pulsar.client.CamelClientEndpoint</target.main.class>
-            </properties>
-        </profile>
     </profiles>
 
     <build>
diff --git a/examples/spring-pulsar/src/main/java/org/apache/camel/example/pulsar/client/CamelClient.java b/examples/spring-pulsar/src/main/java/org/apache/camel/example/pulsar/client/CamelClient.java
index 1f92a50..dc0fe1d 100644
--- a/examples/spring-pulsar/src/main/java/org/apache/camel/example/pulsar/client/CamelClient.java
+++ b/examples/spring-pulsar/src/main/java/org/apache/camel/example/pulsar/client/CamelClient.java
@@ -16,9 +16,10 @@
  */
 package org.apache.camel.example.pulsar.client;
 
+import java.util.Random;
+
 import org.apache.camel.ExchangePattern;
 import org.apache.camel.ProducerTemplate;
-import org.apache.camel.util.IOHelper;
 import org.springframework.context.support.AbstractApplicationContext;
 import org.springframework.context.support.ClassPathXmlApplicationContext;
 
@@ -29,6 +30,8 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
  */
 public final class CamelClient {
 
+    public static final String ENDPOINT_URI = "pulsar:non-persistent://tn1/ns1/cameltest?producerName=clientProd";
+
     private CamelClient() {
         // Helper class
     }
@@ -36,16 +39,16 @@ public final class CamelClient {
     public static void main(final String[] args) throws Exception {
         System.out.println("Notice this client requires that the CamelServer is already running!");
 
-        AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-client.xml");
-
-        // get the camel template for Spring template style sending of messages (= producer)
-        ProducerTemplate camelTemplate = context.getBean("camelTemplate", ProducerTemplate.class);
-
-        System.out.println("Invoking the multiply with 22");
-        camelTemplate.sendBody("pulsar:non-persistent://tn1/ns1/cameltest?producerName=clientProd", ExchangePattern.InOnly, 22);
+        try (AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-client.xml")) {
+            // get the camel template for Spring template style sending of messages (= producer)
+            ProducerTemplate camelTemplate = context.getBean("camelTemplate", ProducerTemplate.class);
 
-        // we're done so let's properly close the application context
-        IOHelper.close(context);
+            for (int i=0; i<10;i++) {
+                int input = new Random().nextInt(100);
+                System.out.printf("Invoking the multiply with %d%n", input);
+                camelTemplate.sendBody(ENDPOINT_URI, ExchangePattern.InOnly, input);
+            }
+        }
     }
 
 }
diff --git a/examples/spring-pulsar/src/main/java/org/apache/camel/example/pulsar/client/CamelClientEndpoint.java b/examples/spring-pulsar/src/main/java/org/apache/camel/example/pulsar/client/CamelClientEndpoint.java
deleted file mode 100644
index b9fadec..0000000
--- a/examples/spring-pulsar/src/main/java/org/apache/camel/example/pulsar/client/CamelClientEndpoint.java
+++ /dev/null
@@ -1,80 +0,0 @@
-/*
- * 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.example.pulsar.client;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.Endpoint;
-import org.apache.camel.Exchange;
-import org.apache.camel.ExchangePattern;
-import org.apache.camel.Producer;
-import org.apache.camel.util.IOHelper;
-import org.springframework.context.support.AbstractApplicationContext;
-import org.springframework.context.support.ClassPathXmlApplicationContext;
-
-/**
- * Client that uses the <a href="http://camel.apache.org/message-endpoint.html">Message Endpoint</a>
- * pattern to easily exchange messages with the Server.
- * <p/>
- * Notice this very same API can use for all components in Camel, so if we were using TCP communication instead
- * of Pulsar messaging we could just use <code>camel.getEndpoint("mina:tcp://someserver:port")</code>.
- * <p/>
- * Requires that the Pulsar broker is running, as well as CamelServer
- */
-public final class CamelClientEndpoint {
-
-    private CamelClientEndpoint() {
-        //Helper class
-    }
-
-    public static void main(final String[] args) throws Exception {
-        System.out.println("Notice this client requires that the CamelServer is already running!");
-
-        AbstractApplicationContext context = new ClassPathXmlApplicationContext("camel-client.xml");
-        CamelContext camel = context.getBean("camel-client", CamelContext.class);
-
-        // get the endpoint from the camel context
-        Endpoint endpoint = camel.getEndpoint("pulsar:tn1/ns1/cameltest");
-
-        // create the exchange used for the communication
-        // we use the in out pattern for a synchronized exchange where we expect a response
-        Exchange exchange = endpoint.createExchange(ExchangePattern.InOut);
-        // set the input on the in body
-        // must be correct type to match the expected type of an Integer object
-        exchange.getIn().setBody(11);
-
-        // to send the exchange we need an producer to do it for us
-        Producer producer = endpoint.createProducer();
-        // start the producer so it can operate
-        producer.start();
-
-        // let the producer process the exchange where it does all the work in this oneline of code
-        System.out.println("Invoking the multiply with 11");
-        producer.process(exchange);
-
-        // get the response from the out body and cast it to an integer
-        int response = exchange.getOut().getBody(Integer.class);
-        System.out.println("... the result is: " + response);
-
-        // stopping the JMS producer has the side effect of the "ReplyTo Queue" being properly
-        // closed, making this client not to try any further reads for the replies from the server
-        producer.stop();
-
-        // we're done so let's properly close the application context
-        IOHelper.close(context);
-    }
-
-}
diff --git a/examples/spring-pulsar/src/main/java/org/apache/camel/example/pulsar/server/TypeConverters.java b/examples/spring-pulsar/src/main/java/org/apache/camel/example/pulsar/common/Beans.java
similarity index 53%
copy from examples/spring-pulsar/src/main/java/org/apache/camel/example/pulsar/server/TypeConverters.java
copy to examples/spring-pulsar/src/main/java/org/apache/camel/example/pulsar/common/Beans.java
index 60ea682..ccb3cd1 100644
--- a/examples/spring-pulsar/src/main/java/org/apache/camel/example/pulsar/server/TypeConverters.java
+++ b/examples/spring-pulsar/src/main/java/org/apache/camel/example/pulsar/common/Beans.java
@@ -14,15 +14,23 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.example.pulsar.server;
+package org.apache.camel.example.pulsar.common;
 
-import org.apache.camel.Converter;
+import org.apache.pulsar.client.admin.PulsarAdmin;
+import org.apache.pulsar.client.api.PulsarClientException;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Bean;
+import org.springframework.context.annotation.Configuration;
 
-public class TypeConverters implements org.apache.camel.TypeConverters {
+/**
+ * The class holding all the beans required to access to Apache Pulsar that are not easy to create from
+ * a pure XML configuration.
+ */
+@Configuration
+public class Beans {
 
-    @Converter
-    public int intFromByteArray(byte[] bytes) {
-        return 22;
+    @Bean
+    public PulsarAdmin pulsarAdmin(@Value("#{pulsarAdminHost}") String pulsarAdminHost) throws PulsarClientException {
+        return PulsarAdmin.builder().serviceHttpUrl(pulsarAdminHost).build();
     }
-
 }
diff --git a/examples/spring-pulsar/src/main/java/org/apache/camel/example/pulsar/server/TypeConverters.java b/examples/spring-pulsar/src/main/java/org/apache/camel/example/pulsar/common/TypeConverters.java
similarity index 79%
rename from examples/spring-pulsar/src/main/java/org/apache/camel/example/pulsar/server/TypeConverters.java
rename to examples/spring-pulsar/src/main/java/org/apache/camel/example/pulsar/common/TypeConverters.java
index 60ea682..cf94573 100644
--- a/examples/spring-pulsar/src/main/java/org/apache/camel/example/pulsar/server/TypeConverters.java
+++ b/examples/spring-pulsar/src/main/java/org/apache/camel/example/pulsar/common/TypeConverters.java
@@ -14,7 +14,9 @@
  * See the License for the specific language governing permissions and
  * limitations under the License.
  */
-package org.apache.camel.example.pulsar.server;
+package org.apache.camel.example.pulsar.common;
+
+import java.nio.ByteBuffer;
 
 import org.apache.camel.Converter;
 
@@ -22,7 +24,12 @@ public class TypeConverters implements org.apache.camel.TypeConverters {
 
     @Converter
     public int intFromByteArray(byte[] bytes) {
-        return 22;
+        return ByteBuffer.wrap(bytes).getInt();
+    }
+
+    @Converter
+    public byte[] intToByteArray(Integer value) {
+        return ByteBuffer.allocate(4).putInt(value).array();
     }
 
 }
diff --git a/examples/spring-pulsar/src/main/resources/META-INF/spring/camel-server.xml b/examples/spring-pulsar/src/main/resources/META-INF/spring/camel-server.xml
index 9ad6f0a..47a7f30 100644
--- a/examples/spring-pulsar/src/main/resources/META-INF/spring/camel-server.xml
+++ b/examples/spring-pulsar/src/main/resources/META-INF/spring/camel-server.xml
@@ -21,23 +21,12 @@
 <!-- START SNIPPET: e1 -->
 <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-       xmlns:context="http://www.springframework.org/schema/context"
        xmlns:camel="http://camel.apache.org/schema/spring"
-       xmlns:util="http://www.springframework.org/schema/util"
        xsi:schemaLocation="
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
-         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
-         http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
-         http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
+         http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
 
-    <!-- let Spring do its IoC stuff in this package -->
-    <context:component-scan base-package="org.apache.camel.example.server"/>
-
-    <!-- spring property placeholder, ignore resource not found as the file resource is for unit testing -->
-    <context:property-placeholder location="classpath:camel.properties,file:target/custom.properties"
-                                  ignore-resource-not-found="true"/>
-
-    <bean id="myOrderTypeConverters" class="org.apache.camel.example.pulsar.server.TypeConverters"/>
+    <import resource="classpath:camel-common.xml"/>
     <!-- declare a camel context that scans for classes that is RouteBuilder
          in the package org.apache.camel.example.server -->
     <camel:camelContext id="camel-server">
@@ -49,32 +38,6 @@
 
     <bean id="multiplier" class="org.apache.camel.example.pulsar.server.Treble"/>
 
-    <!-- pulsar configurations -->
-    <util:set id="clusters" value-type="java.lang.String">
-        <value>standalone</value>
-    </util:set>
-    <bean id="pulsarAdminHost" class="java.lang.String">
-        <constructor-arg value="http://localhost:8080"/>
-    </bean>
-    <bean id="pulsarAdminConfig" class="org.apache.pulsar.client.impl.conf.ClientConfigurationData">
-        <property name="serviceUrl" ref="pulsarAdminHost"/>
-    </bean>
-    <bean id="pulsarAdmin" class="org.apache.pulsar.client.admin.PulsarAdmin">
-        <constructor-arg ref="pulsarAdminHost"/>
-        <constructor-arg ref="pulsarAdminConfig"/>
-    </bean>
-    <bean id="autoconfig" class="org.apache.camel.component.pulsar.utils.AutoConfiguration">
-        <constructor-arg ref="pulsarAdmin"/>
-        <constructor-arg ref="clusters"/>
-    </bean>
-    <bean id="pulsarClientConfig" class="org.apache.pulsar.client.impl.conf.ClientConfigurationData">
-        <property name="serviceUrl" value="pulsar://localhost:6650"/>
-    </bean>
-    <bean id="pulsarClientBuilder" class="org.apache.pulsar.client.impl.ClientBuilderImpl">
-        <constructor-arg ref="pulsarClientConfig"/>
-    </bean>
-    <bean id="pulsarClient" factory-bean="pulsarClientBuilder" factory-method="build"/>
-
     <!-- pulsar component -->
     <bean id="pulsar" class="org.apache.camel.component.pulsar.PulsarComponent">
         <constructor-arg ref="camel-server"/>
diff --git a/examples/spring-pulsar/src/main/resources/camel-client.xml b/examples/spring-pulsar/src/main/resources/camel-client.xml
index fe9f1b6..cf4bfc5 100644
--- a/examples/spring-pulsar/src/main/resources/camel-client.xml
+++ b/examples/spring-pulsar/src/main/resources/camel-client.xml
@@ -20,48 +20,16 @@
 <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
        xmlns:camel="http://camel.apache.org/schema/spring"
-       xmlns:context="http://www.springframework.org/schema/context"
-       xmlns:util="http://www.springframework.org/schema/util"
        xsi:schemaLocation="
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
-         http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
-         http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
-         http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
+         http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
+
+    <import resource="camel-common.xml"/>
 
     <camel:camelContext id="camel-client">
         <camel:template id="camelTemplate"/>
     </camel:camelContext>
 
-    <!-- spring property placeholder, ignore resource not found as the file resource is for unit testing -->
-    <context:property-placeholder location="classpath:camel.properties,file:target/custom.properties"
-                                  ignore-resource-not-found="true"/>
-
-    <!-- pulsar configurations -->
-    <util:set id="clusters" value-type="java.lang.String">
-        <value>standalone</value>
-    </util:set>
-    <bean id="pulsarAdminHost" class="java.lang.String">
-        <constructor-arg value="http://localhost:8080"/>
-    </bean>
-    <bean id="pulsarAdminConfig" class="org.apache.pulsar.client.impl.conf.ClientConfigurationData">
-        <property name="serviceUrl" ref="pulsarAdminHost"/>
-    </bean>
-    <bean id="pulsarAdmin" class="org.apache.pulsar.client.admin.PulsarAdmin">
-        <constructor-arg ref="pulsarAdminHost"/>
-        <constructor-arg ref="pulsarAdminConfig"/>
-    </bean>
-    <bean id="autoconfig" class="org.apache.camel.component.pulsar.utils.AutoConfiguration">
-        <constructor-arg ref="pulsarAdmin"/>
-        <constructor-arg ref="clusters"/>
-    </bean>
-    <bean id="pulsarClientConfig" class="org.apache.pulsar.client.impl.conf.ClientConfigurationData">
-        <property name="serviceUrl" value="pulsar://localhost:6650"/>
-    </bean>
-    <bean id="pulsarClientBuilder" class="org.apache.pulsar.client.impl.ClientBuilderImpl">
-        <constructor-arg ref="pulsarClientConfig"/>
-    </bean>
-    <bean id="pulsarClient" factory-bean="pulsarClientBuilder" factory-method="build"/>
-
     <!-- pulsar component -->
     <bean id="pulsar" class="org.apache.camel.component.pulsar.PulsarComponent">
         <constructor-arg ref="camel-client"/>
diff --git a/examples/spring-pulsar/src/main/resources/camel-client.xml b/examples/spring-pulsar/src/main/resources/camel-common.xml
similarity index 67%
copy from examples/spring-pulsar/src/main/resources/camel-client.xml
copy to examples/spring-pulsar/src/main/resources/camel-common.xml
index fe9f1b6..a56cc51 100644
--- a/examples/spring-pulsar/src/main/resources/camel-client.xml
+++ b/examples/spring-pulsar/src/main/resources/camel-common.xml
@@ -19,54 +19,39 @@
 -->
 <beans xmlns="http://www.springframework.org/schema/beans"
        xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
-       xmlns:camel="http://camel.apache.org/schema/spring"
        xmlns:context="http://www.springframework.org/schema/context"
        xmlns:util="http://www.springframework.org/schema/util"
        xsi:schemaLocation="
          http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
          http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
-         http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd
          http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util.xsd">
 
-    <camel:camelContext id="camel-client">
-        <camel:template id="camelTemplate"/>
-    </camel:camelContext>
+    <!-- let Spring do its IoC stuff in this package -->
+    <context:component-scan base-package="org.apache.camel.example.pulsar.common"/>
 
     <!-- spring property placeholder, ignore resource not found as the file resource is for unit testing -->
-    <context:property-placeholder location="classpath:camel.properties,file:target/custom.properties"
+    <context:property-placeholder location="file:target/custom.properties"
                                   ignore-resource-not-found="true"/>
 
+    <bean id="myTypeConverters" class="org.apache.camel.example.pulsar.common.TypeConverters"/>
+
     <!-- pulsar configurations -->
     <util:set id="clusters" value-type="java.lang.String">
         <value>standalone</value>
     </util:set>
     <bean id="pulsarAdminHost" class="java.lang.String">
-        <constructor-arg value="http://localhost:8080"/>
-    </bean>
-    <bean id="pulsarAdminConfig" class="org.apache.pulsar.client.impl.conf.ClientConfigurationData">
-        <property name="serviceUrl" ref="pulsarAdminHost"/>
-    </bean>
-    <bean id="pulsarAdmin" class="org.apache.pulsar.client.admin.PulsarAdmin">
-        <constructor-arg ref="pulsarAdminHost"/>
-        <constructor-arg ref="pulsarAdminConfig"/>
+        <constructor-arg value="${serviceUrl:http://localhost:8080}"/>
     </bean>
     <bean id="autoconfig" class="org.apache.camel.component.pulsar.utils.AutoConfiguration">
         <constructor-arg ref="pulsarAdmin"/>
         <constructor-arg ref="clusters"/>
     </bean>
     <bean id="pulsarClientConfig" class="org.apache.pulsar.client.impl.conf.ClientConfigurationData">
-        <property name="serviceUrl" value="pulsar://localhost:6650"/>
+        <property name="serviceUrl" value="${brokerUrl:pulsar://localhost:6650}"/>
     </bean>
     <bean id="pulsarClientBuilder" class="org.apache.pulsar.client.impl.ClientBuilderImpl">
         <constructor-arg ref="pulsarClientConfig"/>
     </bean>
     <bean id="pulsarClient" factory-bean="pulsarClientBuilder" factory-method="build"/>
 
-    <!-- pulsar component -->
-    <bean id="pulsar" class="org.apache.camel.component.pulsar.PulsarComponent">
-        <constructor-arg ref="camel-client"/>
-        <property name="autoConfiguration" ref="autoconfig"/>
-        <property name="pulsarClient" ref="pulsarClient"/>
-    </bean>
-
-</beans>
\ No newline at end of file
+</beans>
diff --git a/examples/spring-pulsar/src/main/resources/camel.properties b/examples/spring-pulsar/src/main/resources/camel.properties
deleted file mode 100644
index f7b2833..0000000
--- a/examples/spring-pulsar/src/main/resources/camel.properties
+++ /dev/null
@@ -1,18 +0,0 @@
-## ---------------------------------------------------------------------------
-## 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.
-## ---------------------------------------------------------------------------
-# properties for the application
-tcp.port=61610
diff --git a/examples/spring-pulsar/src/test/java/org/apache/camel/example/SpringJmsClientServerTest.java b/examples/spring-pulsar/src/test/java/org/apache/camel/example/SpringJmsClientServerTest.java
deleted file mode 100644
index e7e8aaf..0000000
--- a/examples/spring-pulsar/src/test/java/org/apache/camel/example/SpringJmsClientServerTest.java
+++ /dev/null
@@ -1,91 +0,0 @@
-/*
- * 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.example;
-
-import java.io.File;
-import java.io.FileOutputStream;
-
-import org.apache.camel.Endpoint;
-import org.apache.camel.Exchange;
-import org.apache.camel.ExchangePattern;
-import org.apache.camel.Producer;
-import org.apache.camel.test.AvailablePortFinder;
-import org.apache.camel.test.spring.junit5.CamelSpringTestSupport;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-import org.springframework.context.support.AbstractApplicationContext;
-import org.springframework.context.support.ClassPathXmlApplicationContext;
-
-import static org.junit.jupiter.api.Assertions.assertEquals;
-
-class SpringJmsClientServerTest extends CamelSpringTestSupport {
-
-    @BeforeAll
-    public static void setupFreePort() throws Exception {
-        // find a free port number, and write that in the custom.properties file
-        // which we will use for the unit tests, to avoid port number in use problems
-        int port = AvailablePortFinder.getNextAvailable();
-        String bank1 = "tcp.port=" + port;
-
-        File custom = new File("target/custom.properties");
-        FileOutputStream fos = new FileOutputStream(custom);
-        fos.write(bank1.getBytes());
-        fos.close();
-    }
-
-    @Override
-    protected AbstractApplicationContext createApplicationContext() {
-        return new ClassPathXmlApplicationContext("/META-INF/spring/camel-server.xml");
-    }
-    
-    @Test
-    void testCamelClientInvocation() {
-        // as opposed to the CamelClientRemoting example we need to define the service URI in this java code
-        int response = template.requestBody("jms:queue:numbers", 22, Integer.class);
-        assertEquals(66, response, "Get a wrong response");
-    }
-    
-    @Test
-    void testCamelEndpointInvocation() throws Exception {
-        // get the endpoint from the camel context
-        Endpoint endpoint = context.getEndpoint("jms:queue:numbers");
-
-        // create the exchange used for the communication
-        // we use the in out pattern for a synchronized exchange where we expect a response
-        Exchange exchange = endpoint.createExchange(ExchangePattern.InOut);
-        // set the input on the in body
-        // must you correct type to match the expected type of an Integer object
-        exchange.getIn().setBody(11);
-
-        // to send the exchange we need an producer to do it for us
-        Producer producer = endpoint.createProducer();
-        // start the producer so it can operate
-        producer.start();
-
-        // let the producer process the exchange where it does all the work in this one line of code
-        producer.process(exchange);
-
-        // get the response from the out body and cast it to an integer
-        int response = exchange.getIn().getBody(Integer.class);
-        
-        assertEquals(33, response, "Get a wrong response.");
-
-        // stop the producer after usage
-        producer.stop();
-    }
-    
-}
diff --git a/examples/spring-pulsar/src/test/java/org/apache/camel/example/SpringPulsarTest.java b/examples/spring-pulsar/src/test/java/org/apache/camel/example/SpringPulsarTest.java
new file mode 100644
index 0000000..0f2c8d0
--- /dev/null
+++ b/examples/spring-pulsar/src/test/java/org/apache/camel/example/SpringPulsarTest.java
@@ -0,0 +1,72 @@
+/*
+ * 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.example;
+
+import java.nio.file.Files;
+import java.nio.file.Paths;
+import java.util.concurrent.TimeUnit;
+
+import org.apache.camel.builder.NotifyBuilder;
+import org.apache.camel.test.spring.junit5.CamelSpringTestSupport;
+import org.junit.jupiter.api.Test;
+import org.springframework.context.support.AbstractApplicationContext;
+import org.springframework.context.support.ClassPathXmlApplicationContext;
+import org.testcontainers.containers.PulsarContainer;
+import org.testcontainers.junit.jupiter.Container;
+import org.testcontainers.junit.jupiter.Testcontainers;
+import org.testcontainers.utility.DockerImageName;
+
+import static org.apache.camel.example.pulsar.client.CamelClient.ENDPOINT_URI;
+import static org.junit.jupiter.api.Assertions.assertTrue;
+
+/**
+ *  A unit test checking that Camel can exchange messages with Apache Pulsar.
+ */
+@Testcontainers
+class SpringPulsarTest extends CamelSpringTestSupport {
+
+    private static final String IMAGE = "apachepulsar/pulsar";
+
+    @Container
+    private final PulsarContainer container = new PulsarContainer(DockerImageName.parse(IMAGE));
+
+    @Override
+    protected void setupResources() throws Exception {
+        super.setupResources();
+        final String fileContent = String.format(
+            "serviceUrl=%s%nbrokerUrl=%s%n", container.getHttpServiceUrl(),
+            container.getPulsarBrokerUrl()
+        );
+        Files.writeString(Paths.get("target/custom.properties"), fileContent);
+    }
+
+    @Override
+    protected AbstractApplicationContext createApplicationContext() {
+        return new ClassPathXmlApplicationContext("/META-INF/spring/camel-server.xml");
+    }
+
+    @Test
+    void should_exchange_messages() {
+        template.sendBody(ENDPOINT_URI, 22);
+
+        NotifyBuilder notify = new NotifyBuilder(context)
+                .whenCompleted(1).wereSentTo("log:*").whenBodiesDone(66).create();
+        assertTrue(
+                notify.matches(20, TimeUnit.SECONDS), "1 message should be completed"
+        );
+    }
+}