다음을 통해 공유


솔루션 계측: 단계별 API 사용

이 항목에서는 주요 BAM API 클래스를 사용하여 애플리케이션을 계측하는 방법에 대해 설명합니다. 다음 코드 조각에서는 상수와 애플리케이션을 계측하는 데 필요한 최소 코드를 사용하여 샘플 코드를 단순화했습니다.

다음 코드 조각은 새 Microsoft.BizTalk.Bam.EventObservation.EventStream 개체, 구체적으로 Microsoft.BizTalk.Bam.EventObservation.DirectEventStream을 만드는 방법을 나타냅니다. 이 코드에서 첫 번째 매개 변수는 BAM 기본 가져오기 데이터베이스의 데이터 저장소에 대한 연결 문자열을 지정하고 두 번째 매개 변수는 데이터 저장소에 이벤트가 기록되는 빈도를 지정합니다.

참고

BAM은 SQL Server 데이터 저장소에 대한 연결만 지원합니다. 예로 나온 연결 문자열은 연결을 설정하는 데 필요한 최소 연결 문자열을 나타냅니다. 실제 구성에서는 연결 문자열에 추가 매개 변수를 지정해야 할 수도 있습니다.

FlushThreshold 값이 0이면 이벤트가 자동으로 기록되지 않기 때문에 Flush 메서드를 호출하여 이벤트를 기록해야 합니다. 값이 1이면 각 이벤트가 발생할 때 이벤트가 기록됩니다. 값이 1보다 큰 경우에는 지정된 수만큼 이벤트가 누적되어 일괄 처리가 발생할 때 이벤트가 기록됩니다. 1보다 큰 값을 사용하면 성능을 개선하는 데 도움이 됩니다.

// Specify the DES connection string.  
const string connBAMPIT =  
   "Integrated Security=SSPI;server=.;database=BAMPrimaryImport";  
// Write the activity update data on every call.  
int flushThreshold = 1;  
// Create a DES instance  
EventStream es =   
   new DirectEventStream(connBAMPIT, flushThreshold);  

[Microsoft.BizTalk.Bam.EventObservation.EventStream]/dotnet/api/microsoft.biztalk.bam.eventobservation.eventstream) 개체가 만들어지면 작업을 시작하고 수집된 마일스톤 및 데이터로 활동 테이블 업데이트를 시작할 수 있습니다. BAM 활동이 배포되면 BAM 기본 가져오기 데이터베이스에 5개의 테이블이 만들어집니다. 개발 프로세스에 대한 자세한 내용은 Overview of the BAM Development Process를 참조하십시오.

Microsoft.BizTalk.Bam.EventObservation.EventStream.BeginActivity 메서드를 호출하면 bam_ PurchaseOrder_Activity 테이블에 레코드가 추가됩니다. 첫 번째 매개 변수에는 업데이트되는 활동의 이름이 포함되고 두 번째 매개 변수에는 현재 활동 인스턴스의 식별자가 포함됩니다. 식별자로 아무 문자열이나 사용할 수 있지만, 해당 활동에 대한 레코드 집합에서 고유한 문자열이어야 합니다.

현재까지는 레코드에 데이터가 들어 있지 않습니다. Microsoft.BizTalk.Bam.EventObservation.EventStream.UpdateActivity 메서드는 캡처된 이벤트 데이터로 레코드를 업데이트합니다. 그런 다음에는 사용자가 활동과 활동 인스턴스 식별자를 다시 한번 지정합니다. 활동에서 정의한 데이터 항목 및 중요 시점의 이름 값 쌍을 Microsoft.BizTalk.Bam.EventObservation.EventStream.UpdateActivity 메서드에 전달합니다. 예를 들어 활동에 MS_Received라는 마일스톤이 정의된 경우 활동이 배포되면 bam_ PurchaseOrder_Activity table 테이블에 이 마일스톤에 대한 열이 만들어집니다. Microsoft.BizTalk.Bam.EventObservation.EventStream.UpdateActivity 메서드 호출에서 MS_Received 및 DateTime.UtcNow로 구성된 이름 값 쌍을 지정하여 구매 주문이 수신된 날짜로 활동을 업데이트합니다.

// When a purchase order is received, you call the  
// BeginActivity method in the receive application.  
// You can then capture the event data by calling   
// the UpdateActivity method.  
es.BeginActivity ("PurchaseOrder", "PO123");  
es.UpdateActivity ("PurchaseOrder", "PO123",  
                    "MS_Received", DateTime.UtcNow,   
                    "T_Customer", "Joe");  

이 샘플에서는 계속해서 두 번째 활동을 수행합니다. Continuation에 대한 자세한 내용은 Activity Continuation을 참조하십시오.

