Partilhar via


How to send MSMQ messages over 4MB in size - #2: Using file chunking in memory

I know the following KnowledgeBase article is over 10 years old but the principles still apply. 

198686 How to send files larger than 4 MB by using Microsoft Message Queuing

  1. Open file
  2. Read first block of data into a memory buffer
  3. Put memory buffer contents into message
  4. Send message
  5. Read next block of data into a memory buffer
  6. Goto 3 unless EOF
  7. Close file

 and at the other end, reverse the process. 

  1. Create file
  2. Read first message body into a memory buffer
  3. Append memory buffer to file
  4. Read next message body into a memory buffer
  5. Goto 3 unless no more messages
  6. Close file

Make use of the Label and AppSpecific message properties to maintain the sequencing of the data.

You could instead use transactions to keep the messages in order but this will require more resources - the whole file would need to be stored as messages in the outgoing queue before sending can commence. In the example above, each fragment is instead sent as soon as msq.send q is called. The same applies on delivery - transactional messaging would only make the file chunks available when all the messages had arrived; non-transactional messaging could be used to start generating the output file as soon as the first chunk arrived.