When using MSMQ, I cannot transfer a message larger than 4 MB ( limit ). How do I get around this limitation?

    2 answers 2

    Unfortunately, no way. This is an architectural limitation. Details here .

    Although for BizTalk, which uses the same MSMQ there is an extension called BizTalk Message Queuing Large Message Extension. Here you can read more.

    The second option is to manually split the messages into parts. I think the implementation example will not be difficult to google, because the topic is quite beaten.

      Apparently, we want to use the bus for passing files. In my opinion, using a tire for this is not the best idea, but if you want, here’s an example from Ms:

      using System; using System.Messaging; using System.IO; namespace FilesInMsmq{ /// <summary> /// This example shows how to send and receive Files larger than 4 Mb. using MSMQ Messages. /// How to run the example: /// FilesInMsmq [send/receive] [File Name] [Queue Path] /// </summary> class MsmqFileExample { //break the mesage into 4 Mb chunks static int chunkSize = 4194000; [STAThread] static void Main(string[] args) { string fileName; string queuePath; if (args.Length > 0) { //get parameters from command prompt fileName = args[1]; queuePath = args[2]; switch (args[0]) { case "send": SendFile(fileName, queuePath); break; case "receive": ReceiveFile(fileName, queuePath); break; } } } static void SendFile(string fileName, string queuePath) { int i; int count = 0; int msgNumber = 0; //Open an existing queue MessageQueue queue = new MessageQueue(queuePath); Message msg = new Message(); try { //Open the file for reading using (FileStream fs = File.OpenRead(fileName)) { // while there are bytes while ((i = fs.ReadByte()) != -1) { // if count has reached size, send message if (count >= chunkSize) { msgNumber++; msg.AppSpecific = msgNumber; //Send the messsage queue.Send(msg); string nextMsgId = msg.Id; count = 0; //Create a new message msg = new Message(); msg.CorrelationId = nextMsgId; } msg.BodyStream.WriteByte((byte)i); count++; // from the original file } msgNumber++; msg.AppSpecific = msgNumber; //Send the last message queue.Send(msg); } } catch (Exception ex) { Console.WriteLine(ex); } finally { //release queue resources queue.Close(); } } static void ReceiveFile(string fileName, string queuePath) { byte[] data; int length; //Open an existing queue MessageQueue queue = new MessageQueue(queuePath); try { //Open file for writing using (FileStream fs = File.OpenWrite(fileName)) { //Receive the first message Message msg = queue.Receive(new TimeSpan(0, 0, 0, 1)); while (msg != null) { //Get the Lenght of the message body stream length = Convert.ToInt32(msg.BodyStream.Length); //Create a buffer to hold the stream in memory data = new byte[length]; //Read the body stream msg.BodyStream.Read(data, 0, length); //Write the buffer into the file fs.Write(data, 0, length); //Receive following message msg = queue.Receive(new TimeSpan(0, 0, 0, 1)); } } } catch (Exception ex) { Console.WriteLine(ex); } finally { //release queue resources queue.Close(); } } } }