계측한 다른 애플리케이션에서 PurchaseOrder 활동을 업데이트하도록 설정하려면 Microsoft.BizTalk.Bam.EventObservation.EventStream.EnableContinuation 메서드 호출을 포함합니다. 이 호출은 다른 애플리케이션에서 업데이트할 활동, 추적되는 활동 인스턴스의 식별자 및 다른 애플리케이션에서 활동을 업데이트하는 데 사용할 Continuation 토큰을 지정합니다. Continuation의 상태를 추적하는 레코드가 bam_PurchaseOrder_continuations 테이블에 기록됩니다. 활동이 다른 프로세스로 이어지면 각 Microsoft.BizTalk.Bam.EventObservation.EventStream.EnableContinuation 메서드 호출에 대한 레코드가 고유한 Continuation 토큰과 함께 기록됩니다.

중요

Continuation 시나리오의 모든 코드 세그먼트에는 자체 Microsoft.BizTalk.Bam.EventObservation.EventStream.EndActivity 메서드 호출이 있어야 합니다. 이 호출이 실패하면 현수/분리된 활동 레코드가 만들어집니다.

그러나 첫 번째 세그먼트(실제 활동 ID 사용)만 Microsoft.BizTalk.Bam.EventObservation.EventStream.BeginActivity 메서드가 있습니다. 다른 모든 세그먼트(자체적인 고유한 토큰 ID 사용)는 Microsoft.BizTalk.Bam.EventObservation.EventStream.BeginActivity 메서드를 호출해야 합니다.

Microsoft.BizTalk.Bam.EventObservation.EventStream.EnableContinuation 메서드가 호출된 후 다른 구성 요소가 활동 ID 대신 Continuation 토큰을 지정하는 Microsoft.BizTalk.Bam.EventObservation.EventStream.UpdateActivity 를 사용하여 구매 주문 활동을 업데이트할 수 있습니다. 다른 구성 요소가 작업을 완료하면 각 구성 요소는 연속 토큰을 사용하여 Microsoft.BizTalk.Bam.EventObservation.EventStream.EndActivity 를 호출하여 BAM 인프라에 더 이상 이벤트가 예상되지 않음을 알려야 합니다.

중요

Microsoft.BizTalk.Bam.EventObservation.EventStream.EnableContinuation 메서드를 호출한 후 활동이 진행되고 있는 프로세스에서 Continuation 토큰과 함께 Microsoft.BizTalk.Bam.EventObservation.EventStream.EndActivity 메서드를 호출하지 않으면 활동이 분리될 수 있습니다.

// Continue the activity to the next process that has been  
// instrumented to handle the continuation.  
es.EnableContinuation("PurchaseOrder", “PO123”, “AP123”);  

마지막으로 활동 이름 및 활동 식별자를 지정하는 Microsoft.BizTalk.Bam.EventObservation.EventStream.EndActivity 메서드를 호출하여 활동이 종료됩니다. 완료되지 않은 Continuation이 하나도 없으면 활동이 bam_PurchaseOrder _completed 테이블로 이동됩니다. Continuation 활동이 완료되지 않으면 활동이 분리될 있습니다.

// Activity from this segment (PO submission) is completed  
es.EndActivity("PurchaseOrder", “PO123”);  

활동이 별도의 프로세스로 진행되면 Microsoft.BizTalk.Bam.EventObservation.EventStream.EnableContinuation 메서드 호출에 선언된 활동 이름 및 Continuation 토큰을 지정하는 Microsoft.BizTalk.Bam.EventObservation.EventStream.UpdateActivity 를 호출하여 활동 테이블을 업데이트하기 위해 애플리케이션이 계측됩니다.

참고

지속되는 활동을 처리하는 프로세스는 Microsoft.BizTalk.Bam.EventObservation.EventStream.BeginActivity 메서드를 호출하지 않습니다. Microsoft.BizTalk.Bam.EventObservation.EventStream.BeginActivity 메서드는 BAM 기본 가져오기 데이터베이스에서 테이블을 만들어 활동 인스턴스를 만듭니다. 활동이 이어지는 다음 프로세스에서 기존 활동의 인스턴스를 업데이트합니다.

// update when the order is approved  
es.UpdateActivity ("PurchaseOrder", “AP123”, "MS_Approved",  
                    DateTime.UtcNow, "T_Product", "Widget");  
  
// update when the product is ready for shipment  
es.UpdateActivity ("PurchaseOrder", “AP123”,  
                   "MS_Ready", DateTime.UtcNow);  

이 샘플에 대한 워크플로의 한 부분에 해당하는 이 코드에서는 특정 유형의 참조인 관련 활동을 지정합니다. 관련 활동을 지정하면 기본 활동과 BAM 포털에서 활동을 보는 사용자에게 표시할 다른 활동 간에 링크를 만들 수 있습니다.

