curl命令失败,上传特定的AVRO模式,该模式可以在Postman中上传正载

发布于 2025-02-06 20:31:56 字数 3803 浏览 2 评论 0原文

在Pulsar中,我一直在编写一些简单的bash脚本,以创建和上传主题使用卷曲命令:

function create_partioned_topic {
    echo -e "\n+++ Creating partioned topic: $TOPIC +++"
    curl --location --request PUT "https://$PULSAR_HOST:$HOST_PULSAR_PORT/admin/v2/persistent/$TENANT/$NAMESPACE/$TOPIC/partitions" \
        --verbose \
        --header "Authorization: Bearer $AUTHORIZATION"  \
        --insecure \
        --header 'Content-Type: application/json' \
        --data-raw '3' 2>&1 | cat | grep "HTTP" # grep -v "Authorization"
}

function uploading_topic {
    echo -e "\n\n+++ Uploading $TOPIC +++"
    curl --location --request POST "https://$PULSAR_HOST:$HOST_PULSAR_PORT/admin/v2/schemas/$TENANT/$NAMESPACE/$TOPIC/schema" \
        --verbose \
        --header "Authorization: Bearer $AUTHORIZATION"  \
        --insecure \
        --header 'Content-Type: application/json' \
        --data-raw $SCHEMA 2>&1 | cat | grep "HTTP" # grep -v "Authorization"
}

这些命令正常工作,除了以下内容,我要上传:

TOPIC=nested_schema
NESTED_SCHEMA='{"schema":"{\"type\":\"record\",\"name\":\"DatasetEventSchema\",\"namespace\":\"channels.$TENANT.$NAMESPACE.$TOPIC.generated\",\"fields\":[{\"name\":\"DataRecord\",\"type\":{\"name\":\"DataRecordSchema\",\"type\":\"record\",\"fields\":[{\"name\":\"id\",\"type\":\"string\"},{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"description\",\"type\":\"string\"},{\"name\":\"created_by\",\"type\":\"string\"},{\"name\":\"updated_by\",\"type\":\"string\"},{\"name\":\"created_at\",\"type\":\"string\"},{\"name\":\"updated_at\",\"type\":\"string\"},{\"name\":\"data_legitimacy\",\"type\":\"string\"},{\"name\":\"item_status\",\"type\":\"string\"},{\"name\":\"tenant_id\",\"type\":\"string\"},{\"name\":\"tags\",\"type\":\"string\"},{\"name\":\"dataset_series_id\",\"type\":\"string\"},{\"name\":\"location_id\",\"type\":\"string\"},{\"name\":\"provided_by\",\"type\":\"string\"},{\"name\":\"metadata\",\"type\":\"string\"}]}},{\"name\":\"MetadataRecord\",\"type\":{\"name\":\"MetadataRecordSchema\",\"type\":\"record\",\"fields\":[{\"name\":\"timestamp\",\"type\":\"string\"},{\"name\":\"record_type\",\"type\":\"string\"},{\"name\":\"operation\",\"type\":\"string\"},{\"name\":\"partition_key_type\",\"type\":\"string\"},{\"name\":\"schema_name\",\"type\":\"string\"},{\"name\":\"table_name\",\"type\":\"string\"},{\"name\":\"transaction_id\",\"type\":\"string\"}]}}]}","type":"AVRO","properties":{}}'

当我通过curl命令上传此架构时,似乎从未完成。我收到通知,即它正在开始发布,但永远不会完成。

我上传工作的其他模式很好。两个示例是:

TOPIC=double_nested_schema
DOUBLE_NESTED_SCHEMA='{"schema":"{\"type\":\"record\",\"name\":\"DoubleNestedSchema\",\"namespace\":\"channels.$TENANT.$NAMESPACE.$TOPIC.generated\",\"fields\":[{\"name\":\"DataRecord\",\"type\":{\"name\":\"DataRecordSchema\",\"type\":\"record\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"IdRecord\",\"type\":{\"name\":\"IdRecordSchema\",\"type\":\"record\",\"fields\":[{\"name\":\"id\",\"type\":\"string\"}]}}]}},{\"name\":\"MetadataRecord\",\"type\":{\"name\":\"MetadataRecordSchema\",\"type\":\"record\",\"fields\":[{\"name\":\"timestamp\",\"type\":\"string\"}]}}]}","type":"AVRO","properties":{}}'

