2

DocumentDB에 쓸 때 트리거 할 트리거를 DocumentDB로 지정할 수 있습니까?Azure 함수 및 DocumentDB 트리거

나는 서비스 버스의 큐 JSON 메시지를 가져와과 같이 DocumentDB로두고 푸른 기능을 가지고 :

using System; 
using System.Threading.Tasks; 

public static string Run(string myQueueItem, TraceWriter log) 
{ 
    log.Info($"C# ServiceBus queue trigger function processed message: {myQueueItem}"); 

    return myQueueItem; 
} 

가 서비스 버스 큐에 추가로이 데이터베이스에 새 문서를 삽입, 그러나 DocumentDB를 추가하고 첨부 파일을 추가 할 때이를 처리하려면 DocumentDB가 필요합니다. 현재의 설정에서는이 작업을 수행 할 수 없으며 DocumentDB에게 트리거를 발생 시키라고 말하고 싶습니다. 나는 이런 식으로 뭔가를 시도

:

using System; 
using System.Threading.Tasks; 

public static string Run(string myQueueItem, TraceWriter log) 
{ 
    log.Info($"C# ServiceBus queue trigger function processed message: {myQueueItem}"); 

    return "x-ms-documentdb-post-trigger-include: addDocument\n" + myQueueItem; 
} 

그것은 일을하고 저에게이 같은 오류를 제공하지 않습니다

예외 기능을 실행하는 동안 : Functions.ServiceBusQueueTriggerCSharp1합니다. Microsoft.Azure.WebJobs.Host : 함수가 반환 된 후 _return 매개 변수를 처리하는 동안 오류가 발생했습니다. Newtonsoft.Json : 파싱하는 동안 예기치 않은 문자가 발생했습니다 : x. 경로 ''라인 0, 위치 0

내가 레코드를 추가 요청 큐를 포화 수 있으며, 데이터베이스가 수요 스파이크를 다루는, 그것을 다룰 수있을 때까지 그들은 단지 버퍼 때문에이 설정처럼, 하지만 네트워크에서 수행 할 수있는 최대한 빨리 클라이언트 시스템에서 데이터를 오프로드 할 수 있으며, 수요가 다시 떨어지면 대기열/데이터베이스 조합이 따라 잡을 수 있습니다.

답변

2

다음 코드 샘플을 참조하여 Azure 기능에서 트리거가 활성화 된 문서를 만들 수 있습니다.

using System; 
using System.Threading.Tasks; 
using Microsoft.Azure.Documents; 
using Microsoft.Azure.Documents.Client; 

public static void Run(string myQueueItem, TraceWriter log) 
{ 
    string EndpointUri = "https://{documentdb account name}.documents.azure.com:443/"; 
    string PrimaryKey = "{PrimaryKey}"; 

    DocumentClient client = new DocumentClient(new Uri(EndpointUri), PrimaryKey); 

    client.CreateDocumentAsync(UriFactory.CreateDocumentCollectionUri("{databaseid}", "{collenctionid}"), new MyChunk { MyProperty = "hello" }, 
       new RequestOptions 
       { 
        PreTriggerInclude = new List<string> { "YourTriggerName" }, 
       }).Wait(); 

    log.Info($"C# ServiceBus queue trigger function processed message: {myQueueItem}"); 
} 

public class MyChunk 
{ 
    public string MyProperty { get; set; } 
} 

: C#을 함수 기능 응용 프로그램의 파일 시스템에서, 제발 upload a project.json file to the function's folder에 Microsoft.Azure.DocumentDB NuGet 패키지를 사용합니다.

project.json 게다가

{ 
    "frameworks": { 
    "net46":{ 
     "dependencies": { 
     "Microsoft.Azure.DocumentDB": "1.13.1" 
     } 
    } 
    } 
} 

, 당신은 this article를 참조하십시오 트리거를 만드는 방법에 대한 자세한 내용은, 당신의 DocumentDB에 트리거를 만든 확인하십시오.

관련 문제