我正在尝试使用 Cosmos 触发器(在 c# 中)创建一个 Azure 函数,用于监视对 CosmosDB 的更改,这看起来相对简单,并且我已经成功地做到了这一点,没有遇到任何麻烦,我有一个 Azure 函数,可以将数据库的更改记录到日志控制台。我正在尝试编写一个输出绑定以将更改发送到 Azure SignalR,但是当我尝试此操作时,我遇到了隔离进程不支持执行此操作所需的程序集。有谁有一个非常简单的 c# Azure Cosmos 触发器函数示例,该函数将检测到的 Cosmos DB 更改发送到 Azure SignalR 服务,以便我可以订阅此示例并将这些更改报告给客户端应用程序。任何帮助将不胜感激。
我在网上找到的我想要做的代码(这只是一个测试函数)如下:
[Function("CosmosTriggerSigR")]
public void Run([CosmosDBTrigger(
databaseName: "test",
collectionName: "testCollection",
ConnectionStringSetting = "cosmos_DOCUMENTDB",
LeaseCollectionName = "leases")]
IReadOnlyList<MyDocument> input,
[SignalR(HubName = "events", ConnectionStringSetting = "SignalRConnectionString")]
IAsyncCollector<SignalRMessage> signalRMessages,
ILogger log)
{
if (input != null && input.Count > 0)
{
_logger.LogInformation("Documents modified: " + input.Count);
_logger.LogInformation("First document Id: " + input[0].Id);
}
}
当尝试部署它时,它显示此错误:
C:\Users\CosmosSigr1204\CosmosTriggerSigR.cs(29, 14): 错误 AZFW0001: 属性“SignalRAttribute”是一个 WebJobs 属性,.NET Worker(隔离进程)不支持该属性。 [C:\Users\CosmosSigr1204\CosmosSigr1204.csproj]
终端进程“C:\Program Files\dotnet\dotnet.exe 'publish', '--configuration', 'Release', '/property:GenerateFullPaths=true', '/consoleloggerparameters:NoSummary'” 终止并退出代码: 1.
我对 Azure SignalR 几乎一无所知,并且我正在尝试蒙混过关,如果上面的代码不是我正在尝试的内容,我深表歉意去做。
I'm trying to create a Azure function with a Cosmos Trigger (in c#) that monitors changes to a CosmosDB, this seems relatively simple and I have managed to do this without trouble, I have an Azure function that logs changes to the DB to the log console. I am trying to write an output binding to send the changes to Azure SignalR but when I try this, I am met with isolated process doesn't support the assemblies required to do this. Does anyone have a very simple example of a c# Azure Cosmos Trigger function that sends the changes detected to a Cosmos DB to an Azure SignalR servicee so I can subscribe to this and report these to a client app. Any help would be greatly appreciated.
The code I found on the web for what I want to do (this is just a test function) is below:
[Function("CosmosTriggerSigR")]
public void Run([CosmosDBTrigger(
databaseName: "test",
collectionName: "testCollection",
ConnectionStringSetting = "cosmos_DOCUMENTDB",
LeaseCollectionName = "leases")]
IReadOnlyList<MyDocument> input,
[SignalR(HubName = "events", ConnectionStringSetting = "SignalRConnectionString")]
IAsyncCollector<SignalRMessage> signalRMessages,
ILogger log)
{
if (input != null && input.Count > 0)
{
_logger.LogInformation("Documents modified: " + input.Count);
_logger.LogInformation("First document Id: " + input[0].Id);
}
}
and the when trying to deploy it, it shows this error:
C:\Users\CosmosSigr1204\CosmosTriggerSigR.cs(29,14): error AZFW0001: The attribute 'SignalRAttribute' is a WebJobs attribute and not supported in the .NET Worker (Isolated Process). [C:\Users\CosmosSigr1204\CosmosSigr1204.csproj]
The terminal process "C:\Program Files\dotnet\dotnet.exe 'publish', '--configuration', 'Release', '/property:GenerateFullPaths=true', '/consoleloggerparameters:NoSummary'" terminated with exit code: 1.
I know pretty much nothing about Azure SignalR and I'm trying to muddle through so apologies if the code above isn't what it should be for what I'm trying to do.
发布评论
评论(1)
这是一个完整的解决方案,它使用您指定的服务组合: https://github.com/github.com/serverless/serverlessazureffriday < /a>
特别是此功能: which ties the
CosmosDBTrigger
andSignalR
output like so:In this case, the code将发送1个SignalR消息,其中包含触发器上收到的所有文档,您可以选择每个触发文档发送1个SignalR消息,这取决于您的应用程序设计。
在此解决方案的情况下,客户端应用程序(浏览器)使用JS库连接到SignalR Hub,并接收包含所有COSMOS DB文档的SignalR消息并消耗数组(参考):
其中
console
只是符合target
的名称。Here is a full solution that uses the combination of services you specify: https://github.com/ealsur/serverlessazurefriday
Particularly this Function: https://github.com/ealsur/serverlessazurefriday/blob/master/src/DistributedDashboard/NotificationsTrigger.cs which ties the
CosmosDBTrigger
andSignalR
output like so:In this case, the code will send 1 SignalR message containing all the documents that were received on the Trigger, you could opt to send 1 SignalR message per Trigger document, that is up to your application design.
In the case of this solution, the client application (browser) connects to the SignalR hub using the JS library and receives the SignalR message that contain all the Cosmos DB documents and consumes the array (reference https://github.com/ealsur/serverlessazurefriday/blob/master/src/ClientApp/scripts/site.js):
Where
console
is just the name that matches theTarget
on the SignalR output message.