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;

            }

        }

    }

  • 相关阅读:
    MVC框架简介
    模型-视图-控制器模式
    高德地图基本开发
    质量属性的六个常见属性场景分析
    架构漫谈读后感
    第十周
    第九周总结
    第八周总结
    springboot基于mybatis的pegehelper分页插件
    webmagic之爬取数据存储为TXT
  • 原文地址:https://www.cnblogs.com/armyfai/p/3586860.html
Copyright © 2011-2022 走看看