主婦と.NETと犬のぶろぐ

奥様 と プログラム と お犬様 の 楽しい日常

目次

Blog 利用状況

ニュース

書庫

日記カテゴリ

MessageQueue(System.Messaging.MessageQueue)

もちろん使ったことなんてないっす。
なので、一から調べようと思ったんですが、ドキュメント があるわあるわ。

まず、MessageQueue を使ってプログラム遊びをしたい場合は、
ワタシの環境(XPSP2)ですが、[Windows コンポーネント] の [メッセージ キュー]を入れねばなりませんでした。
メッセージ キュー

あとは参考文献を読んで、とりあえず組んでみたっす。

■参考文献
メッセージング コンポーネントの使用
MessageQueue クラス
Message クラス

■実行画像
自分で送って自分で受信してるから何も面白くないけど、一応 MessageQueue を使ってます。 MessageQueue

Public Class MessageQueueTest

Private Const MQ_PATH As String = ".\Private$\MyQueue" Private Const ASYNC_MQ_PATH As String = ".\Private$\MyAsyncQueue" Private Const ASYNC_CALLBACK_MQ_PATH As String = ".\Private$\MyAsyncCallBackQueue"
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click ' 受信結果表示領域のクリア Me.PictureBox1.Image = Nothing Me.DataGridView1.DataSource = Nothing Me.DataGridView1.DataMember = Nothing
'' 専用キューの作成(取得) Me.MessageQueue1 = Me.GetMessageQueue(MQ_PATH) ' 受診メッセージを履歴キューに残す Me.MessageQueue1.UseJournalQueue = True
'' メッセージの送信(テキスト) Dim textMessage As System.Messaging.Message = _ New System.Messaging.Message() Dim xmlFormatter As System.Messaging.IMessageFormatter = _ New System.Messaging.XmlMessageFormatter(New Type() {GetType(String)}) With textMessage .Label = "textTest" .Body = "健康だとごはんがうまい" .Formatter = xmlFormatter End With Me.MessageQueue1.Send(textMessage)
'' 受信(テキスト) Me.MessageQueue1.Formatter = xmlFormatter Dim receiveTextMessage As System.Messaging.Message = _ Me.MessageQueue1.Receive() Me.Label1.Text = DirectCast(receiveTextMessage.Body, String)
'' メッセージの送信(画像) Dim imageMessage As System.Messaging.Message = _ New System.Messaging.Message() Dim binaryFormatter As System.Messaging.IMessageFormatter = _ New System.Messaging.BinaryMessageFormatter() With imageMessage .Label = "中さん" .Body = My.Resources.中さん .Formatter = binaryFormatter .Priority = Messaging.MessagePriority.Highest ' 最優先のメッセージ End With Me.MessageQueue1.Send(imageMessage)
'' 受信(画像) Me.MessageQueue1.Formatter = binaryFormatter Dim receiveImageMessage As System.Messaging.Message = _ Me.MessageQueue1.Receive() Dim receive中さん As Bitmap = DirectCast(receiveImageMessage.Body, Bitmap) Me.PictureBox1.SizeMode = PictureBoxSizeMode.Zoom Me.PictureBox1.Size = New Size(CInt(receive中さん.Width / 2), CInt(receive中さん.Height / 2)) Me.PictureBox1.Image = receive中さん
'' メッセージの送信(Dataset) Dim datasetMessage As System.Messaging.Message = _ New System.Messaging.Message() With datasetMessage .Label = "DatasetTest" .Body = Me.CreateDataSet() .Formatter = xmlFormatter End With Me.MessageQueue1.Send(datasetMessage)
'' 受信(Dataset) Me.MessageQueue1.Formatter = xmlFormatter Dim receiveDatasetMessage As System.Messaging.Message = _ Me.MessageQueue1.Receive() Dim receiveDataset As DataSet = DirectCast(receiveDatasetMessage.Body, DataSet) Me.DataGridView1.DataSource = receiveDataset Me.DataGridView1.DataMember = receiveDataset.Tables(0).TableName
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click If Not System.Messaging.MessageQueue.Exists(MQ_PATH) Then Return ' .\Private$\MyNewQueue にあるメッセージを削除 Me.MessageQueue1.Purge() End Sub
Private Sub Button3_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button3.Click If Not System.Messaging.MessageQueue.Exists(MQ_PATH) Then Return ' Queue を削除 System.Messaging.MessageQueue.Delete(MQ_PATH) End Sub
'' 非同期通信 Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click '' 専用キューの作成(取得) Me.MessageQueue2 = Me.GetMessageQueue(ASYNC_MQ_PATH) AddHandler Me.MessageQueue2.ReceiveCompleted, AddressOf ReceiveCompleted Me.MessageQueue2.BeginReceive()
' 送信 Dim textMessage As System.Messaging.Message = _ New System.Messaging.Message() With textMessage .Label = "textTest2" .Body = "病気だとごはんがまずい" .Formatter = New System.Messaging.XmlMessageFormatter(New Type() {GetType(String)}) End With Me.MessageQueue2.Send(textMessage) End Sub
'' 非同期で結果を受け取る Private Sub ReceiveCompleted(ByVal sender As Object, ByVal e As System.Messaging.ReceiveCompletedEventArgs) Dim mq As System.Messaging.MessageQueue = _ DirectCast(sender, System.Messaging.MessageQueue)
Dim msg As System.Messaging.Message = mq.EndReceive(e.AsyncResult) msg.Formatter = New System.Messaging.XmlMessageFormatter(New Type() {GetType(String)}) Console.WriteLine("ReceiveCompleted:" & DirectCast(msg.Body, String))
' 続けてメッセージを受信し続ける場合 mq.BeginReceive() End Sub
'' 非同期通信 その2 Private Sub Button5_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button5.Click '' 専用キューの作成(取得) Me.MessageQueue3 = Me.GetMessageQueue(ASYNC_CALLBACK_MQ_PATH) Dim datasetMessage As System.Messaging.Message = _ New System.Messaging.Message() With datasetMessage .Label = "DatasetTest2" .Body = Me.CreateDataSet() .Formatter = New System.Messaging.XmlMessageFormatter(New Type() {GetType(DataSet)}) End With Me.MessageQueue3.Send(datasetMessage)
' 受信開始 Me.MessageQueue3.BeginReceive(New TimeSpan(0, 0, 0, 10), Nothing, _ AddressOf CallBack) End Sub
' 受信完了 Private Sub CallBack(ByVal result As System.IAsyncResult) If Not result.IsCompleted Then Console.WriteLine("not completed") Return End If
Me.MessageQueue3.Formatter = New System.Messaging.XmlMessageFormatter(New Type() {GetType(DataSet)}) Dim message As System.Messaging.Message = _ Me.MessageQueue3.EndReceive(result) Dim ds As DataSet = DirectCast(message.Body, DataSet) Console.WriteLine("DatasetName:" & ds.DataSetName) Console.WriteLine("TableName:" & ds.Tables(0).TableName) End Sub
Private Function GetMessageQueue(ByVal queueName As String) As System.Messaging.MessageQueue If System.Messaging.MessageQueue.Exists(queueName) Then ' 指定された Queue が存在する場合取得 Return New System.Messaging.MessageQueue(queueName) Else ' 指定された Queue が存在しない場合作成 Return System.Messaging.MessageQueue.Create(queueName) End If End Function
Private Function CreateDataSet() As DataSet Dim ds As DataSet = New DataSet("TestDataset") Dim dt As DataTable = New DataTable("Dogs") ds.Tables.Add(dt)
Dim uniqueColumn As DataColumn = New DataColumn("ID", GetType(Integer)) uniqueColumn.Unique = True uniqueColumn.AutoIncrement = True dt.Columns.Add(uniqueColumn) dt.Columns.Add("NAME", GetType(String))
Dim names As String() = {"ふじこ", "えでん", "オット"} For Each name As String In names Dim row As DataRow = dt.NewRow() row("NAME") = name dt.Rows.Add(row) Next Return ds End Function End Class

