Note
Access to this page requires authorization. You can try signing in or changing directories.
Access to this page requires authorization. You can try changing directories.
The Large Message to MSMQ sample demonstrates how to send an .xml document larger than 4 megabytes (MB) from Message Queuing (also known as MSMQ) to the BizTalk MSMQ adapter by using the MQSendLargeMessage API implemented by MQRTLarge.dll.
What This Sample Does
The sample works as follows:
A user uses SendLargeMessage.exe to send a large .xml file to a queue on a local computer.
BizTalk Server receives the large .xml file from the queue and copies it to a local directory.
Many operations in Message Queuing are asynchronous. That is, many MSMQ API calls (for example, MQSendLargeMessage) return to the caller before the requested operation has fully completed.
MSMQ provides a mechanism to deliver feedback to the application after the operation has completed. This mechanism involves the use of an "Admin Queue." MSMQ returns feedback in the form of a message in the Admin Queue. The Admin Queue to which MSMQ will return feedback is specified when the original MSMQ API call is made. So, for example, when sending a message using the MQSendLargeMessage API, the application can specify the name of an Admin Queue by using the PROPID_M_ADMIN_QUEUE message property on the message passed in the call to MQSendLargeMessage. Even though the application may get a successful return code on the MQSendLargeMessage call, if the message send operation subsequently fails, MSMQ writes a message to that effect to the specified Admin Queue.
If the application does not specify an Admin Queue, a send failure results in the message being lost and no diagnostics captured — in effect, the message disappears without any evidence. A number of error situations in MSMQ can cause this to happen, for example, doing a non-transactional send to a transactional queue.
In the context of this sample, it is important that the code specify a transaction type in the call to MQSendLargeMessage that is consistent with the transaction support specified for the queue to which the message is sent. If this is not done and if no Admin Queue is specified (as is the case in this sample), then MSMQ discards the sent message with no indication that it has done so (that is, no error code returned to the application, no diagnostics written to the event log, and so on).
Where to Find This Sample
<Samples Path>\AdaptersUsage\MSMQLarge
Note
If using a 64-bit version of Windows and BizTalk Server, the sample will be installed in the C:\Program Files (x86)\Microsoft BizTalk Server <version>\SDK\Samples\AdaptersUsage\MSMQLarge folder. Note this change for any other instructions in this document using the C:\Program Files folder.
The following table shows the files in this sample and describes their purpose.
| File | Description |
|---|---|
| MQRTLarge.dll | Provides an add-on for native message queuing. Exposes the MQSendLargeMessage and MQReceiveLargeMessage APIs. You must install BizTalk Server on a 64-bit version of Windows in order to access the 64-bit version of MQRTLarge.dll. For an MSMQ solution without BizTalk Server, the MQRTLarge.dll may still function correctly. However, this is not a recommended configuration that Microsoft supports, and unexpected results may occur if used outside of the BizTalk Server environment. |
| LargeMessages.sln | Provides a Visual Studio solution to create the SendLargeMessage executable used in the sample. |
| XMLCreator.sln | Provides a Visual Studio solution to create the XMLCreator executable to generate a test .xml file for the SDK sample. |
Configure BizTalk and Create the MSMQ Queue
Ensure that Visual Studio, Microsoft Message Queuing, and BizTalk Server installed.
To configure BizTalk Server
In Visual Studio, open the C:\Program Files\Microsoft BizTalk Server <version>\SDK\Samples\AdaptersUsage\MSMQLarge\LargeMessages.sln solution file. Build the sample.
Create a C:\Demo directory where BizTalk Server will place the messages from MSMQ.
Open the BizTalk Server Administration console.
Create a send port for the sample to write the message.
- Expand BizTalk Group, expand Applications, expand BizTalk Application 1, right-click Send Ports, click New, and then click Static One-Way Send Port.
In the Static One-Way Send Port Properties dialog box, set the name of the port to MySendPort.
Set the transport type to File.
Click the Configure button to open the File Transport Properties form. Enter C:\Demo in Destination Folder. Ensure that the host instance identity has access to the C:\Demo folder.
Ensure that File Name is set to %MessageID%.xml. Click OK.
Click Filters.
Set Property to BTS.ReceivePortName.
Set Operator to =.
Set Value to MyReceivePort.
Click OK.
Create a receive port to accept the message from MSMQ.
In the BizTalk Server Administration console, right-click Receive Ports.
Click New, and then click One-way Receive Port.
In the Receive Port Properties dialog box, set the name of the port to MyReceivePort, and then click OK.
After creating a receive port for the sample, you must create a receive location.
In the BizTalk Server Administration console, right-click Receive Locations.
Click New, and then click One-way Receive Location.
Set the name of the receive location to MSMQReceiveLocation.
In the Select a Receive Port dialog box, select MyReceivePort.
In the Receive Location Properties dialog box, set Transport Type to MSMQ.
In the Address (URI) section, click Configure to open the MSMQ Transport Properties form. Set Queue to localhost\private$\test.
Set Transactional to
True, and then click OK.
You must make the ports and receive locations available for use through the BizTalk Server Administration console.
Right-click MySendPort, and then click Enlist.
Right-click MySendPort, and then click Start.
Right-click MSMQReceiveLocation, and then click Enable.
To create the MSMQ queue in Windows Server
Click Start, right-click Computer, and then click Manage.
Expand the Features node.
Expand the Message Queuing node.
Right-click the Private Queues node, click New, and then click Private Queue.
Under Queue name, enter test. Ensure that the Transactional check box is selected.
Click OK.
To create the MSMQ queue in Windows
Click Start, right-click Computer, and then click Manage.
Expand Services and Applications, and then expand the Message Queuing node.
Note
If Message Queuing is not installed in the computer, go to Control Panel > Programs > Programs and Features, and then select Turn Windows features on or off. Check all the features under Microsoft Message Queue (MSMQ) Server, and then click OK.
Right-click the Private Queues node, click New, and then click Private Queue.
Under Queue name, enter test. Ensure that the Transactional check box is selected.
Click OK.
Creating a Test File and Running the Sample
To create a large test file
In Visual Studio, open the solution C:\Program Files\Microsoft BizTalk Server <version>\SDK\Samples\AdaptersUsage\MSMQLarge\XMLCreator\XMLCreator.sln.
Build and run the project.
Under XML Body, type This is a test message.
Under # of times to copy XML body, type
250000.Under XML File Location, type
C:\Program Files\Microsoft BizTalk Server <version>\SDK\Samples\AdaptersUsage\MSMQLarge\LargeFile.xml.Click Create XML, and then click OK.
To run the sample
Open a command prompt and change directory to C:\Program Files\Microsoft BizTalk Server <version>\SDK\Samples\AdaptersUsage\MSMQLarge\SendLargeMessage\bin\debug.
At the command prompt, run SendLargeMessage.exe. The SendLargeMessage executable accepts two variables — the first is the location of the MSMQ queue, and the second is the location of the .xml file to send:
DIRECT=OS:localhost\private$\Test "C:\Program Files\Microsoft BizTalk Server <version>\SDK\Samples\AdaptersUsage\MSMQLarge\LargeFile.xml"Verify that a file of the same size was created on the BizTalk Server computer in the C:\Demo directory. This is the directory you identified in the MySendPort send port.
Comments
SendLargeMessage.exe references the LargeMessages API, which in turn references the BizTalk Message Queuing Large Message Extension (MQRTLarge.dll) API. The Message Queuing Large Message Extension API is an add-on for native message queuing that enables the processing of messages larger than the 4 MB limit of native message queuing.
This sample uses the MQSendLargeMessage API and exposes the API to the .NET Framework by using the LargeMessages API.
See Also
BizTalk Message Queuing Large Message Extension
Adapter Samples - Usage