+关注
已关注

分类  

暂无分类

标签  

暂无标签

日期归档  

暂无数据

在nuclio中解组json

发布于2021-04-16 06:51     阅读(41)     评论(0)     点赞(12)     收藏(2)


0

1

2

3

4

5

我正在尝试使用nuclio创建一个kafka触发器。

我的function.yaml文件是:

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

我的handler.py文件是:

def consumer(context, event):
    if event.trigger.kind == 'kafka-cluster':
        context.logger.info('Invoked from kafka-cluster')

    else:
        return 'A string response'

我通过给我的yml和py文件路径使用一个docker文件运行nuclio:

FROM nuclio/uhttpc:0.0.1-amd64 as uhttpc

# Supplies processor binary, wrapper
FROM ${NUCLIO_ONBUILD_IMAGE} as processor

# From the base image
FROM ${NUCLIO_BASE_IMAGE}

# Copy required objects from the suppliers
COPY --from=processor /home/nuclio/bin/processor /usr/local/bin/processor
COPY --from=processor /home/nuclio/bin/py /opt/nuclio/
COPY --from=uhttpc /home/nuclio/bin/uhttpc /usr/local/bin/uhttpc

RUN pip install nuclio-sdk msgpack --no-index --find-links /opt/nuclio/whl


# Readiness probe
HEALTHCHECK --interval=1s --timeout=3s CMD /usr/local/bin/uhttpc --url http://127.0.0.1:8082/ready || exit 1

# USER CONTENT
ADD ./NuclioKafkaHandler.py /opt/nuclio
ADD ./function.yaml /etc/nuclio/config/processor/processor.yaml
# END OF USER CONTENT

# Run processor with configuration and platform configuration
CMD [ "processor" ]

当我使用kafka在网络中运行我的docker文件时(zookeeper和kafka都在网络rmoff_kafka中运行):

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

我收到以下错误消息:

Error - error unmarshaling JSON: json: cannot unmarshal array into Go value of type functionconfig.Trigger
    .../nuclio/nuclio/pkg/processor/config/reader.go:47

Call stack:
Failed to write configuration
    .../nuclio/nuclio/pkg/processor/config/reader.go:47
Failed to open configuration file
    .../nuclio/nuclio/cmd/processor/app/processor.go:262

解决方案


暂无回答

0

1

2

3

4

5

6

7

8



所属网站分类: 技术文章 > 问答

作者:黑洞官方问答小能手

链接: https://www.pythonheidong.com/blog/article/939359/998ad694d4c2289c9855/

来源: python黑洞网

任何形式的转载都请注明出处,如有侵权 一经发现 必将追究其法律责任

12 0
收藏该文
已收藏

评论内容:(最多支持255个字符)