日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當前位置: 首頁 > 编程资源 > 编程问答 >内容正文

编程问答

Delphi下MSMQ(Mircosoft Message Queue)实例(私有队列)

發(fā)布時間:2025/6/15 编程问答 23 豆豆
生活随笔 收集整理的這篇文章主要介紹了 Delphi下MSMQ(Mircosoft Message Queue)实例(私有队列) 小編覺得挺不錯的,現(xiàn)在分享給大家,幫大家做個參考.

網(wǎng)上關(guān)于消息隊列技術(shù)原理說明的詳細文檔很多,但涉及到Delphi的具體實現(xiàn)很少,這是我從網(wǎng)上找了一上午的資料,自己整合和嘗試的能運行的程序。

打開控制面板->程序->添加組件,添加消息隊列

打開控制面板->計算機管理->服務(wù)與應(yīng)用程序->消息隊列,添加私有有消息Test.

在Delphi中添加MSMQ控件, TMSMQMessage; TMSMQQueueInfo; TMSMQQueue; TMSMQEvent; 這些控件在Project->Import type Library里存在。

unit Unit1; interface uses Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs,MSMQ_TLB,ComObj,StdCtrls,OleServer; type TForm1 = class(TForm) MSMQMessage1: TMSMQMessage; MSMQQueueInfo1: TMSMQQueueInfo; MSMQQueue1: TMSMQQueue; MSMQEvent1: TMSMQEvent; Button1: TButton; edit1:TEdit; edit2: TEdit; Button2: TButton; lbl1: TLabel; lbl2: TLabel; procedure Button1Click(Sender: TObject); procedure Button2Click(Sender: TObject); procedure MSMQEvent1Arrived(Sender: TObject; var Queue: OleVariant; Cursor: Integer); private { Private declarations } public { Public declarations } end; var Form1: TForm1; implementation {$R *.dfm} //發(fā)送消息 procedure TForm1.Button1Click(Sender: TObject); begin//確定消息隊列路徑 MSMQQueueInfo1.PathName :='./Private$/Test'; //遠程機器名 MSMQQueueInfo1.RemoteMachineName := '127.0.0.1' ; //消息內(nèi)容 (MSMQMessage1.DefaultInterface as IMSMQMessage).body :=edit1.Text; //連接到消息隊列 MSMQQueue1.ConnectTo(MSMQQueueInfo1.Open(MQ_SEND_ACCESS, 0)); //發(fā)送消息 MSMQMessage1.Send(MSMQQueueInfo1.Open(MQ_SEND_ACCESS, MQ_DENY_NONE)); showmessage( '已經(jīng)把信息入寫入消息隊列中 '); end; //接收消息 procedure TForm1.Button2Click(Sender: TObject); begin msmqqueueinfo1.PathName :='./Private$/Test'; msmqqueue1.Disconnect; msmqqueue1.ConnectTo(msmqqueueinfo1.Open(1, 0)); //msmqqueue1.EnableNotification(MSMQEvent1.DefaultInterface); end; //MSMQEvent事件 procedure TForm1.MSMQEvent1Arrived(Sender: TObject; var Queue: OleVariant; Cursor: Integer); var Msg: Variant; begin //從隊列中讀取消息 Msg := msmqqueue1.Receive; edit2.Text := Msg.body; end; end.

?

轉(zhuǎn)載于:https://www.cnblogs.com/Coder-MIFir/p/10333753.html

總結(jié)

以上是生活随笔為你收集整理的Delphi下MSMQ(Mircosoft Message Queue)实例(私有队列)的全部內(nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯,歡迎將生活随笔推薦給好友。