MSMQ 수신 위치 만들기 및 프로그래밍 방식으로 포트 보내기
이 항목에서는 WMI를 사용하여 MSMQ 어댑터 위치 또는 포트를 만드는 방법을 설명합니다.
자세한 내용은 UI 지침 및 개발자 API 네임스페이스 참조에서 WMI를 사용하여 날짜/시간 일정 구성을 사용하여 수신 위치 만들기를 참조하세요.
속성 값 설정
포트 또는 위치를 만드는 프로세스는 항상 동일합니다.
올바른 유형의 개체를 만듭니다.
개체에 속성 값을 설정합니다.
개체 값을 데이터베이스에 커밋합니다.
모든 어댑터에는 HostName과 같은 특정 속성이 공통적으로 있습니다. 이러한 공통 속성은 직접 개체에 할당하여 설정합니다. 다음 C# 코드는 일반적인 경우를 보여 줍니다.
objReceiveLocation["HostName"] = "BizTalkServerApplication";
일부 어댑터가 공유하지 않는 속성에 값을 할당합니다. 문자열로 XML 문서를 만들고 그 문자열을 CustomCfg 속성에 할당합니다. 다음 C# 코드는 일반적인 FILE 어댑터의 경우를 보여 줍니다.
objReceiveLocation["CustomCfg"] =
@"<CustomProps>"
+ @"<BatchSize>20</BatchSize>"
+ @"<FileMask>*.xml</FileMask>"
+ @"<FileNetFailRetryCount>5</FileNetFailRetryCount>"
+ @"<FileNetFailRetryInt>5</FileNetFailRetryInt>"
+ @"</CustomProps>";
CustomProps 요소에 있는 태그의 이름은 어댑터가 속성에 사용하는 내부 이름입니다.
MSMQ 어댑터의 CustomProps 태그 안에는 단일 태그로 AdapterConfig가 있습니다. AdapterConfig 태그에는 Config 태그에 싸인 사용자 지정 속성 값의 XML 태그 문자열이 포함되어 있습니다. 그러나 태그는 인코딩됩니다. ""는 "<<"를 대체하고 ">"는 ">"를 대체합니다. 예를 들어 MSMQ 속성의 어댑터 하위 집합에 대한 XML은 다음과 같이 표시될 수 있습니다.
<Config>
<batchSize>40</batchSize>
</Config>
vt 특성은 사용되지 않습니다. CustomCfg 속성에 할당된 문자열은 인코딩 후 다음과 같이 표시됩니다.
<CustomProps><AdapterConfig vt="8"><Config><batchSize>40</batchSize></Config></AdapterConfig></CustomProps>
사용자 지정 속성 이름
다음 표에서는 MSMQ 어댑터 사용자 지정 속성 보내기 의 내부 이름을 설명합니다.
사용자 지정 속성 이름 보내기 | 표시 이름 |
---|---|
acknowledgeType | 승인 유형 |
administrationQueue | 관리 큐 |
인증서(certificate) | 인증서 지문 |
encryptionAlgorithm | 암호화 알고리즘 |
maximumMessageSize | 최대 메시지 크기(KB) |
password | 암호 |
priority | 메시지 우선 순위 |
queue | 대상 큐 |
recoverable | Recoverable |
segmentationSupport | 조각화 지원 |
sendBatchSize | Batch 크기 |
sendQueueName | 대상 큐 |
timeOut | 제한 시간 |
timeOutUnits | 시간 제한 단위 |
transactional | 트랜잭션 |
useAuthentication | 인증 사용 |
useDeadLetterQueue | 배달 못한 편지 큐 사용 |
useJournalQueue | 저널 큐 사용 |
userName | 사용자 이름 |
다음 표에서는 MSMQ 어댑터 사용자 지정 속성 수신 의 내부 이름을 설명합니다.
Receive 사용자 지정 속성 이름 | 표시 이름 |
---|---|
batchSize | Batch 크기 |
암호 | 암호 |
큐 | 큐 |
serialProcessing | Serial Processing |
트랜잭션 | 트랜잭션 |
userName | 사용자 이름 |
샘플 코드
다음 C# 프로그램은 MSMQ 어댑터의 단일 수신 위치를 만듭니다. 여기서는 수신 포트인 ReceivePort1이 있으며 도우미 함수를 사용하여 사용자 지정 속성을 인코딩하고 형식을 지정하는 경우를 가정합니다.
using System;
using System.Management;
using System.Text;
namespace CreateReceive
{
///
/// Program to create a receive location.
///
class CreateReceive
{
/// The main entry point for the application.
[STAThread]
static void Main()
{
// Custom properties & values
string cfg =
@"<queue>FORMATNAME:DIRECT=OS:MYMACHINE02\PRIVATE$\QUEUE2</queue>"
+ @"<batchSize>40</batchSize>"
+ @"<transactional>true</transactional>"
+ @"<serialProcessing>false</serialProcessing>";
CreateReceiveLocation (
"Code Created Location",
"ReceivePort1",
"MSMQ",
"BizTalkServerApplication",
EncodeCustomProps(cfg), // Encode the custom props
"Microsoft.BizTalk.DefaultPipelines.PassThruReceive,"
+ " Microsoft.BizTalk.DefaultPipelines,"
+ " Version=3.0.1.0, Culture=neutral,"
+ " PublicKeyToken=31bf3856ad364e35",
@"FORMATNAME:DIRECT=OS:MYMACHINE\PRIVATE$\QUEUE2"
);
}
static string EncodeCustomProps (string cp) {
// Enclose the properties and values in a Config> tag.
StringBuilder tmp = new StringBuilder( @"<Config>" + cp + @"</Config>");
// Encode the string
tmp = tmp.Replace("<","<");
tmp = tmp.Replace(">",">");
return (
// Enclose the encoded string with necessary tags
"<CustomProps><AdapterConfig vt=\"8\">"
+ tmp.ToString()
+ "</AdapterConfig></CustomProps>");
}
static void CreateReceiveLocation (
string name, // Location name
string port, // Receive port, already exists
string adapterName, // The transport type
string hostName, // BTS host
string customCfg, // Encoded custom properties
string pipeline, // Full specification of pipeline
string inboundTransport)// Inbound transport url
{
try
{
// Create options to store options in management object
PutOptions options = new PutOptions();
options.Type = PutType.CreateOnly;
// Create a management object
// Get the class
ManagementClass objReceiveLocationClass =
new ManagementClass(
"root\\MicrosoftBizTalkServer",
"MSBTS_ReceiveLocation",
null);
// Create an instance of the member of the class
ManagementObject objReceiveLocation =
objReceiveLocationClass.CreateInstance();
// Fill in the properties
objReceiveLocation["Name"] = name;
objReceiveLocation["ReceivePortName"] = port;
objReceiveLocation["AdapterName"] = adapterName;
objReceiveLocation["HostName"] = hostName;
objReceiveLocation["PipelineName"] = pipeline;
objReceiveLocation["CustomCfg"] = customCfg;
objReceiveLocation["IsDisabled"] = true;
objReceiveLocation["InBoundTransportURL"] = inboundTransport;
// Put the options -- creates the receive location
objReceiveLocation.Put(options);
}
catch (Exception excep)
{
System.Console.WriteLine("Create Receive Location ({0}) failed - {1}",
name, excep.Message);
}
}
}
}