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

标签 java azure-functions

官方文档似乎缺少有关使用这些输出绑定(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/

相关文章:

java - JCombobox 改变另一个 JCombobox

java - 使用 JAXB 的具有属性和内容的 XML 元素

java - 我的method.add(int)不会将用户输入添加到我的数组中

azure - 在逻辑应用程序和 Azure 应用程序功能之间共享应用程序服务计划

javascript - 您可以从函数绑定(bind)中读取连接字符串吗?

c# - 在 using 指令 ​​ "using Accord.Video.FFMPEG"中,命名空间中不存在 FFMPEG

java 泛型扩展和列表

java - 为什么在我的 IDE 中找不到 javafx.mail.jar Java 库?

azure - 如何使用 Azure Functions 代替 WebJobs?

azure - 尽管捕获异常,但仍发生 ScriptHost 错误