MessagePropertyFilter 클래스
어셈블리: System.Messaging(system.messaging.dll)
MessageQueue 인스턴스에 MessagePropertyFilter를 설정하면 메시지를 피킹하거나 받을 때 검색되는 속성 집합을 제어할 수 있습니다. 메시지 정보를 검색하는 MessageQueue의 인스턴스에 대해 필터가 설정됩니다. MessagePropertyFilter 부울 값 멤버를 false로 설정하면 관련된 Message 속성 정보가 MessageQueue에서 검색되는 것을 방지할 수 있습니다.
부울 값이 아닌 필터 속성은 여러 개 있습니다. 이러한 필터 속성은 Message.Body, Message.Extension 또는 Message.Label의 기본 크기를 가져오거나 설정하는 정수 값입니다.
속성 수를 제한하여 검색하면 큐에서 데이터의 전송량이 작아지므로 성능이 향상됩니다.
MessagePropertyFilter에 속성을 설정하는 경우, 메시지를 받거나 피킹하는 동안 해당 속성을 검색할지 여부만을 나타내게 됩니다. Message의 관련된 속성 값은 변경하지 않습니다.
MessagePropertyFilter 생성자는 모든 필터 속성을 기본값으로 설정하며, 부울 값에 대한 기본값은 false입니다. 정수 값 속성에 할당되는 기본값에 대한 내용은 생성자 항목을 참조하십시오.
다음 코드 예제에서는 우선 순위가 다른 두 메시지를 큐에 보내고 이후에 검색합니다.
using System; using System.Messaging; namespace MyProject { /// <summary> /// Provides a container class for the example. /// </summary> public class MyNewQueue { //************************************************** // Provides an entry point into the application. // // This example sends and receives a message from // a queue. //************************************************** public static void Main() { // Create a new instance of the class. MyNewQueue myNewQueue = new MyNewQueue(); // Send messages to a queue. myNewQueue.SendMessage(MessagePriority.Normal, "First Message Body."); myNewQueue.SendMessage(MessagePriority.Highest, "Second Message Body."); // Receive messages from a queue. myNewQueue.ReceiveMessage(); myNewQueue.ReceiveMessage(); return; } //************************************************** // Sends a string message to a queue. //************************************************** public void SendMessage(MessagePriority priority, string messageBody) { // Connect to a queue on the local computer. MessageQueue myQueue = new MessageQueue(".\\myQueue"); // Create a new message. Message myMessage = new Message(); if(priority > MessagePriority.Normal) { myMessage.Body = "High Priority: " + messageBody; } else myMessage.Body = messageBody; // Set the priority of the message. myMessage.Priority = priority; // Send the Order to the queue. myQueue.Send(myMessage); return; } //************************************************** // Receives a message. //************************************************** public void ReceiveMessage() { // Connect to the a queue on the local computer. MessageQueue myQueue = new MessageQueue(".\\myQueue"); // Set the queue to read the priority. By default, it // is not read. myQueue.MessageReadPropertyFilter.Priority = true; // Set the formatter to indicate body contains a string. myQueue.Formatter = new XmlMessageFormatter(new Type[] {typeof(string)}); try { // Receive and format the message. Message myMessage = myQueue.Receive(); // Display message information. Console.WriteLine("Priority: " + myMessage.Priority.ToString()); Console.WriteLine("Body: " + myMessage.Body.ToString()); } catch (MessageQueueException) { // Handle Message Queuing exceptions. } // Handle invalid serialization format. catch (InvalidOperationException e) { Console.WriteLine(e.Message); } // Catch other exceptions as necessary. return; } } }
package MyProject;
import System.*;
import System.Messaging.*;
/// <summary>
/// Provides a container class for the example.
/// </summary>
public class MyNewQueue
{
//**************************************************
// Provides an entry point into the application.
//
// This example sends and receives a message from
// a queue.
//**************************************************
public static void main(String[] args)
{
// Create a new instance of the class.
MyNewQueue myNewQueue = new MyNewQueue();
// Send messages to a queue.
myNewQueue.SendMessage(MessagePriority.Normal, "First Message Body.");
myNewQueue.SendMessage(MessagePriority.Highest, "Second Message Body.");
// Receive messages from a queue.
myNewQueue.ReceiveMessage();
myNewQueue.ReceiveMessage();
return;
} //main
//**************************************************
// Sends a string message to a queue.
//**************************************************
public void SendMessage(MessagePriority priority, String messageBody)
{
// Connect to a queue on the local computer.
MessageQueue myQueue = new MessageQueue(".\\myQueue");
// Create a new message.
Message myMessage = new Message();
if (priority.CompareTo(MessagePriority.Normal) > 0) {
myMessage.set_Body("High Priority: " + messageBody);
}
else {
myMessage.set_Body(messageBody);
}
// Set the priority of the message.
myMessage.set_Priority(priority);
// Send the Order to the queue.
myQueue.Send(myMessage);
return;
} //SendMessage
//**************************************************
// Receives a message.
//**************************************************
public void ReceiveMessage()
{
// Connect to the a queue on the local computer.
MessageQueue myQueue = new MessageQueue(".\\myQueue");
// Set the queue to read the priority. By default, it
// is not read.
myQueue.get_MessageReadPropertyFilter().set_Priority(true);
// Set the formatter to indicate body contains a string.
myQueue.set_Formatter(new XmlMessageFormatter(new Type[]
{ String.class.ToType() }));
try {
// Receive and format the message.
Message myMessage = myQueue.Receive();
// Display message information.
Console.WriteLine("Priority: " + myMessage.get_Priority().ToString());
Console.WriteLine("Body: " + myMessage.get_Body().ToString());
}
catch (MessageQueueException exp) {
// Handle Message Queuing exceptions.
}
// Handle invalid serialization format.
catch (InvalidOperationException e) {
Console.WriteLine(e.get_Message());
}
// Catch other exceptions as necessary.
return;
} //ReceiveMessage
} //MyNewQueue
Windows 98, Windows 2000 SP4, Windows CE, Windows Millennium Edition, Windows Mobile for Pocket PC, Windows Mobile for Smartphone, Windows Server 2003, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP SP2, Windows XP Starter Edition
.NET Framework에서 모든 플래폼의 모든 버전을 지원하지는 않습니다. 지원되는 버전의 목록은 시스템 요구 사항을 참조하십시오.