使用docker compose

时间:2019-10-16 20:51:03

标签: elasticsearch apache-kafka docker-compose apache-kafka-connect

我正在设置一个生产者,将其作为(键值)发送消息[给卡夫卡[key是生成的唯一stringvaluejson有效负载]由kafka connect(v5.3.1)提取的主题(v1.0.0),然后将其发送到Elastic搜索容器(v 7.1)。

kafka connect配置为在ES上查找具有主题名称的索引(该索引已在具有模式的ES上进行映射),并使用kafka key作为插入的每个文档的唯一id(_id)进入索引。生产者将内容放入kafka主题后,必须通过连接将其拉出并发送给ES。

kafka connect(5.3.1)需要从kafka主题发送给它的值具有以下格式,以便将其映射到弹性搜索索引

{
"schema": {es_schema },
"payload":{ es_payload }
}

我的制作人只能发送

{
es_payload
}

我正在使用docker / docker-compose容器在本地模拟

我让生产者能够发送到kafka并被kafka connect接走,但是无法发送给弹性节点,说明在有效负载中找不到该模式

我的kafka connect sink配置

curl -X POST \
  http://localhost:8083/connectors/ \
  -H 'Content-Type: application/json' \
  -d '{
  "name": "elasticsearch-sink",
  "config": {
    "connector.class": "io.confluent.connect.elasticsearch.ElasticsearchSinkConnector",
    "tasks.max": "1",
    "topics": "adn-kafka",
    "key.ignore": "false",
    "schema.ignore": "false",
    "connection.url": "http://elasticsearch:9200",
    "type.name": "",
    "name": "elasticsearch-sink",
    "value.converter.schemas.enable": "false",
    "key.converter.schemas.enable":"false"
  }
}'

我得到的错误

Caused by: org.apache.kafka.connect.errors.DataException: JsonConverter with schemas.enable requires "schema" and "payload" fields and may not contain additional fields. If you are trying to deserialize plain JSON data, set schemas.enable=false in your converter configuration.
     at org.apache.kafka.connect.json.JsonConverter.toConnectData(JsonConverter.java:338)
     at org.apache.kafka.connect.runtime.WorkerSinkTask.lambda$convertAndTransformRecord$0(WorkerSinkTask.java:510)
     at org.apache.kafka.connect.runtime.errors.RetryWithToleranceOperator.execAndRetry(RetryWithToleranceOperator.java:128)
     at org.apache.kafka.connect.runtime.errors.RetryWithToleranceOperator.execAndHandleError(RetryWithToleranceOperator.java:162)
     ... 13 more

如果我设置了schema.ignore : true,它不会在架构中寻找索引,我认为这是正确的方式,因为我的索引已被映射,并且我不希望kafka连接发送以创建新索引< / p>

我的docker撰写

version: '3'
services:
  zookeeper:
    container_name : zookeeper
    image: zookeeper
    ports:
     - 2181:2181
     - 2888:2888
     - 3888:3888

  kafka:
    container_name : kafka
    image: bitnami/kafka:1.0.0-r5
    depends_on:
      - zookeeper
    ports:
      - "9092:9092"
    environment:
      KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181
      KAFKA_BROKER_ID: "42"
      KAFKA_ADVERTISED_HOST_NAME: "kafka"
      ALLOW_PLAINTEXT_LISTENER: "yes" 

  elasticsearch:
    container_name : elasticsearch
    image:
      elasticsearch:7.1.1
    ulimits:
      memlock:
        soft: -1
        hard: -1
      nofile:
        soft: 65536
        hard: 65536
    environment:
      - cluster.name=docker-cluster
      - node.name=node1
      - bootstrap.memory_lock=true
      - "ES_JAVA_OPTS=-Xms4g -Xmx4g"
      - discovery.type=single-node

    ports:
      - "9400:9200"
      - "9500:9300"
    deploy:
      resources:
        limits:
          memory: 6G
        reservations:
          memory: 6G
  kibana:
    container_name : kibana
    image: docker.elastic.co/kibana/kibana:7.1.1
    # environment:
      # - SERVER_NAME=Local kibana
      # - SERVER_HOST=0.0.0.0
      # - ELASTICSEARCH_URL=elasticsearch:9400
    ports:
      - "5601:5601"
    depends_on:
      - elasticsearch

  kafka-connect:
    container_name : kafka-connect
    image: confluentinc/cp-kafka-connect:5.3.1
    ports:
      - 8083:8083
    depends_on:
      - zookeeper
      - kafka
    volumes:
      - $PWD/connect-plugins:/connect-plugins
    environment:
      CONNECT_BOOTSTRAP_SERVERS: "kafka:9092"
      CONNECT_REST_PORT: 8083
      CONNECT_GROUP_ID: kafka-connect
      CONNECT_CONFIG_STORAGE_TOPIC: docker-kafka-connect-configs
      CONNECT_OFFSET_STORAGE_TOPIC: docker-kafka-connect-offsets
      CONNECT_STATUS_STORAGE_TOPIC: docker-kafka-connect-status
      CONNECT_KEY_CONVERTER: "org.apache.kafka.connect.storage.StringConverter"
      CONNECT_VALUE_CONVERTER: "org.apache.kafka.connect.json.JsonConverter"
      CONNECT_INTERNAL_KEY_CONVERTER: "org.apache.kafka.connect.json.JsonConverter"
      CONNECT_INTERNAL_VALUE_CONVERTER: "org.apache.kafka.connect.json.JsonConverter"
      CONNECT_KEY_CONVERTER-SCHEMAS_ENABLE: "false"
      CONNECT_VALUE_CONVERTER-SCHEMAS_ENABLE: "false"
      CONNECT_REST_ADVERTISED_HOST_NAME: "kafka-connect"
      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_PLUGIN_PATH: '/usr/share/java'
      # Interceptor config
      CONNECT_PRODUCER_INTERCEPTOR_CLASSES: "io.confluent.monitoring.clients.interceptor.MonitoringProducerInterceptor"
      CONNECT_CONSUMER_INTERCEPTOR_CLASSES: "io.confluent.monitoring.clients.interceptor.MonitoringConsumerInterceptor"
      CLASSPATH: /usr/share/java/monitoring-interceptors/monitoring-interceptors-5.3.1.jar

kafka主题名称:test-kafka

Es索引:test-kafka

ES映射

{
    "mappings":{
        "properties" :{
            "ppid":{
                "type":"long"
            },
            "field1":{
                "type":"long"
            },
            "field2":{
                "type":"long"
            },
            "time1":{
                "type":"date",
                "format":"yyyy-MM-dd HH:mm:ss"
            },
            "time2":{
                "type":"date",
                "format":"yyyy-MM-dd HH:mm:ss"
            },
            "status":{
                "type":"keyword"
            },
            "field3":{
                "type":"integer"
            },
            "field4":{
                "type":"integer"
            }
        }
    }
}

有效载荷已发送到kafka主题

{ "ppid" : 1, "field1":2 , "field2":1,"time1":"2019-09-25 07:36:48", "time2":"2019-09-25 07:36:48", "status":"SUCCESS", "field3":30,"field4":16}

0 个答案:

没有答案