Partilhar via


C-C++ Code Example: Setting PROPID_Q_MULTICAST_ADDRESS

 

Applies To: Windows 10, Windows 7, Windows 8, Windows 8.1, Windows Server 2008, Windows Server 2008 R2, Windows Server 2012, Windows Server 2012 R2, Windows Server Technical Preview, Windows Vista

This example provides an application-defined function that sets the PROPID_Q_MULTICAST_ADDRESS property of an existing queue based on the multicast address provided by the caller. This property cannot be set for a transactional queue.

The value of this property is a string containing a valid multicast address (in the form shown below).

<address>:<port>  

The address must be in the class D range from 224.0.0.0 to 239.255.255.255. However, only certain ranges of addresses in this range are unreserved and available for sending multicast messages. For the latest list of reserved multicast addresses, see the Internet Assigned Number Authority (IANA) Internet Multicast Addresses Web page. There are no restrictions on the port number.

Note

To disassociate an existing queue from a multicast address set the type Indicator of PROPID_Q_MULTICAST_ADDRESS

Setting this property affects what messages are routed to the queue. Setting this property has no effect on messages already in the queue.

A direct format name can be passed to this function only for a local private queue.

For information on how Message Queuing uses multicast addresses to send message to multiple destination queues, see Multiple-Destination Messaging.

To set PROPID_Q_MULTICAST_ADDRESS

  1. Define the maximum number of queue properties to be specified and the queue property counter.

  2. Define the MQQUEUEPROPS structure.

  3. Specify PROPID_Q_MULTICAST_ADDRESS.

  4. Initialize the MQQUEUEPROPS structure.

  5. Validate the input parameters provided by the caller.

  6. Call MQSetQueueProperties to set the multicast address associated with the queue. If the call fails the returned error code is returned to the caller.

Code Example

The following code example requires MSMQ 3.0.

HRESULT SetMulticastAddressProp(  
                                LPCWSTR wszQueueFormatName,  
                                LPWSTR wszValue  
                                )  
{  
  
  // Define the maximum number of queue properties and a property counter.  
  const int NUMBEROFPROPERTIES = 1;  
  DWORD cPropId=0;  
  
  // Define a queue property structure.  
  MQQUEUEPROPS   QueueProps;  
  MQPROPVARIANT  aQueuePropVar[NUMBEROFPROPERTIES];  
  QUEUEPROPID    aQueuePropId[NUMBEROFPROPERTIES];  
  HRESULT        aQueuePropStatus[NUMBEROFPROPERTIES];  
  HRESULT = MQ_OK;  
  
  // Validate the input parameters.  
  if (wszQueueFormatName == NULL || wszValue == NULL)  
  {  
    return  MQ_ERROR_INVALID_PARAMETER;  
  }  
  
  // Set PROPID_Q_MULTICAST_ADDRESS with the requested value.  
  aQueuePropId[cPropId] = PROPID_Q_MULTICAST_ADDRESS;  
  aQueuePropVar[cPropId].vt = VT_LPWSTR ;  
  aQueuePropVar[cPropId].pwszVal  = wszValue;  
  cPropId++;  
  
  // Initialize the MQQUEUEPROPS structure.  
  QueueProps.cProp = cPropId;  
  QueueProps.aPropID = aQueuePropId;  
  QueueProps.aPropVar = aQueuePropVar;  
  QueueProps.aStatus = aQueuePropStatus;  
  
  // Set the queue properties.  
  hr = MQSetQueueProperties(wszQueueFormatName, &QueueProps);  
  return hr;  
}