C# Azure函数-将事件从eventhub写入Blob存储
我正在尝试将事件从事件中心移动到Blob存储。我在eventhub上创建了触发器,以便在消息到达eventhub时触发。此外,我还将输出配置为Blob存储。现在,我在函数中所做的是:C# Azure函数-将事件从eventhub写入Blob存储,c#,azure-functions,azure-eventhub,azure-blob-storage,C#,Azure Functions,Azure Eventhub,Azure Blob Storage,我正在尝试将事件从事件中心移动到Blob存储。我在eventhub上创建了触发器,以便在消息到达eventhub时触发。此外,我还将输出配置为Blob存储。现在,我在函数中所做的是: public static void Run(string myEventHubMessage, out string outputBlob, TraceWriter log) { outputBlob = myEventHubMessage; } 这将在Ouputs配置中提到的容器中创建一个新blob。
public static void Run(string myEventHubMessage, out string outputBlob, TraceWriter log)
{
outputBlob = myEventHubMessage;
}
这将在Ouputs配置中提到的容器中创建一个新blob。但是,我想基于eventhub消息中的数据创建一个具有指定名称的blob,并需要在将数据保存到Azure blob时设置内容类型和其他元数据。有人能帮我怎么做吗
问候,
John配置输出绑定有几种可能性 如果需要基于事件中心消息属性设置Blob路径,可以声明强类型消息
public class MyEvent
{
public string SomeName { get; set; }
// more properties
}
然后以声明方式将其绑定到blob路径,例如
{
"type": "blob",
"name": "outputBlob",
"path": "mycontainer/{SomeName}.json",
"connection": "...",
"direction": "out"
},
并相应地修改函数
public static void Run(MyEvent myEventHubMessage, out MyEvent outputBlob)
{
outputBlob = myEventHubMessage;
}
如果需要更高级的计算来确定输出路径,可以从function.json
中删除声明性输出绑定,并使用命令式绑定:
public static async Task Run(string myEventHubMessage, Binder binder)
{
var path = ...;
using (var writer = binder.Bind<TextWriter>(new BlobAttribute(path)))
{
writer.Write(myEventHubMessage);
}
}
公共静态异步任务运行(字符串myEventHubMessage,Binder)
{
var路径=。。。;
使用(var writer=binder.Bind(新的BlobatAttribute(路径)))
{
writer.Write(myEventHubMessage);
}
}
如果需要设置Blob的更多属性,请绑定到ICollector
var collector=binder.Bind(新的BlobatAttribute(路径));
Add(新的CloudBlockBlob{…});
您应该使用所有这些选项来确定哪个场景适合您。有几种可能配置输出绑定 如果需要基于事件中心消息属性设置Blob路径,可以声明强类型消息
public class MyEvent
{
public string SomeName { get; set; }
// more properties
}
然后以声明方式将其绑定到blob路径,例如
{
"type": "blob",
"name": "outputBlob",
"path": "mycontainer/{SomeName}.json",
"connection": "...",
"direction": "out"
},
并相应地修改函数
public static void Run(MyEvent myEventHubMessage, out MyEvent outputBlob)
{
outputBlob = myEventHubMessage;
}
如果需要更高级的计算来确定输出路径,可以从function.json
中删除声明性输出绑定,并使用命令式绑定:
public static async Task Run(string myEventHubMessage, Binder binder)
{
var path = ...;
using (var writer = binder.Bind<TextWriter>(new BlobAttribute(path)))
{
writer.Write(myEventHubMessage);
}
}
公共静态异步任务运行(字符串myEventHubMessage,Binder)
{
var路径=。。。;
使用(var writer=binder.Bind(新的BlobatAttribute(路径)))
{
writer.Write(myEventHubMessage);
}
}
如果需要设置Blob的更多属性,请绑定到ICollector
var collector=binder.Bind(新的BlobatAttribute(路径));
Add(新的CloudBlockBlob{…});
您应该使用所有这些选项来确定哪个场景适合您。您可能不再需要这样做了。
事件中心现在支持从管道到blob存储的开箱即用 您可能不再需要这样做了。 事件中心现在支持从管道到blob存储的开箱即用