投稿日時 : 2007年2月23日 9:49

Feedback

# re: MessageQueue(System.Messaging.MessageQueue) 2007/02/23 16:13 黒龍

やってみると意外と簡単なんですよね。信頼性も高くなるしあれこれ悩まずにすむので最近お気に入りです。

# re: MessageQueue(System.Messaging.MessageQueue) 2007/02/26 10:18 なおこ(・∀・)

>> 黒龍さん
たしかに、やってみると意外に簡単に実装できました。
まぁやってることが凄く簡単なことだからかもしれませんが...

# TEoswfKcgM 2014/08/28 5:12 http://crorkz.com/

86IHyW Thanks for the blog post, can I set it up so I get an email sent to me whenever you make a new article?

# IKCgrOTdiW 2014/09/16 18:27 https://www.youtube.com/watch?v=6BlpsZ7LHRQ

This site can be a walk-by means of for all of the information you wished about this and didn't know who to ask. Glimpse here, and you'll undoubtedly discover it.

# OZQofOgPKKvTBhSVg 2014/09/18 17:02 http://kickstarter-dymaxion.info/story/27299

gSXUNN Looking forward to reading more. Great blog.Really looking forward to read more. Fantastic.

# オメガコピー 2017/08/24 5:03 ranigaslam@excite.co.jp

