Is there a tool that makes it easy to export messages from Message Queuing (MSMQ)?

I am currently working on a batch processing application using MSMQ in C #. In application design, I have an error queue containing XML messages using ActiveXFormatter. I know that I can write an application to write these error messages to text files or database tables.

Are there other ready-made tools available that allow you to export messages to various formats (i.e. text files, database tables, etc.)? I'm just looking for best practices.

+3
source share
1 answer

Ok. . .

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Messaging;

namespace ExportMSMQMessagesToFiles
{
    public partial class frmMain : Form
    {
        public frmMain()
        {
            InitializeComponent();
        }

        private void btnExportTextFiles_Click(object sender, EventArgs e)
        {           
            //Setup MSMQ using path from user...
            MessageQueue q = new MessageQueue(txtMSMQ.Text);

            //Setup formatter... Whatever you want!?
            q.Formatter = new ActiveXMessageFormatter();

            // Loop over all messages and write them to a file... (in this case XML)
            MessageEnumerator msgEnum = q.GetMessageEnumerator2();
            int k = 0;
            while (msgEnum.MoveNext())
            {
                System.Messaging.Message msg = msgEnum.Current;                                
                string fileName = this.txtFileLocation.Text + "\\" + k + ".xml";                
                System.IO.File.WriteAllText(fileName, msg.Body.ToString());
                k++;
            }

            MessageBox.Show("All done!");
        }
    }
}

+4

Source: https://habr.com/ru/post/1707783/


All Articles