Я пытаюсь отправить сообщение своему брокеру, используя схему Avro, но я всегда получаю сообщение об ошибке:
2020-02-01 11: 24: 37.189 [nioEventLoopGroup-4- 1] Приложение ERROR - необработанное: POST - / api / orchestration / org. apache .kafka.common.errors.SerializationException: ошибка регистрации схемы Avro: «строка». Причина: io.confluent.kafka.schemaregistry.client.rest .exceptions.RestClientException: регистрируемая схема несовместима с более ранней схемой, код ошибки: 409
Здесь мой контейнер docker:
connect:
image: confluentinc/cp-kafka-connect:5.4.0
hostname: confluentinc-connect
container_name: confluentinc-connect
depends_on:
- zookeeper
- broker
- schema-registry
ports:
- "8083:8083"
environment:
CONNECT_BOOTSTRAP_SERVERS: 'broker:29092'
CONNECT_REST_ADVERTISED_HOST_NAME: connect
CONNECT_REST_PORT: 8083
CONNECT_GROUP_ID: confluentinc-connect
CONNECT_CONFIG_STORAGE_TOPIC: confluentinc-connect-configs
CONNECT_CONFIG_STORAGE_REPLICATION_FACTOR: 1
CONNECT_OFFSET_FLUSH_INTERVAL_MS: 10000
CONNECT_OFFSET_STORAGE_TOPIC: confluentinc-connect-offsets
CONNECT_OFFSET_STORAGE_REPLICATION_FACTOR: 1
CONNECT_STATUS_STORAGE_TOPIC: confluentinc-connect-status
CONNECT_STATUS_STORAGE_REPLICATION_FACTOR: 1
CONNECT_KEY_CONVERTER: org.apache.kafka.connect.storage.StringConverter
CONNECT_KEY_CONVERTER_SCHEMAS_ENABLE: "true"
CONNECT_VALUE_CONVERTER: io.confluent.connect.avro.AvroConverter
CONNECT_VALUE_CONVERTER_SCHEMA_REGISTRY_URL: 'http://schema-registry:8081'
CONNECT_INTERNAL_KEY_CONVERTER: "org.apache.kafka.connect.json.JsonConverter"
CONNECT_INTERNAL_VALUE_CONVERTER: "org.apache.kafka.connect.json.JsonConverter"
CONNECT_ZOOKEEPER_CONNECT: 'zookeeper:2181'
CONNECT_LOG4J_ROOT_LOGLEVEL: "INFO"
CONNECT_LOG4J_LOGGERS: "org.apache.kafka.connect.runtime.rest=WARN,org.reflections=ERROR"
CONNECT_CONFIG_STORAGE_REPLICATION_FACTOR: "1"
CONNECT_OFFSET_STORAGE_REPLICATION_FACTOR: "1"
CONNECT_STATUS_STORAGE_REPLICATION_FACTOR: "1"
CONNECT_PRODUCER_INTERCEPTOR_CLASSES: "io.confluent.monitoring.clients.interceptor.MonitoringProducerInterceptor"
CONNECT_CONSUMER_INTERCEPTOR_CLASSES: "io.confluent.monitoring.clients.interceptor.MonitoringConsumerInterceptor"
CONNECT_LOG4J_LOGGERS: org.apache.zookeeper=ERROR,org.I0Itec.zkclient=ERROR,org.reflections=ERROR
CONNECT_PLUGIN_PATH: "/usr/share/java,/usr/share/extras"
Мой производитель (написан на Kolin )
val prop: HashMap<String, Any> = HashMap()
prop[BOOTSTRAP_SERVERS_CONFIG] = bootstrapServers
prop[KEY_SERIALIZER_CLASS_CONFIG] = StringSerializer::class.java.name
prop[VALUE_SERIALIZER_CLASS_CONFIG] = KafkaAvroSerializer::class.java.name
prop[SCHEMA_REGISTRY_URL] = schemaUrl
prop[ENABLE_IDEMPOTENCE_CONFIG] = idempotence
prop[ACKS_CONFIG] = acks.value
prop[RETRIES_CONFIG] = retries
prop[MAX_IN_FLIGHT_REQUESTS_PER_CONNECTION] = requestPerConnection
prop[COMPRESSION_TYPE_CONFIG] = compression.value
prop[LINGER_MS_CONFIG] = linger
prop[BATCH_SIZE_CONFIG] = batchSize.value
return KafkaProducer(prop)
Моя схема Avro:
{
"type": "record",
"namespace": "com.rjdesenvolvimento",
"name": "create_client_value",
"doc": "Avro Schema for Kafka Command",
"fields": [
{
"name": "id",
"type": "string",
"logicalType": "uuid",
"doc": "UUID for indentifaction command"
},
{
"name": "status",
"type": {
"name": "status",
"type": "enum",
"symbols": [
"Open",
"Closed",
"Processing"
],
"doc": "Can be only: Open, Closed or Processing"
},
"doc": "Status of the command"
},
{
"name": "message",
"type": {
"type": "record",
"name": "message",
"doc": "Avro Schema for insert new client",
"fields": [
{
"name": "id",
"type": "string",
"logicalType": "uuid",
"doc": "UUID for indentifaction client transaction"
},
{
"name": "active",
"type": "boolean",
"doc": "Soft delete for client"
},
{
"name": "name",
"type": "string",
"doc": "Name of the client"
},
{
"name": "email",
"type": "string",
"doc": "Email of the client"
},
{
"name": "document",
"type": "string",
"doc": "CPF or CPNJ of the client"
},
{
"name": "phones",
"doc": "A list of phone numbers",
"type": {
"type": "array",
"items": {
"name": "phones",
"type": "record",
"fields": [
{
"name": "id",
"type": "string",
"logicalType": "uuid",
"doc": "UUID for indentifaction of phone transaction"
},
{
"name": "active",
"type": "boolean",
"doc": "Soft delete for phone number"
},
{
"name": "number",
"type": "string",
"doc": "The phone number with this regex +xx xx xxxx xxxx"
}
]
}
}
},
{
"name": "address",
"type": "string",
"logicalType": "uuid",
"doc": "Adrres is an UUID for a other address-microservice"
}
]
}
}
]
}
И мой пост:
{
"id" : "9ec818da-6ee0-4634-9ed8-c085248cae12",
"status" : "Open",
"message": {
"id" : "9ec818da-6ee0-4634-9ed8-c085248cae12",
"active" : true,
"name": "name",
"email": "email@com",
"document": "document",
"phones": [
{
"id" : "9ec818da-6ee0-4634-9ed8-c085248cae12",
"active" : true,
"number": "+xx xx xxxx xxxx"
},
{
"id" : "9ec818da-6ee0-4634-9ed8-c085248cae12",
"active" : true,
"number": "+xx xx xxxx xxxx"
}
],
"address": "9ec818da-6ee0-4634-9ed8-c085248cae12"
}
}
Что я делаю не так? Github project: https://github.com/rodrigodevelms/kafka-registry
ОБНОВЛЕНИЕ =====
Вкратце: я не генерирую свои классы с помощью плагина Gradle Avro. В этом примере мой POST отправляет объект Client. И в служба, она собирает объект типа Command следующим образом:
id: тот же идентификатор клиента
статус: открыт
сообщение: POST, который был отправлен.
Поэтому я отправляю это в KAFKA, а в соединении (jdb c sink postgres) я ставлю в качестве fields.whitelist только атрибуты сообщения (клиента) и я не получаю ни идентификатор команды, ни статус.
on github the only classes that matter to understand the code are:
1 - https://github.com/rodrigodevelms/kafka-registry/blob/master/kafka/src/main/kotlin/com/rjdesenvolvimento/messagebroker/producer/Producer.kt
2 - https://github.com/rodrigodevelms/kafka-registry/blob/master/kafka/src/main/kotlin/com/rjdesenvolvimento/messagebroker/commnad/Command.kt
3 - https://github.com/rodrigodevelms/kafka-registry/blob/master/src/client/Controller.kt
4 - https://github.com/rodrigodevelms/kafka-registry/blob/master/src/client/Service.kt
5 - docker -compose.yml, insert-client-value.avs c, postgresql. json,
, если я установил режим совместимости схемы avro на «нет», я могу отправить сообщение, но будут показаны некоторые неизвестные символы, как показано на фотографии ниже.
введите описание изображения здесь