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;

            }

        }

    }

  • 相关阅读:
    1. 两数之和
    RabbitMQ主题交换机
    RabbitMQ路由
    RabbitMQ发布订阅
    RabbitMQ简介和安装
    55. 跳跃游戏
    63. 不同路径 II
    62. 不同路径
    6. Z 字形变换
    sql注入攻击与防御第一章(笔记)
  • 原文地址:https://www.cnblogs.com/armyfai/p/3586860.html
Copyright © 2011-2022 走看看