Share via


Message Routing (Windows Embedded CE 6.0)

1/6/2010

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 Routing Registry Settings

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

Note

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 abc123.com to send messages to xyz.com and they are not exposed directly to each other in the network, you can set the RouteTo subkey of abc123.com to use def456.com as the router.

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

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSMQ\SimpleClient\RouteTo]
    "DIRECT=OS:xyz.com\*"="DIRECT=OS:def456.com\routingqueue"

The new host, def456.com, creates routingqueue as needed, so you do not have to create this queue. The original host value, as in DIRECT=OS:xyz.com\*, allows you to specify the host name (xyz.com) but not the queue name.

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

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

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

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

Note

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 ghi.com to route messages from abc123.com to the final destination xyz.com, you set the RouteFrom subkey of ghi.com to following registry key.

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSMQ\SimpleClient\RouteFrom]
    "f10436ce-8e8c-a581-1a84-e10f0ce265bf"="DIRECT=OS:xyz.com\routingqueue"

Note that the GUID of the sender (abc123.com) 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 abc123.com sends a message to the DIRECT=HTTP://def456.com/msmq/private$/Q1 and you want forward the message to another destination without notifying the sender, you can set the abc123.com registry to the following value.

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSMQ\SimpleClient\RouteLocal]
    "URI1"="DIRECT=HTTP://def456.com/msmq/private$/Q1"

Then you can set the def456.com registry to the following value.

[HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\MSMQ\SimpleClient\RouteLocal]
    "URI1"="DIRECT=HTTP://xyz.com/msmq/private$/account"

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

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

If the def456.com finds a registry key, "DIRECT=HTTP://xyz.com/msmq/private$/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.

Note

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"
HKEY hKey = NULL;
DWORD dwDisp = 0;
if(ERROR_SUCCESS == RegCreateKeyEx(
                         HKEY_LOCAL_MACHINE,
                         pRegKey,
                         0,
                         NULL,
                         REG_OPTION_NON_VOLATILE,
                         KEY_WRITE,
                         NULL,
                         &hKey,
                         &dwDisp))
{
   if(dwDisp == REG_OPENED_EXISTING_KEY)
      printf("MSMQ: registry key exist (overwriting)");

   ULONG hr = RegSetValueEx(
                 hKey,
                 pSource,
                 0,
                 REG_SZ,
                 (BYTE *)pDestination,
                 sizeof(WCHAR)*(wcslen(pDestination)+1));
   RegCloseKey(hKey);
   if(hr!=ERROR_SUCCESS)
      printf("error 0x%0X", hr);
}

See Also

Concepts

MSMQ Application Development
Summary of Supported MSMQ Functions
Administration
MSMQ COM Support
Internet Messaging
HTTP Transport
SOAP Reliable Messaging Protocol
Message Conversion
MSMQ Security

Other Resources

Message Queuing