主婦と.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?

# lZPyOAedPVsVxgO 2014/08/29 10:18 http://propertyduniyahub.blogspot.in/

Heya i'm for the first time here. I found this board and I find It really useful & it helped me out a lot. I hope to give something back and help others like you aided me.

# ZdeVWhosDttD 2014/08/29 11:46 http://www.fastinsuranceagents.com

Thanks for sharing, this is a fantastic article.Thanks Again. Really Great.

# lUbkfXcEMxcZ 2014/08/29 14:42 http://www.fiverr.com/ioliru/submit-200-search-eng

This is one awesome blog post.Much thanks again. Keep writing.

# NcUYHJozxGcVmrOPt 2014/08/29 20:18 http://www.nicolasandasp.com

Appreciate you sharing, great article post. Keep writing.

# JHLuvNRfirXBrjbG 2014/08/29 20:20 http://criminallawyersottawa.com

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

# uaAsaXMjaQV 2014/08/29 22:08 http://criminallawyersottawa.com

Well I definitely liked studying it. This post provided by you is very useful for proper planning.

# PANJSSXsNbbPgFSsPJ 2014/08/31 0:05 https://www.youtube.com/watch?v=CX-BtyBKO8Q

I just could not depart your web site before suggesting that I actually enjoyed the standard information a person provide for your visitors? Is gonna be back often to check up on new posts

# YoUOyvcLkZM 2014/08/31 3:49 http://www.appsforlumia.com

fantastic post, very informative. I wonder why the other experts of this sector do not notice this. You must continue your writing. I'm sure, you have a great readers' base already!

# PPMoVZooUnHlh 2014/09/01 19:50 https://www.youtube.com/watch?v=dP_QhySt2gY

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

# iHAhiZnTltcaNDE 2014/09/02 1:56 http://www.organic-organic.com

Hey, thanks for the blog.Much thanks again. Great.

# kPhLdJrOFJRSrCGskNm 2014/09/02 19:18 http://www.botaniquebartley.info/

Fantastic post but I was wondering if you could write a litte more on this topic? I'd be very grateful if you could elaborate a little bit more. Kudos!

# RtQjnEliOEQahXVodjY 2014/09/02 19:23 http://www.gigasize.com/get/j1wr9j3yx3c

I am so grateful for your article post.Much thanks again. Really Great.

# yXLjVutwJGzHB 2014/09/02 20:36 https://www.youtube.com/watch?v=KLiKPsOc22A

Hi, i think that i saw you visited my blog so i came to ???return the favor???.I am attempting to find things to enhance my web site!I suppose its ok to use a few of your ideas!!

# TWEPzBgtOxNhRE 2014/09/02 21:55 http://imle.info/story.php?title=coaching-supplies

Really informative blog post. Want more.

# gIlFFqpCOeOJT 2014/09/03 20:13 https://www.youtube.com/watch?v=ietNoQGnfas

whoah this blog is great i like reading your articles. Stay up the good paintings! You realize, lots of people are searching round for this information, you can aid them greatly.

# wRfWAjnVMOX 2014/09/03 21:33 https://www.youtube.com/watch?v=cTkBiqmO3cs

I'm still learning from you, while I'm trying to reach my goals. I absolutely liked reading everything that is written on your website.Keep the stories coming. I loved it!

# xKVqEoIzaZJ 2014/09/04 19:21 http://pauses.ru/memberlist.php?mode=viewprofile&a

I really like and appreciate your article post.Really looking forward to read more. Awesome.

# HiNYITiytVvMorCIe 2014/09/05 20:49 http://alpenforum.forumsmotion.com/f1-forum

Hi, i believe that i saw you visited my weblog so i came to ???go back the choose???.I'm trying to find issues to improve my site!I suppose its good enough to use some of your ideas!!

# yzLyBFHOgb 2014/09/06 20:18 http://www.super-man-u.com

Hey there, You have done an incredible job. I'll definitely digg it and for my part recommend to my friends. I am confident they'll be benefited from this web site.

# bbbOHoqrMkDhlbKUEfJ 2014/09/06 21:38 http://metrocontests.com

F*ckin' amazing things here. I'm very satisfied to peer your post. Thanks a lot and i am looking forward to touch you. Will you kindly drop me a e-mail?

