This topic has not yet been rated - Rate this topic

MessagePropertyFilter Class

Controls and selects the properties that are retrieved when peeking or receiving messages from a message queue.

System.Object
  System.Messaging.MessagePropertyFilter

Namespace:  System.Messaging
Assembly:  System.Messaging (in System.Messaging.dll)
[TypeConverterAttribute(typeof(ExpandableObjectConverter))]
public class MessagePropertyFilter : ICloneable

The MessagePropertyFilter type exposes the following members.

  Name Description
Public method MessagePropertyFilter Initializes a new instance of the MessagePropertyFilter class and sets default values for all properties.
Top
  Name Description
Public property AcknowledgeType Gets or sets a value that indicates whether to retrieve Message.AcknowledgeType property information when receiving or peeking a message.
Public property Acknowledgment Gets or sets a value that indicates whether to retrieve Message.Acknowledgment property information when receiving or peeking a message.
Public property AdministrationQueue Gets or sets a value that indicates whether to retrieve Message.AdministrationQueue property information when receiving or peeking a message.
Public property AppSpecific Gets or sets a value that indicates whether to retrieve Message.AppSpecific property information when receiving or peeking a message.
Public property ArrivedTime Gets or sets a value that indicates whether to retrieve Message.ArrivedTime property information when receiving or peeking a message.
Public property AttachSenderId Gets or sets a value that indicates whether to retrieve Message.AttachSenderId property information when receiving or peeking a message.
Public property Authenticated Gets or sets a value that indicates whether to retrieve Message.Authenticated property information when receiving or peeking a message.
Public property AuthenticationProviderName Gets or sets a value that indicates whether to retrieve Message.AuthenticationProviderName property information when receiving or peeking a message.
Public property AuthenticationProviderType Gets or sets a value that indicates whether to retrieve Message.AuthenticationProviderType property information when receiving or peeking a message.
Public property Body Gets or sets a value that indicates whether to retrieve Message.Body property information when receiving or peeking a message.
Public property ConnectorType Gets or sets a value that indicates whether to retrieve Message.ConnectorType property information when receiving or peeking a message.
Public property CorrelationId Gets or sets a value that indicates whether to retrieve Message.CorrelationId property information when receiving or peeking a message.
Public property DefaultBodySize Gets or sets the size, in bytes, of the default body buffer.
Public property DefaultExtensionSize Gets or sets the size, in bytes, of the default extension buffer.
Public property DefaultLabelSize Gets or sets the size, in bytes, of the default label buffer.
Public property DestinationQueue Gets or sets a value that indicates whether to retrieve Message.DestinationQueue property information when receiving or peeking a message.
Public property DestinationSymmetricKey Gets or sets a value that indicates whether to retrieve Message.DestinationSymmetricKey property information when receiving or peeking a message.
Public property DigitalSignature Gets or sets a value that indicates whether to retrieve Message.DigitalSignature property information when receiving or peeking a message.
Public property EncryptionAlgorithm Gets or sets a value that indicates whether to retrieve Message.EncryptionAlgorithm property information when receiving or peeking a message.
Public property Extension Gets or sets a value that indicates whether to retrieve Message.Extension property information when receiving or peeking a message.
Public property HashAlgorithm Gets or sets a value that indicates whether to retrieve Message.HashAlgorithm property information when receiving or peeking a message.
Public property Id Gets or sets a value that indicates whether to retrieve Message.Id property information when receiving or peeking a message.
Public property IsFirstInTransaction Gets or sets a value that indicates whether to retrieve Message.IsFirstInTransaction property information when receiving or peeking a message.
Public property IsLastInTransaction Gets or sets a value that indicates whether to retrieve Message.IsLastInTransaction property information when receiving or peeking a message.
Public property Label Gets or sets a value that indicates whether to retrieve Message.Label property information when receiving or peeking a message.
Public property LookupId Gets or sets a value that indicates whether to retrieve LookupId property information when receiving or peeking a message.
Public property MessageType Gets or sets a value that indicates whether to retrieve Message.MessageType property information when receiving or peeking a message.
Public property Priority Gets or sets a value that indicates whether to retrieve Message.Priority property information when receiving or peeking a message.
Public property Recoverable Gets or sets a value that indicates whether to retrieve Message.Recoverable property information when receiving or peeking a message.
Public property ResponseQueue Gets or sets a value that indicates whether to retrieve Message.ResponseQueue property information when receiving or peeking a message.
Public property SenderCertificate Gets or sets a value that indicates whether to retrieve Message.SenderCertificate property information when receiving or peeking a message.
Public property SenderId Gets or sets a value that indicates whether to retrieve Message.SenderId property information when receiving or peeking a message.
Public property SenderVersion Gets or sets a value that indicates whether to retrieve Message.SenderVersion property information when receiving or peeking a message.
Public property SentTime Gets or sets a value that indicates whether to retrieve Message.SentTime property information when receiving or peeking a message.
Public property SourceMachine Gets or sets a value that indicates whether to retrieve Message.SourceMachine property information when receiving or peeking a message.
Public property TimeToBeReceived Gets or sets a value that indicates whether to retrieve Message.TimeToBeReceived property information when receiving or peeking a message.
Public property TimeToReachQueue Gets or sets a value that indicates whether to retrieve Message.TimeToReachQueue property information when receiving or peeking a message.
Public property TransactionId Gets or sets a value that indicates whether to retrieve Message.TransactionId property information when receiving or peeking a message.
Public property TransactionStatusQueue Gets or sets a value that indicates whether to retrieve Message.TransactionStatusQueue property information when receiving or peeking a message.
Public property UseAuthentication Gets or sets a value that indicates whether to retrieve Message.UseAuthentication property information when receiving or peeking a message.
Public property UseDeadLetterQueue Gets or sets a value that indicates whether to retrieve Message.UseDeadLetterQueue property information when receiving or peeking a message.
Public property UseEncryption Gets or sets a value that indicates whether to retrieve Message.UseEncryption property information when receiving or peeking a message.
Public property UseJournalQueue Gets or sets a value that indicates whether to retrieve Message.UseJournalQueue property information when receiving or peeking a message.
Public property UseTracing Gets or sets a value that indicates whether to retrieve Message.UseTracing property information when receiving or peeking a message.
Top
  Name Description
