官方文档似乎缺少使用这些输出绑定的文档,https://docs.microsoft.com/en-us/azure/azure-functions/functions-reference-java没有提供使用这些绑定的任何示例。
有没有人有运气使用这些?我希望实现类似的目标:
@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
}
答案 0 :(得分:2)
<强> @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;
}
AzureWebJobsStorage
已在local.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)
希望它对你有所帮助。
答案 1 :(得分:1)
经过大量调查后发现,你必须拥有一个名为“RowKey”的属性
大写R 非常重要 以下是工作实现的示例。
@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)