# aPAyCbJlRrQmLomEOBZ 2014/09/07 0:36 http://inductioncookwaresets.com/

Very neat article.Much thanks again. Keep writing.

# rxBALgWRXMyvhMh 2014/09/07 3:41 http://appliancespart.net/

Really appreciate you sharing this post. Awesome.

# bKTSDbnzaohSWMB 2014/09/08 23:59 http://blog.ideafit.com/blogs/waqar-hassan/what-ty

A round of applause for your post.Really looking forward to read more. Want more.

# AdDNxrtsiz 2014/09/09 0:48 http://www.everytrail.com/view_trip.php?trip_id=29

Major thanks for the post.Really looking forward to read more.

# JJooNaEfSxTOzwzTnLS 2014/09/09 8:19 http://ecommerce-investments.com/luis-souto/

Really appreciate you sharing this article.Really looking forward to read more. Much obliged.

# teoRCZTbAG 2014/09/09 12:56 http://vente-sur-internet.com/luis-souto/

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

# IxhUGOjnwVLAhItXG 2014/09/09 16:43 http://grsu4.info/story.php?id=90597

Really appreciate you sharing this post.Really looking forward to read more. Awesome.

# QhoHTdXtEtiffxnxsc 2014/09/09 19:37 http://www.arrasproperties.com/category/properties

I have fun with, result in I found exactly what I used to be having a look for. You've ended my four day long hunt! God Bless you man. Have a great day. Bye

# SAjIqbGsMxG 2014/09/09 21:50 http://www.designingdigitally.com

There is noticeably a bundle to learn about this. I assume you made sure good factors in features also.

# xvihQZsmqiDCRUT 2014/09/09 23:38 http://www.3dseriousgames.com

Awesome blog article.Thanks Again. Want more.

# bNWYgCYbkcAkYjV 2014/09/10 17:44 http://tiny.cc/goldenskinzuerich

I am so grateful for your article post.Really looking forward to read more. Great.

# oysURjfJUZss 2014/09/10 17:59 https://www.youtube.com/watch?v=6l8bpZ0oY_M

Thanks for another wonderful article. Where else could anybody get that type of info in such an ideal method of writing? I've a presentation next week, and I am on the look for such information.

# FFmwTSDYSyiDHnQsVj 2014/09/10 18:07 http://selfsoul.info/story/82779

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

# ylINUFmoeucNMpuMTzq 2014/09/11 12:16 http://www.rateniagara.com/story.php?title=quick-h

Muchos Gracias for your article. Keep writing.

# FuNwZBdVlkva 2014/09/11 15:27 http://freeticketopen.com/story.php?title=sophia-h

I value the blog post.Much thanks again. Much obliged.

# GunfQdvtRskY 2014/09/11 17:00 http://www.lady-susanna.ru/user/Treparahakse3m/

Thanks a lot for the post.Thanks Again. Awesome.

# YKqTkyUjXLpxhJfuFF 2014/09/11 18:01 http://swiss-vps.com/products/windows-vps/

I have been absent for some time, but now I remember why I used to love this web site. Thanks , I will try and check back more often. How frequently you update your website?

# jBPZcuDBDuoRNCJJhrj 2014/09/11 20:55 http://www.ukessays.com

I'm curious to find out what blog platform you have been utilizing? I'm having some small security problems with my latest website and I'd like to find something more safe. Do you have any solutions?

# dFjwjQLzbwpeKtCww 2014/09/11 22:09 http://viralquake.com/category/weird/

Looking forward to reading more. Great article post. Really Great.

# XIwxweBMMG 2014/09/12 0:56 http://www.bookjetty.com/forums/6/topics/71696?pos

Really appreciate you sharing this blog post.Really looking forward to read more. Want more.

# TTrfNNzYjjbywrpVG 2014/09/12 4:56 http://auction-your.com/browse-categories

Really appreciate you sharing this post. Much obliged.

# vPaWKIXSYvjHWw 2014/09/12 6:58 http://fondartema.com/index/8-7461

Thanks-a-mundo for the article post.Thanks Again. Fantastic.

# suguIxRgoY 2014/09/12 21:55 http://social.xfire.com/blog/groove3582/10568332/