Public method ClearAll Sets all Boolean filter values to false, so that no message properties are retrieved when receiving a message.
Public method Clone Creates a shallow copy of the object.
Public method Equals(Object) Determines whether the specified Object is equal to the current Object. (Inherited from Object.)
Protected method Finalize Allows an object to try to free resources and perform other cleanup operations before it is reclaimed by garbage collection. (Inherited from Object.)
Public method GetHashCode Serves as a hash function for a particular type. (Inherited from Object.)
Public method GetType Gets the Type of the current instance. (Inherited from Object.)
Protected method MemberwiseClone Creates a shallow copy of the current Object. (Inherited from Object.)
Public method SetAll Specifies to retrieve all message properties when receiving a message.
Public method SetDefaults Sets the filter values of common Message Queuing properties to true and the integer-valued properties to their default values.
Public method ToString Returns a string that represents the current object. (Inherited from Object.)
Top

Setting the MessagePropertyFilter on a MessageQueue instance controls the set of properties that are retrieved when peeking or receiving a message. The filter is set on the instance of MessageQueue that retrieves the message information. When you set a MessagePropertyFilter Boolean-valued member to false, you prevent the information of the associated Message property from being retrieved by the MessageQueue.

There are several filter properties that are not Boolean values. They are integer values that get or set the default sizes of the Message.Body, Message.Extension, or Message.Label.

Retrieving a limited set of properties helps improve performance because smaller amounts of data are transferred from the queue.

When setting a property on MessagePropertyFilter, you are only indicating whether that property is retrieved when a message is received or peeked. You are not changing the associated property value for the Message.

The MessagePropertyFilter constructor sets all filter properties to their default values, which for the Boolean values is false. See the constructor topic for the defaults assigned to the integer-valued properties.

The following code example sends two messages of different priorities to the queue, and retrieves them subsequently.


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;
		}
	}
}


.NET Framework

Supported in: 4, 3.5, 3.0, 2.0, 1.1, 1.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows XP SP2 x64 Edition, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.
Did you find this helpful?
(1500 characters remaining)
Community Content Add
Annotations FAQ