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
- Open file
- Read first block of data into a memory buffer
- Put memory buffer contents into message
- Send message
- Read next block of data into a memory buffer
- Goto 3 unless EOF
- Close file
and at the other end, reverse the process.
- Create file
- Read first message body into a memory buffer
- Append memory buffer to file
- Read next message body into a memory buffer
- Goto 3 unless no more messages
- 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.