fantastic post, very informative. I ponder why the other experts of this sector don't realize this. You should continue your writing. I am sure, you've a huge readers' base already!

# KShwMOuyODHBeSY 2014/09/12 23:56 http://www.myfilmebi.net/user/papycoedinidep/

Great, thanks for sharing this post. Great.

# AvRGoleRrpmAvYgSX 2014/09/13 1:30 http://munservis.mirniy.ru/user/nipayaybdrunab/

I think this is a real great blog. Fantastic.

# xurHQoFeTTjWAmHaB 2014/09/13 3:03 http://kinowarez.com/user/egyirnarnbuooy/

Thanks a lot for the blog article.Thanks Again. Much obliged.

# HdCoUymtnO 2014/09/13 17:05 https://www.youtube.com/edit?video_id=CSuUco_72Vs

Usually I don't read article on blogs, however I wish to say that this write-up very pressured me to take a look at and do so! Your writing taste has been surprised me. Thanks, very great article.

# UtpuxWJTFtnbfp 2014/09/15 7:33 http://ava-pskov.ru/index.php?subaction=userinfo&a

Looking forward to reading more. Great blog article.Thanks Again. Much obliged.

# RSOmYubZfgLIYLup 2014/09/15 11:21 http://www.theboatonlinestore.com/

F*ckin' remarkable issues here. I'm very glad to peer your post. Thanks a lot and i'm taking a look forward to contact you. Will you please drop me a mail?

# eDQDneFLVe 2014/09/15 16:06 http://httpdoolations.info/story/18780

Im grateful for the article.Thanks Again. Keep writing.

# FhtnCQMtflcLFJDiG 2014/09/15 19:01 https://www.youtube.com/watch?v=TwvstEk_Ljg

Thanks again for the article post. Fantastic.

# 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.

# QpkskyLyLIXWIO 2014/09/17 0:49 http://giveaways.xyz

Awesome blog article.Much thanks again. Will read on...

# SRNRtjzArxjfqC 2014/09/17 16:53 http://www.1818-888.com

It's arduous to search out educated individuals on this subject, however you sound like you know what you're talking about! Thanks

# MOslMSZfpZszcF 2014/09/17 18:38 https://local.amazon.com/deals/B00NF3NXH6

Hi there, I found your web site by means of Google even as looking for a similar subject, your web site got here up, it seems to be great. I've bookmarked it in my google bookmarks.

# BPhxYAGdpfqVBUMrDoo 2014/09/17 22:06 http://youtu.be/pJYaev2gZYc

I was recommended this website by my cousin. I am not sure whether this post is written by him as nobody else know such detailed about my trouble. You're incredible! Thanks!

# JpXliBuGKBQgUB 2014/09/17 22:11 http://khashut.ru/index/8-22196

I loved your article. Will read on...

# mcDWxQkpOmWQHSWf 2014/09/18 12:06 http://cathugger.com/sharkchurch77/blog/the-need-f

Hey, thanks for the blog post. Want more.

# sMFTzVLGdTJra 2014/09/18 16:22 http://youtu.be/VI1nFVEsujo

Definitely, what a fantastic site and revealing posts, I definitely will bookmark your website.Best Regards!

# 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.

# vIYzjJWwGAMcO 2014/09/18 19:59 http://www.sotka.tu1.ru/board/tools.php?event=prof

Thanks a lot for the post.Much thanks again. Awesome.

# KIkafRxXgqJwg 2014/09/19 0:13 http://youtu.be/9im_Z9iN_XA

I truly appreciate this blog article.Thanks Again. Keep writing.

# ルイ ヴィトン 財布 ランキング 2016/11/22 1:19 ryrvrwa@docomo.ne.jp

ブランド通販店(*^-^*)
スーパーコピーブランドメンズレディースファッション時計バッグ財布を海外通販!
スーパーコピーブランド激安ショッピングサイトです。
送料無料(日本全国)!
サポート体制も万全です。スタイルが豊富で。
最新作も随時入荷いたしております。
ご安心購入くださいませ。
ルイ ヴィトン 財布 ランキング http://www.newkakaku.com/xinq6.htm

タイトル  
名前  
Url
コメント