gpt4 book ai didi

java - 如何在java azure函数中使用@BlobOutput或@TableOutput

转载 作者:行者123 更新时间:2023-12-01 19:56:53 25 4
gpt4 key购买 nike

官方文档似乎缺少有关使用这些输出绑定(bind)的文档,https://learn.microsoft.com/en-us/azure/azure-functions/functions-reference-java没有给出任何使用这些绑定(bind)的示例。

有人用过这些吗?我希望实现类似的目标:

@FunctionName("consumeNodeInfo")
fun consumeNodeInfoFromQueue(@QueueTrigger(queueName = "nodeinfos", connection = "AzureWebJobsStorage", name = "nodeinfos", dataType = "binary") addedNodeInfo: ByteArray,
@TableOutput(name = "networkmap", tableName = "networkmap") table: OutputBinding<SignedNodeInfoRow>) {
table.value = SignedNodeInfoRow(addedNodeInfo)
}

open class SignedNodeInfoRow(val signedNodeInfo: ByteArray) {
val rowKey = signedNodeInfo.deserialize<SignedNodeInfo>().raw.hash
}

最佳答案

@BlobOutput:

请引用我的示例代码:

@FunctionName("blob")
public String functionHandler(
@QueueTrigger(name = "myQueueItem", queueName = "walkthrough", connection = "AzureWebJobsStorage") String queue,
@BlobOutput(name = "blob", connection = "AzureWebJobsStorage" , path = "samples-java/2.txt") OutputBinding<String> blob) {

blob.setValue(queue);
return queue;
}

AzureWebJobsStoragelocal.settings.json

中配置
{
"IsEncrypted": false,
"Values": {
"AzureWebJobsStorage": "<your connection string>",
"AzureWebJobsDashboard": ""
}
}

function.json:

{
"scriptFile" : "..\\fabrikam-functions-1.0-SNAPSHOT.jar",
"entryPoint" : "com.fabrikam.functions.Function.functionHandler",
"bindings" : [ {
"type" : "queueTrigger",
"name" : "myQueueItem",
"direction" : "in",
"connection" : "AzureWebJobsStorage",
"queueName" : "walkthrough"
}, {
"type" : "blob",
"name" : "blob",
"direction" : "out",
"connection" : "AzureWebJobsStorage",
"path" : "samples-java/2.txt"
} ],
"disabled" : false
}
<小时/>

@TableOutput:

仅供总结:

我们可以从此 doc 检查 function.json 中的属性。永远不要忘记名为 RowKey 的属性。

示例代码:

@FunctionName("consumeNodeInfo")
fun consumeNodeInfoFromQueue(@QueueTrigger(queueName = "nodeinfos", connection = "AzureWebJobsStorage", name = "nodeinfos", dataType = "binary") addedNodeInfo: ByteArray,
@TableOutput(name = "networkmap", tableName = "networkmap", connection = "AzureWebJobsStorage", partitionKey = "nodeInfos") table: OutputBinding<SignedNodeInfoRow>) {
val nodeInfo = addedNodeInfo.deserialize<SignedNodeInfo>()
table.value = SignedNodeInfoRow(nodeInfo.raw.hash.toString(), addedNodeInfo.toBase58())
}

data class SignedNodeInfoRow(val RowKey: String, val arrayAsBase58String: String)

希望对您有帮助。

关于java - 如何在java azure函数中使用@BlobOutput或@TableOutput,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/49325678/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com