C#操作MSMQ(消息队列)

using System;

using System.Collections.Generic;

using System.Text;

using System.Messaging;

using System.Data;

using System.Data.SqlClient;



namespace msmq

{

   
class Program

    {

       
staticvoid Main(string[] args)

        {

           
string database = args[0];



           
string path =".\\private$\\"+ args[1];



           
if (!MessageQueue.Exists(path))

                MessageQueue.Create(path);



           
string strsql ="select md5 from video with(nolock) order by id";



           
int i =0;

           
using (SqlDataReader dr = SqlHelper.ExecuteReader(string.Format(System.Configuration.ConfigurationSettings.AppSettings["db"], database), CommandType.Text, strsql))

            {

               
while (dr.Read())

                {

                    Console.WriteLine(
--i);

                    SendMessage(path, dr[
0].ToString(), string.Empty);

                }

                dr.Close();

                Console.WriteLine(
"完成");

            }

        }



       
privatestaticvoid SendMessage(string path, string label, object body)

        {

           
//new MessageQueue(path).Send(body, label);

           
//return;

            MessageQueue mq =new MessageQueue(path);

            System.Messaging.Message msg
=new System.Messaging.Message();

            msg.Label
= label;

            msg.Body
= body;

            msg.Recoverable
=true;

            mq.Send(msg);

            msg
=null;

            mq.Close();

            mq
=null;

        }

    }

}

你可能感兴趣的:(消息队列)