zoukankan      html  css  js  c++  java
  • 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;

            }

        }

    }

  • 相关阅读:
    我是来讲笑话的
    dom4j读取xml
    Mysql常用命令
    如何快速开发小型系统
    Spring aop的实现原理
    Spring IOC容器解析及实现原理
    如何编写更棒的代码
    Git使用教程
    关于程序员吃青春饭问题之探讨
    如何自学编程
  • 原文地址:https://www.cnblogs.com/armyfai/p/3586860.html
Copyright © 2011-2022 走看看