Skip to content

Commit

Permalink
Add support of pulsar-kafka-adapter for kafka-0.9 api (apache#4886)
Browse files Browse the repository at this point in the history
Fixes apache#4791

**Motivation**

Currently the Pulsar Kafka wrapper is using Kafka 0.10.x version. However, there are users who use legacy-kafka version in their system and willing to move to pulsar. This PR provides pulsar-kafka adapter for kafka-api-version 0.9.X. So, this adapter can help users in their migration process from kafka-0.9 to pulsar.
  • Loading branch information
fxbing authored and sijie committed Aug 6, 2019
1 parent c7b2cb3 commit f6ed037
Show file tree
Hide file tree
Showing 23 changed files with 2,235 additions and 3 deletions.
3 changes: 3 additions & 0 deletions pulsar-client-kafka-compat/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,10 @@

<modules>
<module>pulsar-client-kafka</module>
<module>pulsar-client-kafka_0_9</module>
<module>pulsar-client-kafka-shaded</module>
<module>pulsar-client-kafka-shaded_0_9</module>
<module>pulsar-client-kafka-tests</module>
<module>pulsar-client-kafka-tests_0_9</module>
</modules>
</project>
271 changes: 271 additions & 0 deletions pulsar-client-kafka-compat/pulsar-client-kafka-shaded_0_9/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,271 @@
<?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
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.apache.pulsar</groupId>
<artifactId>pulsar-client-kafka-compat</artifactId>
<version>2.5.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

<artifactId>pulsar-client-kafka_0_9</artifactId>
<name>Pulsar Kafka compatibility 0.9 :: API</name>

<description>Drop-in replacement for Kafka client library that publishes and consumes
messages on Pulsar topics</description>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>pulsar-client-kafka_0_9-original</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-shade-plugin</artifactId>
<executions>
<execution>
<phase>package</phase>
<goals>
<goal>shade</goal>
</goals>
<configuration>
<createDependencyReducedPom>true</createDependencyReducedPom>
<promoteTransitiveDependencies>true</promoteTransitiveDependencies>
<artifactSet>
<includes>
<include>org.apache.kafka:kafka-clients</include>
<include>org.apache.pulsar:pulsar-client-kafka_0_9-original</include>
<include>org.apache.pulsar:pulsar-client-original</include>
<include>org.apache.commons:commons-lang3</include>
<include>commons-codec:commons-codec</include>
<include>org.apache.bookkeeper:bookkeeper-common-allocator</include>
<include>commons-collections:commons-collections</include>
<include>org.asynchttpclient:*</include>
<include>io.netty:netty-codec-http</include>
<include>io.netty:netty-transport-native-epoll</include>
<include>org.reactivestreams:reactive-streams</include>
<include>com.typesafe.netty:netty-reactive-streams</include>
<include>org.javassist:javassist</include>
<include>com.google.protobuf:protobuf-java</include>
<include>com.google.guava:guava</include>
<include>com.google.code.gson:gson</include>
<include>com.fasterxml.jackson.core</include>
<include>com.fasterxml.jackson.module</include>
<include>com.fasterxml.jackson.dataformat</include>
<include>io.netty:netty</include>
<include>io.netty:netty-*</include>
<include>org.apache.pulsar:pulsar-common</include>
<include>org.apache.bookkeeper:circe-checksum</include>
<include>com.yahoo.datasketches:sketches-core</include>
<include>org.apache.httpcomponents:httpclient</include>
<include>commons-logging:commons-logging</include>
<include>org.apache.httpcomponents:httpcore</include>
<include>org.eclipse.jetty:*</include>
<include>com.yahoo.datasketches:*</include>
<include>commons-*:*</include>
<include>org.yaml:snakeyaml</include>
<include>org.objenesis:*</include>

<include>org.apache.avro:*</include>
<!-- Avro transitive dependencies-->
<include>org.codehaus.jackson:jackson-core-asl</include>
<include>org.codehaus.jackson:jackson-mapper-asl</include>
<include>com.thoughtworks.paranamer:paranamer</include>
<include>org.xerial.snappy:snappy-java</include>
<include>org.apache.commons:commons-compress</include>
<include>org.tukaani:xz</include>
</includes>
</artifactSet>
<filters>
<filter>
<artifact>commons-logging:commons-logging</artifact>
<includes>
<include>**</include>
</includes>
</filter>
</filters>
<relocations>
<relocation>
<pattern>org.apache.kafka.clients.producer.KafkaProducer</pattern>
<shadedPattern>org.apache.kafka.clients.producer.OriginalKafkaProducer</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.kafka.clients.producer.PulsarKafkaProducer</pattern>
<shadedPattern>org.apache.kafka.clients.producer.KafkaProducer</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.kafka.clients.consumer.KafkaConsumer</pattern>
<shadedPattern>org.apache.kafka.clients.consumer.OriginalKafkaConsumer</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.kafka.clients.consumer.PulsarKafkaConsumer</pattern>
<shadedPattern>org.apache.kafka.clients.consumer.KafkaConsumer</shadedPattern>
</relocation>

<!-- General relocation rules for Pulsar client dependencies -->

<relocation>
<pattern>org.asynchttpclient</pattern>
<shadedPattern>org.apache.pulsar.shade.org.asynchttpclient</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.commons</pattern>
<shadedPattern>org.apache.pulsar.shade.org.apache.commons</shadedPattern>
</relocation>
<relocation>
<pattern>com.google</pattern>
<shadedPattern>org.apache.pulsar.shade.com.google</shadedPattern>
</relocation>
<relocation>
<pattern>com.fasterxml.jackson</pattern>
<shadedPattern>org.apache.pulsar.shade.com.fasterxml.jackson</shadedPattern>
</relocation>
<relocation>
<pattern>io.netty</pattern>
<shadedPattern>org.apache.pulsar.shade.io.netty</shadedPattern>
</relocation>
<relocation>
<pattern>com.yahoo.datasketches</pattern>
<shadedPattern>org.apache.pulsar.shade.com.yahoo.datasketches</shadedPattern>
</relocation>
<relocation>
<pattern>com.yahoo.sketches</pattern>
<shadedPattern>org.apache.pulsar.shade.com.yahoo.sketches</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.http</pattern>
<shadedPattern>org.apache.pulsar.shade.org.apache.http</shadedPattern>
</relocation>
<relocation>
<pattern>org.eclipse.jetty</pattern>
<shadedPattern>org.apache.pulsar.shade.org.eclipse</shadedPattern>
</relocation>
<relocation>
<pattern>org.reactivestreams</pattern>
<shadedPattern>org.apache.pulsar.shade.org.reactivestreams</shadedPattern>
</relocation>
<relocation>
<pattern>com.typesafe</pattern>
<shadedPattern>org.apache.pulsar.shade.com.typesafe</shadedPattern>
</relocation>
<relocation>
<pattern>com.yahoo.memory</pattern>
<shadedPattern>org.apache.pulsar.shade.com.yahoo.memory</shadedPattern>
</relocation>
<relocation>
<pattern>org.objenesis</pattern>
<shadedPattern>org.apache.pulsar.shade.org.objenesis</shadedPattern>
</relocation>
<relocation>
<pattern>org.yaml</pattern>
<shadedPattern>org.apache.pulsar.shade.org.yaml</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.avro</pattern>
<shadedPattern>org.apache.pulsar.shade.org.apache.avro</shadedPattern>
<excludes>
<exclude>org.apache.avro.reflect.AvroAlias</exclude>
<exclude>org.apache.avro.reflect.AvroDefault</exclude>
<exclude>org.apache.avro.reflect.AvroEncode</exclude>
<exclude>org.apache.avro.reflect.AvroIgnore</exclude>
<exclude>org.apache.avro.reflect.AvroMeta</exclude>
<exclude>org.apache.avro.reflect.AvroName</exclude>
<exclude>org.apache.avro.reflect.AvroSchema</exclude>
<exclude>org.apache.avro.reflect.Nullable</exclude>
<exclude>org.apache.avro.reflect.Stringable</exclude>
<exclude>org.apache.avro.reflect.Union</exclude>
</excludes>
</relocation>
<!--Avro transitive dependencies-->
<relocation>
<pattern>org.codehaus.jackson</pattern>
<shadedPattern>org.apache.pulsar.shade.org.codehaus.jackson</shadedPattern>
</relocation>
<relocation>
<pattern>com.thoughtworks.paranamer</pattern>
<shadedPattern>org.apache.pulsar.shade.com.thoughtworks.paranamer</shadedPattern>
</relocation>
<relocation>
<pattern>org.xerial.snappy</pattern>
<shadedPattern>org.apache.pulsar.shade.org.xerial.snappy</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.commons</pattern>
<shadedPattern>org.apache.pulsar.shade.org.apache.commons</shadedPattern>
</relocation>
<relocation>
<pattern>org.tukaani</pattern>
<shadedPattern>org.apache.pulsar.shade.org.tukaani</shadedPattern>
</relocation>
<relocation>
<pattern>org.apache.bookkeeper</pattern>
<shadedPattern>org.apache.pulsar.shade.org.apache.bookkeeper</shadedPattern>
</relocation>
</relocations>
<filters>
<filter>
<artifact>org.apache.pulsar:pulsar-client-original</artifact>
<includes>
<include>**</include>
</includes>
</filter>
</filters>
</configuration>
</execution>
</executions>
</plugin>
<plugin>
<!-- This plugin is used to run a script after the package phase in order to rename
libnetty_transport_native_epoll_x86_64.so from Netty into
liborg_apache_pulsar_shade_netty_transport_native_epoll_x86_64.so
to reflect the shade that is being applied.
-->
<artifactId>exec-maven-plugin</artifactId>
<groupId>org.codehaus.mojo</groupId>
<executions>
<execution>
<id>rename-epoll-library</id>
<phase>package</phase>
<goals>
<goal>exec</goal>
</goals>
<configuration>
<executable>${project.parent.basedir}/../src/${rename.netty.native.libs}</executable>
<arguments>
<argument>${project.artifactId}</argument>
</arguments>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ public static void main(String[] args) {
log.info("Message {} sent successfully", i);
}

producer.flush();
producer.close();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ public static void main(String[] args) {
log.info("Message {} sent successfully", i);
}

producer.flush();
producer.close();
}

Expand Down
70 changes: 70 additions & 0 deletions pulsar-client-kafka-compat/pulsar-client-kafka-tests_0_9/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
<?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
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"
xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.apache.pulsar</groupId>
<artifactId>pulsar-client-kafka-compat</artifactId>
<version>2.5.0-SNAPSHOT</version>
<relativePath>..</relativePath>
</parent>

<artifactId>pulsar-client-kafka_0_9-tests</artifactId>
<name>Pulsar Kafka compatibility 0.9 :: Tests</name>

<description>Tests to verify the correct shading configuration for the pulsar-client-kafka wrapper</description>

<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>pulsar-client-kafka_0_9</artifactId>
<version>${project.version}</version>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>pulsar-broker</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>pulsar-broker</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>

<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>managed-ledger-original</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<type>test-jar</type>
</dependency>
</dependencies>

</project>
Loading

0 comments on commit f6ed037

Please sign in to comment.