Message Routing

Windows Mobile 6.5
A version of this page is also available for

The HTTP endpoint for MSMQ can be mapped to another device on your network as the ultimate destination for your message. For example, your exposed gateway or Perimeter Network device can receive messages on behalf of some internal private devices that are not exposed directly to the public network.

Each queue on the edge device can be mapped to either a local queue or a queue on another device that is reachable from the edge device. Additionally, individual queues can be mapped to different machines.

Message Queuing provides a set of routing registries that enable messages to be routed in a variety of ways in response to network conditions.

The router registries must be set before the MSMQ service starts.

You can use the HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSMQ\SimpleClient registry key to set the message route. The following subkeys specify the message routes:

  • RouteTo
  • RouteFrom
  • RouteLocal

Use the RouteTo and RouteFrom pair when the source and destination MSMQ hosts are not exposed directly to each other in the network. You can specify a router that connects to both source and destination hosts to send messages across.

For example, to allow to send messages to and they are not exposed directly to each other in the network, you can set the RouteTo subkey of to use as the router.

The following registry key allows the application to deliver all messages whose original destination is to the new destination


The new host,, creates routingqueue as needed, so you do not have to create this queue. The original host value, as in\*, allows you to specify the host name ( but not the queue name.

Only the host name part,, is used for the routing. Therefore, all queues going to the will be routed to

The delivery of messages to totally depends on the routing ability of the MSMQ message router ( once those messages are sent to the router.

MSMQ has a routing capability, so messages can be routed to their original destination if is exposed to

If the router does not have a routing capability, the messages will simply be discarded.

Messages being routed by RouteTo and RouteFrom still maintain their original destination queue name.

This registry key is useful when the MSMQ sender cannot directly reach the destination host device, such as a device behind a firewall or when connected to another network protocol. In this case, you can set the firewall or the edge device as the router.

The RouteFrom subkey is used to handle special cases. Sometimes you may want to forward messages only from a known MSMQ host for security purposes. You set the RouteFrom subkey in your edge device. This way you can specify the source devices that you allow the edge device to route messages for.

For example, to allow to route messages from to the final destination, you set the RouteFrom subkey of to following registry key.


Note that the GUID of the sender ( is f10436ce-8e8c-a581-1a84-e10f0ce265bf.

SRMP routing uses the RouteLocal subkey for message routing. This is not related to either the RouteTo or RouteFrom subkeys.

For example, if sends a message to the DIRECT=HTTP://$/Q1 and you want forward the message to another destination without notifying the sender, you can set the registry to the following value.


Then you can set the registry to the following value.


When sends an SRMP message to "HTTP://$/Q1", this is sent to the with a tag "URI1".

When receives this SRMP message, checks its local registry for matching "URI1".

If the finds a registry key, "DIRECT=HTTP://$/account" in this case, it forwards that message to the specified queue.

The RouteLocal subkey applies only when sending messages through SRMP. The routing destination in the destination-side registry can be any valid queue name.

Using RouteLocal changes the final destination queue name in the message.

The following sample code shows how to set the RouteTo subkey.

WCHAR* pSource = L"DIRECT=OS:cemsmq-wxp\\*";
WCHAR* pDestination = L"DIRECT=OS:CEPCKS32976X\\routingqueue";
WCHAR* pRegKey = L"SOFTWARE\\Microsoft\\MSMQ\\SimpleClient\\RouteTo"
DWORD dwDisp = 0;
if(ERROR_SUCCESS == RegCreateKeyEx(
      printf("MSMQ: registry key exist (overwriting)");

   ULONG hr = RegSetValueEx(
                 (BYTE *)pDestination,
      printf("error 0x%0X", hr);

Community Additions