在nuclio中解组json

vqlkdk9b  于 2021-06-04  发布在  Kafka
关注(0)|答案(0)|浏览(245)

我想用努克利奥创造一个Kafka触发器。
我的function.yaml文件是:

  1. apiVersion: "nuclio.io/v1beta1"
  2. kind: "NuclioFunction"
  3. spec:
  4. description: >
  5. Uses the inception model of the TensorFlow open-source machine-learning library to classify images.
  6. The function demonstrates advanced uses of nuclio with a custom base image, third-party Python packages,
  7. pre-loading data into function memory (the AI Model), structured logging, and exception handling.
  8. runtime: "python:3.6"
  9. handler: handler:consumer
  10. minReplicas: 1
  11. maxReplicas: 1
  12. triggers:
  13. myKafkaTrigger:
  14. kind: kafka-cluster
  15. attributes:
  16. initialOffset: earliest
  17. topics:
  18. - mytopic
  19. brokers:
  20. - broker:9092
  21. consumerGroup: my-consumer-group

我的handler.py文件是:

  1. def consumer(context, event):
  2. if event.trigger.kind == 'kafka-cluster':
  3. context.logger.info('Invoked from kafka-cluster')
  4. else:
  5. return 'A string response'

我正在使用docker文件运行nuclio,方法是提供yml和py文件路径:

  1. FROM nuclio/uhttpc:0.0.1-amd64 as uhttpc
  2. # Supplies processor binary, wrapper
  3. FROM ${NUCLIO_ONBUILD_IMAGE} as processor
  4. # From the base image
  5. FROM ${NUCLIO_BASE_IMAGE}
  6. # Copy required objects from the suppliers
  7. COPY --from=processor /home/nuclio/bin/processor /usr/local/bin/processor
  8. COPY --from=processor /home/nuclio/bin/py /opt/nuclio/
  9. COPY --from=uhttpc /home/nuclio/bin/uhttpc /usr/local/bin/uhttpc
  10. RUN pip install nuclio-sdk msgpack --no-index --find-links /opt/nuclio/whl
  11. # Readiness probe
  12. HEALTHCHECK --interval=1s --timeout=3s CMD /usr/local/bin/uhttpc --url http://127.0.0.1:8082/ready || exit 1
  13. # USER CONTENT
  14. ADD ./NuclioKafkaHandler.py /opt/nuclio
  15. ADD ./function.yaml /etc/nuclio/config/processor/processor.yaml
  16. # END OF USER CONTENT
  17. # Run processor with configuration and platform configuration
  18. CMD [ "processor" ]

当我用kafka在网络中运行docker文件时(zookeeper和kafka都在网络中运行rmoff\u kafka):

  1. docker run --network=rmoff_kafka --rm --name kafka -p 8080:8080 kafka

我得到一个错误:

  1. Error - error unmarshaling JSON: json: cannot unmarshal array into Go value of type functionconfig.Trigger
  2. .../nuclio/nuclio/pkg/processor/config/reader.go:47
  3. Call stack:
  4. Failed to write configuration
  5. .../nuclio/nuclio/pkg/processor/config/reader.go:47
  6. Failed to open configuration file
  7. .../nuclio/nuclio/cmd/processor/app/processor.go:262

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题