新品の財布の
●株式情報はいつでも更新します!
◆品質が良くて、は価格が、実物の写真が低いです!
◆経営方針:品質を重視して、納期も厳守して、第1を使いを信じます!
◆超とりわけ安い価格で、安心して、迅速で、確かで、顧客の身辺まで(に)引き渡します。
豊富な商品でそろってい最も新作もいつでも商品が到着してゆっくりと見てくださいのためです。
広大な客がご光臨賜りを歓迎します
オメガコピー http://www.gooshop001.com

# fKBjWMFMZLykc 2018/06/01 19:33 http://www.suba.me/

XTMmFu Perfectly written subject matter, thanks for entropy.

# KclvvWRUVEHhhTDfW 2018/06/04 0:12 https://topbestbrand.com/คร&am

wonderful points altogether, you simply received a brand new reader. What may you suggest about your publish that you made a few days ago? Any sure?

# qOYNRjQixJFNiLpNA 2018/06/04 2:42 http://www.seoinvancouver.com/

Really informative blog.Really looking forward to read more. Much obliged.

# extmScSXNTmPg 2018/06/04 10:12 http://www.seoinvancouver.com/

This particular blog is without a doubt educating as well as amusing. I have found many handy stuff out of this source. I ad love to go back again and again. Thanks!

# sfykegbfhRgVDaY 2018/06/04 17:41 http://narcissenyc.com/

Looking forward to reading more. Great article post.Thanks Again. Keep writing.

# mEevBnDjNbyc 2018/06/05 3:14 http://www.narcissenyc.com/

Some truly prize articles on this website , saved to fav.

# YerdGFPobUzAuMiEyfe 2018/06/05 5:09 http://www.narcissenyc.com/

Wow, great blog article.Really looking forward to read more. Awesome.

# JCSLYAEtXY 2018/06/05 7:04 http://www.narcissenyc.com/

Wow, fantastic weblog structure! How lengthy have you been running a blog for? you make running a blog glance easy. The total glance of your website is magnificent, let alone the content!

# IxFMweJkLyiW 2018/06/05 8:59 http://seovancouver.net/

Wow! This could be one particular of the most useful blogs We ave ever arrive across on this subject. Basically Great. I am also an expert in this topic so I can understand your effort.

# dYyMjzdlInMkE 2018/06/05 12:45 http://vancouverdispensary.net/

What as Happening i am new to this, I stumbled upon this I ave found It absolutely useful and it has helped me out loads. I hope to contribute & assist other users like its aided me. Good job.

# riRUcKIpmCg 2018/06/05 16:31 http://vancouverdispensary.net/

you could have an awesome weblog here! would you wish to make some invite posts on my blog?

# ZOeSLjffmVVhC 2018/06/05 22:16 http://closestdispensaries.com/

You ought to really control the comments on this site

# OMdHzGBiEyIeYPinZh 2018/06/06 0:26 https://www.youtube.com/watch?v=zetV8p7HXC8

Major thankies for the article post.Really looking forward to read more.

# mJYCGzhAsy 2018/06/08 19:28 https://altcoinbuzz.io/south-korea-recognises-cryp

you have got an amazing blog here! would you wish to make some invite posts on my blog?

# AyIAaEJWOcTFb 2018/06/08 21:28 http://markets.financialcontent.com/sgvtribune/new

My brother recommended I might like this blog. He was entirely right. This post truly made my day. You can not imagine simply how much time I had spent for this information! Thanks!

# qbcHIkVpCsFWVSo 2018/06/08 23:15 https://topbestbrand.com/ฉี&am

Muchos Gracias for your post. Much obliged.

# fDNTXxApyKANEvuX 2018/06/09 3:40 https://www.prospernoah.com/nnu-income-program-rev

Im obliged for the blog article.Thanks Again. Fantastic.

# fvixARhMGg 2018/06/09 4:48 https://victorpredict.net/

magnificent points altogether, you just won a brand new reader. What may you suggest in regards to your publish that you made a few days ago? Any sure?

# rHoJebDogJ 2018/06/09 6:33 http://www.seoinvancouver.com/

We can no longer afford established veterans if they have interest in him than expected.

# XzjlJvSeMv 2018/06/09 10:27 http://www.seoinvancouver.com/

Im thankful for the blog article. Great.

# EBYdAjYUCahrD 2018/06/09 16:11 http://www.seoinvancouver.com/

I think this is a real great blog post.Much thanks again. Want more.

# SCvGaAiTsJALYsivYe 2018/06/10 5:34 http://www.seoinvancouver.com/

Thanks for some other great article. Where else may anyone get that type of information in such a perfect method of writing? I have a presentation next week, and I am on the look for such information.

