Trigger Azure Data Factory Pipeline from Logic App w/ Parameter

前端 未结 3 1953
终归单人心
终归单人心 2020-12-18 14:06

Let me preface that I\'m a noob to Logic Apps and Data Factory. Anyways, I\'m currently working on an integration and one part of it is that I need to trigger a pipeline in

3条回答
  •  情话喂你
    2020-12-18 14:58

    as I said in the comment I create a workaround with azure functions. Azure functions and logic app work well together. On this link you can see how to create and manage pipelines with .net https://docs.microsoft.com/en-us/azure/data-factory/quickstart-create-data-factory-dot-net

    If you already have ADF and pipeline, you just want to run it (with pipelines) then you can just

    Dictionary parameters = new Dictionary
           {
               {"BoxSerialNumbers", req.BoxSerialNumbers},
               {"StartDate", req.StartDate },
               {"EndDate",req.EndDate },
               {"Recipient", req.Recipient }
           };//this is how you add initialaze parameters
    
            var client = Authenticate(); //Authentication with azure
            log.Info("Creating.");
            CreateRunResponse runResponse = client.Pipelines.CreateRun(resourceGroup, dataFactoryName, "pipeline1", parameters);//run pipeline, you can do this async (it's better)
            log.Info("Created.");
            var response = new HttpResponseMessage();
            if (client.PipelineRuns.Get(resourceGroup, dataFactoryName, runResponse.RunId).Status.Equals("InProgress"))
            {
                response = new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new StringContent(runResponse.RunId, Encoding.UTF8)
                };
            }
            else
            {
                response = new HttpResponseMessage(HttpStatusCode.BadRequest)
                {
                    Content = new StringContent("Pipeline didn't started", Encoding.UTF8)//just some validation for function
                };
            }
            return response;                                               
    
    
        public static DataFactoryManagementClient Authenticate()
        {
            var context = new AuthenticationContext("https://login.windows.net/" + tenantID);
            ClientCredential cc = new ClientCredential(applicationID, authenticationKey);
            AuthenticationResult result = context.AcquireTokenAsync("https://management.azure.com/", cc).Result;
            ServiceClientCredentials cred = new TokenCredentials(result.AccessToken);
            return new DataFactoryManagementClient(cred) { SubscriptionId = subscriptionID };
        }
    

    So in the request, you can pass your parameters from a logic app, with runId you can check status. Then in logic app just simple HTTP request to call this function. Hope this help someone.

提交回复
热议问题