Microsoft.BizTalk.Bam.EventObservation.EventStream.AddRelatedActivity 메서드 호출이 활동을 연결하는 bam_ PurchaseOrder_ActiveRelationships에 레코드를 기록합니다.

// These are shipped in two shipments.  
// Relates the current purchase order   
// instance to two shippings.  
// Note: only one direction  
es.AddRelatedActivity ("PurchaseOrder", “AP123”,  
                       "Shipping", “UPS101”);  
es.AddRelatedActivity ("PurchaseOrder", “AP123”,  
                       "Shipping", “UPS102”);  

지속되는 활동을 종료하려면 종료하려는 Continuation의 Continuation 토큰을 지정하는 Microsoft.BizTalk.Bam.EventObservation.EventStream.EndActivity 메서드를 호출합니다. 완료되지 않은 Continuation이 하나도 없으면 구매 주문 활동이 완료된 테이블로 이동됩니다.

// Activity from this segment (ApprovalProcess) is completed  
es.EndActivity("PurchaseOrder", “AP123”);  

전체 코드 샘플

//---------------------------------------------------------------------  
// File:BAMMinimalSample.cs  
//   
// Summary: Demonstrates how to instrument an application   
//using BAM APIs to track useful information.  
//  
// Sample: BAM Api Sample  
//  
//---------------------------------------------------------------------  
// This file is part of the Microsoft BizTalk Server SDK  
//  
// Copyright (c) Microsoft Corporation. All rights reserved.  
//  
// This source code is intended only as a supplement to Microsoft   
// BizTalk Server release and/or on-line documentation. See   
// these other materials for detailed information regarding Microsoft // code samples.  
//  
// THIS CODE AND INFORMATION ARE PROVIDED "AS IS" WITHOUT WARRANTY OF  
// ANY KIND, WHETHER EXPRESSED OR IMPLIED, INCLUDING BUT NOT LIMITED TO // THE IMPLIED WARRANTIES OF MERCHANTABILITY AND/OR FITNESS FOR A   
// PARTICULAR PURPOSE.  
//---------------------------------------------------------------------  
// This sample requires that you add the     
// Microsoft.BizTalk.Bam.EventObservation.dll to the   
// references in the Visual Studio Solution.  
  
using System;  
using System.Text;  
using Microsoft.BizTalk.Bam.EventObservation;  
  
namespace EventStreamSample  
{  
  
    static void Main(string[] args)  
    {  
        //   
  // The following code would appear in a purchase order  
   // receipt application.  
        //  
  
        // Specify the DES connection string.  
        const string connBAMPIT =  
            "Integrated Security=SSPI;server=.;database=BAMPrimaryImport";  
  
        // Write the activity update data on every call.  
        int flushThreshold = 1;  
  
        // Create an instance of the DirectEventStream.  
        EventStream es =   
               new DirectEventStream(connBAMPIT, flushThreshold);  
  
        // When a purchase order is received, you call the  
       // BeginActivity method in the receive application.  
  // You can then capture the event data by calling   
        // the UpdateActivity method.  
        es.BeginActivity ("PurchaseOrder", "PO123");  
        es.UpdateActivity ("PurchaseOrder", "PO123",  
                    "MS_Received", DateTime.UtcNow,   
                    "T_Customer", "Joe");  
  
   // Continue the activity to the next process that has been  
   // instrumented to handle the continuation.  
        es.EnableContinuation("PurchaseOrder", “PO123”, “AP123”);  
  
        // Activity from this segment (PO submission) is completed  
        // end activity is synonymous to IsCompleted = 1  
        es.EndActivity("PurchaseOrder", “PO123”);  
  
        //  
        // The following code would typically appear in a separate   
        // application that monitors the approval process  
        // (ApprovalProcess.exe)  
        //  
  
        // update when the order is approved  
        es.UpdateActivity ("PurchaseOrder", “AP123”, "MS_Approved",  
                            DateTime.UtcNow, "T_Product", "Widget");  
  
        // update when the product is ready for shipment  
        es.UpdateActivity ("PurchaseOrder", “AP123”,  
                            "MS_Ready", DateTime.UtcNow);  
  
        // These are shipped in two shipments.  
        // Relates the current purchase order  
        // instance to two shippings.  
        // Note: only one direction  
        es.AddRelatedActivity ("PurchaseOrder", “AP123”,  
                                "Shipping", “UPS101”);  
        es.AddRelatedActivity ("PurchaseOrder", “AP123”,  
                                "Shipping", “UPS102”);  
  
        // Activity from this segment (ApprovalProcess) is completed  
        es.EndActivity("PurchaseOrder", “AP123”);  
  
        // In another Shipping application, two shipments with  
            ID’s UPS101 and UPS102 will be created.  
    }  
}  

참고 항목

이벤트 스트림을 사용하여 BAM 활동 구현