# wlzBQyWijZ 2018/06/10 11:52 https://topbestbrand.com/เส&am

Very good article! We are linking to this particularly great post on our website. Keep up the great writing.

# oGMApHIUTTWbPV 2018/06/11 15:42 https://www.guaranteedseo.com/

Wow, superb blog layout! How long have you been blogging for? you make blogging look easy. The overall look of your web site is great, let alone the content!

# GESAiXoHgeMfUUPm 2018/06/11 18:14 https://topbestbrand.com/10-วิ

I truly appreciate this article post.Really looking forward to read more. Great.

# WQOAPZQskoxe 2018/06/12 20:50 http://closestdispensaries.com/

pretty practical stuff, overall I consider this is worth a bookmark, thanks

# cQgHlnFMOT 2018/06/13 0:47 http://naturalattractionsalon.com/

Real wonderful information can be found on weblog.

# SyOgNcurBPUaQQRPV 2018/06/13 2:45 http://www.seoinvancouver.com/

I think this is a real great post. Fantastic.

# JvcFrmkjloaGGswcX 2018/06/13 9:25 http://www.seoinvancouver.com/

Muchos Gracias for your post.Really looking forward to read more. Much obliged.

# vuClViEwWdHjPlzCurA 2018/06/13 11:20 http://www.seoinvancouver.com/

Whoa! This blog looks exactly like my old one! It as on a totally different subject but it has pretty much the same layout and design. Outstanding choice of colors!

# KYOtUWemgBhYNBBas 2018/06/13 19:55 http://hairsalonvictoriabc.com

I think this is a real great blog article.Really looking forward to read more. Keep writing.

# ELBrJlBlySuiDz 2018/06/13 21:54 https://www.youtube.com/watch?v=KKOyneFvYs8

Very soon this site will be famous among all blogging and

# RtueUwTiBkLbHf 2018/06/14 0:30 https://topbestbrand.com/ตก&am

My brother suggested I might like this blog. He was totally right. This post actually made my day. You cann at imagine just how much time I had spent for this information! Thanks!

# ZpLWriVlYYP 2018/06/15 2:21 https://www.youtube.com/watch?v=cY_mYj0DTXg

you are not more popular because you definitely have the gift.

# JBfWHbaoaHIyBVcJM 2018/06/15 13:36 http://tienlenmiennam.club/forum/profile.php?id=61

Perfect piece of work you have done, this site is really cool with superb info.

# xQCGDTzWlfbwDVQYA 2018/06/15 20:14 https://topbestbrand.com/เว&am

There is obviously a lot to realize about this. I assume you made various good points in features also.

# hWUcJbsGQa 2018/06/16 6:49 http://affordable-kitchens-and-b17161.blogocial.co

Im grateful for the article. Will read on...

# NwJfJuoteHiVP 2018/06/18 13:29 https://www.youtube.com/watch?v=zetV8p7HXC8

Spot on with this write-up, I honestly think this web site needs much more attention. I all probably be returning to see more, thanks for the information!

# ZRzFhxBraP 2018/06/18 15:28 https://www.techlovesstyle.com/about

I value the blog.Much thanks again. Great.

# UwWSHBcKTJwthoAb 2018/06/18 18:08 https://topbestbrand.com/รั&am

Very good blog post. I definitely appreciate this site. Stick with it!

# AIYeBmyfGyWdHp 2018/06/18 22:09 https://profiles.wordpress.org/tony03731/

Really appreciate you sharing this post.Much thanks again. Great.

# zUjqurMiaLOvY 2018/06/19 0:54 https://www.openstreetmap.org/user/jimmie1

I think other web site proprietors should take this website as an model, very clean and wonderful user friendly style and design, as well as the content. You are an expert in this topic!

# vYflzjiNRdJdw 2018/06/19 1:35 http://apk-game-pool.moonfruit.com

You are my aspiration , I possess few blogs and occasionally run out from to brand.

# JjSbbLCUZHBlEmlvA 2018/06/19 2:17 https://audioboom.com/users/5171158

The players a maneuvers came on the opening day. She also happens to be an unassailable lead.

# UFVnjyTcpIiryLa 2018/06/19 3:40 http://weepty.webstarts.com/

the home of some of my teammates saw us.

# DEMbknZPxe 2018/06/19 9:07 https://www.graphicallyspeaking.ca/

Wow, great article post.Much thanks again. Fantastic.

# SCWWNpuSaCJAVBB 2018/06/19 15:48 https://www.marwickmarketing.com/

You made some decent points there. I checked on the internet to learn more about the issue and found most individuals will go along with your views on this website.

タイトル  
名前  
Url
コメント