I am currently working on batch processing application using MSMQ in C#. In the application design, I have an error queue containing XML messages using the ActiveXFormatter
. I know that I can write an application to write these error messages to text files or database tables.
Are there other pre-built tools available allowing you to export messages to variety of formats (ie text files, database tables, etc.)? I am just looking for best practices.
Ok. I found the solution of writing code to be really easy. Here's my reference solution.
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!"); } } }
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.