proto类kafka.message.exchangemessage$order

fykwrbwg  于 2021-06-04  发布在  Kafka
关注(0)|答案(1)|浏览(429)

我正在尝试针对ApacheKafka2.5设置MongoKafka连接器。我用的是Kafkaprotobuff连接器。

ExchangeMessage.proto
--------------------
syntax = "proto3";
package exchange_message_def;

option java_package = "kafka.message";
option java_outer_classname = "ExchangeMessage";
option optimize_for = SPEED;

message Order {
  string oid = 1;
}

我为这个proto构建了一个jar文件,并将其放在plugins路径中。但我有以下错误。
我的pom文件:

<?xml version="1.0" encoding="UTF-8"?>
<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">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.data</groupId>
    <artifactId>data-exchange</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <skip.tests>false</skip.tests>
    </properties>

    <dependencies>
        <!-- Unit testing -->
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.12</version>
            <scope>test</scope>
        </dependency>
        <!-- Protocol Buffers -->
        <dependency>
            <groupId>com.google.protobuf</groupId>
            <artifactId>protobuf-java</artifactId>
            <version>3.12.2</version>
        </dependency>
        <dependency>
            <groupId>com.github.os72</groupId>
            <artifactId>protoc-jar-maven-plugin</artifactId>
            <version>3.11.4</version>
        </dependency>
        <dependency>
            <groupId>io.grpc</groupId>
            <artifactId>protoc-gen-grpc-java</artifactId>
            <version>1.30.2</version>
            <type>pom</type>
        </dependency>
    </dependencies>
    <build>
        <plugins>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-compiler-plugin</artifactId>
                <configuration>
                    <source>11</source>
                    <target>11</target>
                </configuration>
            </plugin>
            <plugin>
                <groupId>org.apache.maven.plugins</groupId>
                <artifactId>maven-jar-plugin</artifactId>
                <version>3.0.2</version>
                <configuration>
                    <finalName>${project.name}-${project.version}</finalName>
                    <archive>
                        <manifest>
                            <addClasspath>true</addClasspath>
                            <classpathPrefix>lib/</classpathPrefix>
                        </manifest>
                    </archive>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-assembly-plugin</artifactId>
                <version>2.5.5</version>
                <configuration>
                    <appendAssemblyId>false</appendAssemblyId>
                    <finalName>${project.name}-${project.version}</finalName>
                    <descriptors>
                        <descriptor>src/assembly/dist.xml</descriptor>
                    </descriptors>
                </configuration>
            </plugin>
            <plugin>
                <artifactId>maven-dependency-plugin</artifactId>
                <executions>
                    <execution>
                        <phase>process-sources</phase>
                        <goals>
                            <goal>copy-dependencies</goal>
                        </goals>
                        <configuration>
                            <outputDirectory>${project.build.directory}/lib</outputDirectory>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
            <plugin>
                <groupId>com.github.os72</groupId>
                <artifactId>protoc-jar-maven-plugin</artifactId>
                <version>3.11.4</version>
                <executions>
                    <execution>
                        <phase>generate-sources</phase>
                        <goals>
                            <goal>run</goal>
                        </goals>
                        <configuration>
                            <protocVersion>3.12.2</protocVersion>
                            <includeDirectories>
                                <include>src/main/proto</include>
                            </includeDirectories>
                            <inputDirectories>
                                <include>src/main/proto</include>
                            </inputDirectories>
                            <outputTargets>
                                <outputTarget>
                                    <type>java</type>
                                    <addSources>main</addSources>
                                    <outputDirectory>src/main/java</outputDirectory>
                                </outputTarget>
                                <outputTarget>
                                    <type>grpc-java</type>
                                    <addSources>main</addSources>
                                    <outputDirectory>src/main/grpc</outputDirectory>
                                    <pluginArtifact>io.grpc:protoc-gen-grpc-java:1.30.2</pluginArtifact>
                                </outputTarget>
                                <outputTarget>
                                    <type>python</type>
                                    <addSources>main</addSources>
                                    <outputDirectory>src/main/python</outputDirectory>
                                </outputTarget>
                                <outputTarget>
                                    <type>js</type>
                                    <addSources>main</addSources>
                                    <outputDirectory>src/main/js</outputDirectory>
                                </outputTarget>
                            </outputTargets>
                        </configuration>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>
</project>

mongo接收器配置:

{
    "name":"mongo-sink",        
    "config":{
    "name": "mongo-sink",
    "topics": "zz",
    "connector.class": "com.mongodb.kafka.connect.MongoSinkConnector",
    "tasks.max":"1",
    "key.converter": "org.apache.kafka.connect.converters.IntegerConverter",
    "value.converter": "com.blueapron.connect.protobuf.ProtobufConverter",
    "value.converter.protoClassName":"kafka.message.ExchangeMessage$Order",
    "key.converter.schemas.enable":false,
    "value.converter.schemas.enable":true,
    "connection.uri": "mongodb://user:password@localhost:27017",
    "database":"data_db",
    "collection":"zz",
    "max.num.retries":"3",
    "retries.defer.timeout":"5000",
    "key.projection.type":"none",
    "key.projection.list": "",
    "value.projection.type":"none",
    "value.projection.list": "",
    "field.renamer.mapping":"[]",
    "field.renamer.regex":"[]",
    "document.id.strategy":"com.mongodb.kafka.connect.sink.processor.id.strategy.BsonOidStrategy",
    "post.processor.chain":"com.mongodb.kafka.connect.sink.processor.DocumentIdAdder",
    "delete.on.null.values":false,
    "writemodel.strategy":"com.mongodb.kafka.connect.sink.writemodel.strategy.ReplaceOneDefaultStrategy",
    "max.batch.size":"2",
    "rate.limiting.timeout":"100",
    "rate.limiting.every.n":"100",
    "change.data.capture.handler":""
    }
}

我收到以下错误:
org.apache.kafka.connect.errors.connectexception:在com.blueapron.connect.protobuf.protobufconverter.configure(protobufconverter)的类路径中找不到原型类kafka.message.exchangemessage$order。java:48)在org.apache.kafka.connect.runtime.isolation.plugins.newconverter(插件。java:293)在org.apache.kafka.connect.runtime.worker.starttask(worker。java:442)位于org.apache.kafka.connect.runtime.distributed.distributedherder.starttask(distributedherder)。java:1147)访问org.apache.kafka.connect.runtime.distributed.distributedherder.access$1600(distributedherder)。java:126)在org.apache.kafka.connect.runtime.distributed.distributedherder$12.call(distributedherder。java:1162)在org.apache.kafka.connect.runtime.distributed.distributedherder$12.call(distributedherder。java:1158)在java.base/java.util.concurrent.futuretask.run(futuretask。java:264)在java.base/java.util.concurrent.threadpoolexecutor.runworker(threadpoolexecutor。java:1128)在java.base/java.util.concurrent.threadpoolexecutor$worker.run(threadpoolexecutor。java:628)在java.base/java.lang.thread.run(thread。java:834)

jutyujz0

jutyujz01#

之前,我复制了3个jar文件到kafka插件路径:
mongoconnector jar文件
我的proto文件的自定义jar文件
BlueBuff连接器jar文件
为了解决这个问题,我做了以下工作:从插件路径中删除了blueporporar jar文件,并创建了一个自定义jar文件的uber jar,方法是在pom文件中添加以下内容作为依赖项:

<dependency>
        <groupId>com.sclasen</groupId>
        <artifactId>kafka-connect-protobuf-converter</artifactId>
        <version>2.0.1</version>
    </dependency>

并将我的uberjar和mongo连接器jar放在插件路径中。

相关问题