Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions apache-camel/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -849,6 +849,10 @@
<groupId>org.apache.camel</groupId>
<artifactId>camel-pubnub</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-pulsar</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-quartz</artifactId>
Expand Down Expand Up @@ -2177,6 +2181,11 @@
<artifactId>camel-pubnub-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-pulsar-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-quartz2-starter</artifactId>
Expand Down
10 changes: 10 additions & 0 deletions bom/camel-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2058,6 +2058,16 @@
<artifactId>camel-pubnub-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-pulsar</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-pulsar-starter</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-quartz</artifactId>
Expand Down
98 changes: 98 additions & 0 deletions components/camel-pulsar/pom.xml
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>
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);

Copy link
Copy Markdown
Contributor

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.

}

@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;
}
}
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);
}

}
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;
}

}
Loading