TOPIC=simplest_schema
SIMPLEST_SCHEMA='{"schema":"{\"type\":\"record\",\"name\":\"SimplestExample\",\"namespace\":\"channels.$TENANT.$NAMESPACE.$TOPIC.generated\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"}]}","type":"AVRO","properties":{}}'

我尝试了

  • 上述尝试的事情,我尝试了两个不同的模式simplest_schemadouble_nested_schema,它们正常工作,
  • 我还测试了运行该运行的等效于在Postman中上传我的nested_schema,并且效果很好。这是否表明卷发有些不喜欢我的格式?

In pulsar, I've been writing some simple BASH scripts to create and upload topics to my namespace using curl commands:

function create_partioned_topic {
    echo -e "\n+++ Creating partioned topic: $TOPIC +++"
    curl --location --request PUT "https://$PULSAR_HOST:$HOST_PULSAR_PORT/admin/v2/persistent/$TENANT/$NAMESPACE/$TOPIC/partitions" \
        --verbose \
        --header "Authorization: Bearer $AUTHORIZATION"  \
        --insecure \
        --header 'Content-Type: application/json' \
        --data-raw '3' 2>&1 | cat | grep "HTTP" # grep -v "Authorization"
}

function uploading_topic {
    echo -e "\n\n+++ Uploading $TOPIC +++"
    curl --location --request POST "https://$PULSAR_HOST:$HOST_PULSAR_PORT/admin/v2/schemas/$TENANT/$NAMESPACE/$TOPIC/schema" \
        --verbose \
        --header "Authorization: Bearer $AUTHORIZATION"  \
        --insecure \
        --header 'Content-Type: application/json' \
        --data-raw $SCHEMA 2>&1 | cat | grep "HTTP" # grep -v "Authorization"
}

These commands work fine except for the following I'm trying to upload:

TOPIC=nested_schema
NESTED_SCHEMA='{"schema":"{\"type\":\"record\",\"name\":\"DatasetEventSchema\",\"namespace\":\"channels.$TENANT.$NAMESPACE.$TOPIC.generated\",\"fields\":[{\"name\":\"DataRecord\",\"type\":{\"name\":\"DataRecordSchema\",\"type\":\"record\",\"fields\":[{\"name\":\"id\",\"type\":\"string\"},{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"description\",\"type\":\"string\"},{\"name\":\"created_by\",\"type\":\"string\"},{\"name\":\"updated_by\",\"type\":\"string\"},{\"name\":\"created_at\",\"type\":\"string\"},{\"name\":\"updated_at\",\"type\":\"string\"},{\"name\":\"data_legitimacy\",\"type\":\"string\"},{\"name\":\"item_status\",\"type\":\"string\"},{\"name\":\"tenant_id\",\"type\":\"string\"},{\"name\":\"tags\",\"type\":\"string\"},{\"name\":\"dataset_series_id\",\"type\":\"string\"},{\"name\":\"location_id\",\"type\":\"string\"},{\"name\":\"provided_by\",\"type\":\"string\"},{\"name\":\"metadata\",\"type\":\"string\"}]}},{\"name\":\"MetadataRecord\",\"type\":{\"name\":\"MetadataRecordSchema\",\"type\":\"record\",\"fields\":[{\"name\":\"timestamp\",\"type\":\"string\"},{\"name\":\"record_type\",\"type\":\"string\"},{\"name\":\"operation\",\"type\":\"string\"},{\"name\":\"partition_key_type\",\"type\":\"string\"},{\"name\":\"schema_name\",\"type\":\"string\"},{\"name\":\"table_name\",\"type\":\"string\"},{\"name\":\"transaction_id\",\"type\":\"string\"}]}}]}","type":"AVRO","properties":{}}'

When I'm uploading this Schema via a curl command, it seems to never complete. I get the notification that it's beginning to post, but it never finishes.

Other schemas I upload work just fine. Two examples are:

TOPIC=double_nested_schema
DOUBLE_NESTED_SCHEMA='{"schema":"{\"type\":\"record\",\"name\":\"DoubleNestedSchema\",\"namespace\":\"channels.$TENANT.$NAMESPACE.$TOPIC.generated\",\"fields\":[{\"name\":\"DataRecord\",\"type\":{\"name\":\"DataRecordSchema\",\"type\":\"record\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"},{\"name\":\"IdRecord\",\"type\":{\"name\":\"IdRecordSchema\",\"type\":\"record\",\"fields\":[{\"name\":\"id\",\"type\":\"string\"}]}}]}},{\"name\":\"MetadataRecord\",\"type\":{\"name\":\"MetadataRecordSchema\",\"type\":\"record\",\"fields\":[{\"name\":\"timestamp\",\"type\":\"string\"}]}}]}","type":"AVRO","properties":{}}'

TOPIC=simplest_schema
SIMPLEST_SCHEMA='{"schema":"{\"type\":\"record\",\"name\":\"SimplestExample\",\"namespace\":\"channels.$TENANT.$NAMESPACE.$TOPIC.generated\",\"fields\":[{\"name\":\"name\",\"type\":\"string\"}]}","type":"AVRO","properties":{}}'

Things I've tried

  • As I mentioned above, I've tried the two different schemas SIMPLEST_SCHEMA and DOUBLE_NESTED_SCHEMA and they work fine
  • I've also tested running the equivalent of uploading my NESTED_SCHEMA in Postman and it works fine. Does this indicate there's something about curl that doesn't like my formatting?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

梅窗月明清似水 2025-02-13 20:31:56

fwiw,在修复单个引号后,我尝试通过此站点并将内容类型指定为application/json。当我这样做时,我收到了错误:您选择了“应用程序/JSON”内容类型,但是提供的字符串不是有效的JSON字符串。

基于此,看来您的JSON已畸形。

FWIW, After fixing the single quotes, I tried sending that problematic schema via curl on this site and specifying the content type as application/json. When I did, I received the error: You selected 'application/json' content type, but the provided string is not a valid JSON string.

Based on this, it appears that your JSON is malformed.

还如梦归 2025-02-13 20:31:56

我尝试了许多解决方案,但是我一直发现这在Postman中效果很好,但不作为Curl Command。

当我打开-erbose标题时,我看到我在这一点上被挂断了:

> Expect: 100-continue
> 
* Done waiting for 100-continue

显然,此行为是在以下方式完成的:

  • 请求是一个帖子或
  • 请求是帖子,并且数据大小大于1024字节,

您可以通过将设置为空字符串来关闭此行为。

像这样:

curl -h'期望:'

此版本的curl命令最终为我工作:

    curl --location --request POST "https://$PULSAR_HOST:$HOST_PULSAR_PORT/admin/v2/schemas/$TENANT/$NAMESPACE/$TOPIC/schema" \
        --verbose \
        --header 'Expect:' \
        --header "Authorization: Bearer $AUTHORIZATION"  \
        --insecure \
        --header "Content-Type: $content_type" \
        --data-raw $SCHEMA 2>&1 | grep "HTTP" # grep -v "Authorization"

请参阅参考:

I tried a number of solutions, but I kept finding that this worked fine in Postman but not as curl command.

When I turned on the --verbose header I saw that I was getting hung up at about this point:

> Expect: 100-continue
> 
* Done waiting for 100-continue

Evidently this behavior is done when:

  • the request is a PUT or
  • the request is a POST and the data size is larger than 1024 bytes

You can turn off this behavior by setting the Except header to an empty string.

like so:

curl -H 'Expect:'

This version of the curl command ended up working for me:

    curl --location --request POST "https://$PULSAR_HOST:$HOST_PULSAR_PORT/admin/v2/schemas/$TENANT/$NAMESPACE/$TOPIC/schema" \
        --verbose \
        --header 'Expect:' \
        --header "Authorization: Bearer $AUTHORIZATION"  \
        --insecure \
        --header "Content-Type: $content_type" \
        --data-raw $SCHEMA 2>&1 | grep "HTTP" # grep -v "Authorization"

See references:

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文