-
Notifications
You must be signed in to change notification settings - Fork 5.2k
CAMEL-12665 - Apache Pulsar integration via Component #2849
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Closed
Closed
Changes from all commits
Commits
Show all changes
19 commits
Select commit
Hold shift + click to select a range
93b8b2b
squashed commit of cherrypick to camel-2.x branch
e85f611
addressing apache review comments
foamdino bd67e44
rename from Utils -> Impl
foamdino a7e373c
change to interface
foamdino 8f5c4bb
remove THG specific string
foamdino 4692b8e
remove THG specific string
foamdino 2aef9bd
add testcontainers support and fix PulsarConcurrentConsumerInTest
foamdino 397a2d3
fix more container tests
foamdino 31547cf
add component META-INF
foamdino 68b15f4
fix documentation, remove unneeded method call
foamdino a11fcba
renaming tests
foamdino 4258cb1
remove jdk properties
foamdino 4ef5a9c
remove empty retry code
foamdino 6edeead
fix tests
foamdino 00f7df0
remove commented out logging
foamdino 1ca0022
adjust pom as requested
foamdino c48c4df
address most of the checkstyle comments except one make final as it p…
foamdino fcba9d3
Revert "address most of the checkstyle comments except one make final…
foamdino c98012e
Backport Pulsar Component changes from master to 2.x
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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,98 @@ | ||
| <?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> | ||
| <artifactId>components</artifactId> | ||
| <groupId>org.apache.camel</groupId> | ||
| <version>2.24.0-SNAPSHOT</version> | ||
| </parent> | ||
| <modelVersion>4.0.0</modelVersion> | ||
|
|
||
| <artifactId>camel-pulsar</artifactId> | ||
| <packaging>jar</packaging> | ||
| <name>Camel :: Pulsar</name> | ||
| <description>Camel Apache Pulsar Component</description> | ||
|
|
||
| <properties> | ||
| </properties> | ||
|
|
||
| <dependencies> | ||
|
|
||
| <dependency> | ||
| <groupId>org.apache.pulsar</groupId> | ||
| <artifactId>pulsar-client</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.pulsar</groupId> | ||
| <artifactId>pulsar-client-admin</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.camel</groupId> | ||
| <artifactId>camel-core</artifactId> | ||
| </dependency> | ||
|
|
||
| <!-- testing --> | ||
| <dependency> | ||
| <groupId>org.apache.camel</groupId> | ||
| <artifactId>camel-test</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.mockito</groupId> | ||
| <artifactId>mockito-core</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>junit</groupId> | ||
| <artifactId>junit</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.testcontainers</groupId> | ||
| <artifactId>testcontainers</artifactId> | ||
| <version>${testcontainers-version}</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.testcontainers</groupId> | ||
| <artifactId>pulsar</artifactId> | ||
| <version>${testcontainers-version}</version> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <!-- logging --> | ||
| <dependency> | ||
| <groupId>org.apache.logging.log4j</groupId> | ||
| <artifactId>log4j-api</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.logging.log4j</groupId> | ||
| <artifactId>log4j-core</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>org.apache.logging.log4j</groupId> | ||
| <artifactId>log4j-slf4j-impl</artifactId> | ||
| <scope>test</scope> | ||
| </dependency> | ||
| </dependencies> | ||
| </project> |
81 changes: 81 additions & 0 deletions
81
components/camel-pulsar/src/main/java/org/apache/camel/component/pulsar/PulsarComponent.java
This file contains hidden or 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,81 @@ | ||
| /* | ||
| * 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.component.pulsar; | ||
|
|
||
| import java.util.Map; | ||
|
|
||
| import org.apache.camel.CamelContext; | ||
| import org.apache.camel.Endpoint; | ||
| import org.apache.camel.component.pulsar.configuration.PulsarConfiguration; | ||
| import org.apache.camel.component.pulsar.utils.AutoConfiguration; | ||
| import org.apache.camel.impl.DefaultComponent; | ||
| import org.apache.camel.spi.Metadata; | ||
| import org.apache.pulsar.client.api.PulsarClient; | ||
|
|
||
| public class PulsarComponent extends DefaultComponent { | ||
|
|
||
| @Metadata | ||
| private AutoConfiguration autoConfiguration; | ||
| @Metadata | ||
| private PulsarClient pulsarClient; | ||
|
|
||
| public PulsarComponent() { | ||
| this(null); | ||
| } | ||
|
|
||
| public PulsarComponent(CamelContext context) { | ||
| super(context); | ||
| } | ||
|
|
||
| @Override | ||
| protected Endpoint createEndpoint(final String uri, final String path, final Map<String, Object> parameters) throws Exception { | ||
| final PulsarConfiguration configuration = new PulsarConfiguration(); | ||
|
|
||
| setProperties(configuration, parameters); | ||
| if (autoConfiguration != null) { | ||
| setProperties(autoConfiguration, parameters); | ||
|
|
||
| if (autoConfiguration.isAutoConfigurable()) { | ||
| autoConfiguration.ensureNameSpaceAndTenant(path); | ||
| } | ||
| } | ||
|
|
||
| return PulsarEndpoint.create(uri, path, configuration, this, pulsarClient); | ||
| } | ||
|
|
||
| public AutoConfiguration getAutoConfiguration() { | ||
| return autoConfiguration; | ||
| } | ||
|
|
||
| /** | ||
| * The pulsar autoconfiguration | ||
| */ | ||
| public void setAutoConfiguration(AutoConfiguration autoConfiguration) { | ||
| this.autoConfiguration = autoConfiguration; | ||
| } | ||
|
|
||
| public PulsarClient getPulsarClient() { | ||
| return pulsarClient; | ||
| } | ||
|
|
||
| /** | ||
| * The pulsar client | ||
| */ | ||
| public void setPulsarClient(PulsarClient pulsarClient) { | ||
| this.pulsarClient = pulsarClient; | ||
| } | ||
| } | ||
81 changes: 81 additions & 0 deletions
81
components/camel-pulsar/src/main/java/org/apache/camel/component/pulsar/PulsarConsumer.java
This file contains hidden or 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,81 @@ | ||
| /* | ||
| * 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.component.pulsar; | ||
|
|
||
| import java.util.Collection; | ||
| import java.util.Queue; | ||
| import java.util.concurrent.ConcurrentLinkedQueue; | ||
|
|
||
| import org.apache.camel.Processor; | ||
| import org.apache.camel.component.pulsar.utils.consumers.ConsumerCreationStrategy; | ||
| import org.apache.camel.component.pulsar.utils.consumers.ConsumerCreationStrategyFactory; | ||
| import org.apache.camel.impl.DefaultConsumer; | ||
| import org.apache.pulsar.client.api.Consumer; | ||
| import org.apache.pulsar.client.api.PulsarClientException; | ||
|
|
||
| import static org.apache.camel.component.pulsar.utils.PulsarUtils.stopConsumers; | ||
|
|
||
| public class PulsarConsumer extends DefaultConsumer { | ||
|
|
||
| private final PulsarEndpoint pulsarEndpoint; | ||
| private final ConsumerCreationStrategyFactory consumerCreationStrategyFactory; | ||
|
|
||
| private Queue<Consumer<byte[]>> pulsarConsumers; | ||
|
|
||
| public PulsarConsumer(PulsarEndpoint pulsarEndpoint, Processor processor) { | ||
| super(pulsarEndpoint, processor); | ||
| this.pulsarEndpoint = pulsarEndpoint; | ||
| this.pulsarConsumers = new ConcurrentLinkedQueue<>(); | ||
| this.consumerCreationStrategyFactory = ConsumerCreationStrategyFactory.create(this); | ||
| } | ||
|
|
||
| @Override | ||
| protected void doStart() throws Exception { | ||
| pulsarConsumers = stopConsumers(pulsarConsumers); | ||
|
|
||
| Collection<Consumer<byte[]>> consumers = createConsumers(pulsarEndpoint, consumerCreationStrategyFactory); | ||
|
|
||
| pulsarConsumers.addAll(consumers); | ||
| } | ||
|
|
||
| @Override | ||
| protected void doStop() throws PulsarClientException { | ||
| pulsarConsumers = stopConsumers(pulsarConsumers); | ||
| } | ||
|
|
||
| @Override | ||
| protected void doSuspend() throws PulsarClientException { | ||
| pulsarConsumers = stopConsumers(pulsarConsumers); | ||
| } | ||
|
|
||
| @Override | ||
| protected void doResume() throws Exception { | ||
| pulsarConsumers = stopConsumers(pulsarConsumers); | ||
|
|
||
| Collection<Consumer<byte[]>> consumers = createConsumers(pulsarEndpoint, consumerCreationStrategyFactory); | ||
|
|
||
| pulsarConsumers.addAll(consumers); | ||
| } | ||
|
|
||
| private Collection<Consumer<byte[]>> createConsumers(final PulsarEndpoint endpoint, final ConsumerCreationStrategyFactory factory) throws Exception { | ||
|
|
||
| ConsumerCreationStrategy strategy = factory.getStrategy(endpoint.getPulsarConfiguration().getSubscriptionType()); | ||
|
|
||
| return strategy.create(endpoint); | ||
| } | ||
|
|
||
| } |
92 changes: 92 additions & 0 deletions
92
components/camel-pulsar/src/main/java/org/apache/camel/component/pulsar/PulsarEndpoint.java
This file contains hidden or 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,92 @@ | ||
| /* | ||
| * 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.component.pulsar; | ||
|
|
||
| import org.apache.camel.Consumer; | ||
| import org.apache.camel.Exchange; | ||
| import org.apache.camel.Processor; | ||
| import org.apache.camel.Producer; | ||
| import org.apache.camel.component.pulsar.configuration.PulsarConfiguration; | ||
| import org.apache.camel.impl.DefaultEndpoint; | ||
| import org.apache.camel.spi.UriEndpoint; | ||
| import org.apache.camel.spi.UriParam; | ||
| import org.apache.camel.spi.UriPath; | ||
| import org.apache.pulsar.client.api.PulsarClient; | ||
| import org.apache.pulsar.client.api.PulsarClientException; | ||
|
|
||
| @UriEndpoint(scheme = "pulsar", title = "Apache Pulsar", syntax = "pulsar:persistence://tenant/namespace/topic", label = "messaging") | ||
| public class PulsarEndpoint extends DefaultEndpoint { | ||
|
|
||
| private PulsarClient pulsarClient; | ||
| @UriParam | ||
| private PulsarConfiguration pulsarConfiguration; | ||
| @UriPath(label = "consumer,producer", description = "The Topic's full URI path including type, tenant and namespace") | ||
| private final String topic; | ||
|
|
||
| public PulsarEndpoint(String uri, String path, PulsarConfiguration pulsarConfiguration, PulsarComponent component, PulsarClient pulsarClient) throws PulsarClientException { | ||
| super(uri, component); | ||
| this.topic = path; | ||
| this.pulsarConfiguration = pulsarConfiguration; | ||
| this.pulsarClient = pulsarClient; | ||
| } | ||
|
|
||
| public static PulsarEndpoint create(final String uri, final String path, final PulsarConfiguration pulsarConfiguration, final PulsarComponent component, | ||
| final PulsarClient pulsarClient) | ||
| throws PulsarClientException, IllegalArgumentException { | ||
|
|
||
| if (null == pulsarConfiguration) { | ||
| throw new IllegalArgumentException("PulsarEndpointConfiguration cannot be null"); | ||
| } | ||
|
|
||
| return new PulsarEndpoint(uri, path, pulsarConfiguration, component, pulsarClient); | ||
| } | ||
|
|
||
| @Override | ||
| public Producer createProducer() { | ||
| return new PulsarProducer(this); | ||
| } | ||
|
|
||
| @Override | ||
| public Consumer createConsumer(Processor processor) throws Exception { | ||
| PulsarConsumer consumer = new PulsarConsumer(this, processor); | ||
| configureConsumer(consumer); | ||
| return consumer; | ||
| } | ||
|
|
||
| @Override | ||
| public boolean isSingleton() { | ||
| return false; | ||
| } | ||
|
|
||
| @Override | ||
| public Exchange createExchange() { | ||
| return super.createExchange(); | ||
| } | ||
|
|
||
| public PulsarClient getPulsarClient() { | ||
| return pulsarClient; | ||
| } | ||
|
|
||
| public PulsarConfiguration getPulsarConfiguration() { | ||
| return pulsarConfiguration; | ||
| } | ||
|
|
||
| public String getTopic() { | ||
| return topic; | ||
| } | ||
|
|
||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The constructor must be changed like on master.