473,545 Members | 1,759 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

When and Where I should use MSMQ?

Hi all,
Where is the MSMQ use for? For example, I have a client program to control
the database and how can I use MSMQ in my program? When I should use it?
For example I have a method to insert new record to the database and how can
I use MSMQ in this method?
Nov 16 '05 #1
10 18236
MSMQ is typically used when you need to provide message-oriented
communication somewhere in a system. I typically use it when I'm developing
a truly asynchronous app, and I need to transactionally accept messages and
queue them up for a receiver.

But aren't you putting the cart before the horse? If you need MSMQ, use it.
It's really not the sort of thing where you look for a way to use it in the
app before establishing a need.
--
Mickey Williams
Author, "Visual C# .NET Core Ref", MS Press
www.neudesic.com
www.servergeek.com

"Jet Leung" <xi**@tom.com > wrote in message
news:es******** *****@TK2MSFTNG P14.phx.gbl...
Hi all,
Where is the MSMQ use for? For example, I have a client program to control
the database and how can I use MSMQ in my program? When I should use it?
For example I have a method to insert new record to the database and how can I use MSMQ in this method?

Nov 16 '05 #2
> > Where is the MSMQ use for? For example, I have a client program to
control
I've also wondered about this.

Would a typical example be the pattern where you register on a website, and
after you hit the Register button, it sends you an email sometime later on
with an autogenerated password to the email you indicated in your
registration? Is that one example of using a message queue?
Nov 16 '05 #3
Yes
Nov 16 '05 #4
"Flip" <[remove]ph******@hotmai l.com> wrote in message
news:OG******** *****@TK2MSFTNG P12.phx.gbl...
> Where is the MSMQ use for? For example, I have a client program to

control
I've also wondered about this.

Would a typical example be the pattern where you register on a website,
and
after you hit the Register button, it sends you an email sometime later on
with an autogenerated password to the email you indicated in your
registration? Is that one example of using a message queue?


Yes indeed, and it's the "sometime later" in your post which is important.
E.g. if you have an eCommerce system where people can purchase goods with a
credit card, you will typically want to authorise the purchase in real-time
and provide a response to the customer in as close to real-time as possible
i.e. your purchase has been authorised, your bank has declined the
transaction etc. That would not be a good candidate for MSMQ because you
don't actually want to queue this message up - you want to tell the person
there and then.

However, your warehouse might arrange the packaging and dispatch of goods
all through the day but only send out the dispatch notification emails as a
batch process through the night when the site is less busy, so that part of
the process would be a prime candidate for MSMQ because the clients don't
really need to know the precise minute that their goods were dispatched.
Nov 16 '05 #5
Cool, so I'm on the right track then. Thanks! :>
Nov 16 '05 #6
The canonical exmaple is an ecomerce website where you want to verify the order in terms of stock and credit card clearance. So you make the user wait until you have verified these and give them a confirmation number (and maybe send an email). However, the dispatch of the product needs to go to the shipping department who only work 9-5 maybe. So you can't make the user wait for the shipping department to OK the order being shipped, SO you queue the shipping request on to a reliable queue (one that won't lose its state if the machine crashes) like MSMQ or MQSeries and the shipping department dequeue the messages in the morning when they come into work.

Regards

Richard Blewett - DevelopMentor
http://staff.develop.com/richardb/weblog

nntp://news.microsoft. com/microsoft.publi c.dotnet.langua ges.csharp/<OG************ *@TK2MSFTNGP12. phx.gbl>
Where is the MSMQ use for? For example, I have a client program to

control
I've also wondered about this.

Would a typical example be the pattern where you register on a website, and
after you hit the Register button, it sends you an email sometime later on
with an autogenerated password to the email you indicated in your
registration? Is that one example of using a message queue?

---
Incoming mail is certified Virus Free.
Checked by AVG anti-virus system (http://www.grisoft.com).
Version: 6.0.770 / Virus Database: 517 - Release Date: 27/09/2004

[microsoft.publi c.dotnet.langua ges.csharp]
Nov 16 '05 #7
Jon
One use of MSMQ is to get round the performance hit of writing a record to
database or disk. These operations (relatively speaking) are quite slow.
However, if you have an object containing data you wish to persist in this
way, you can dump it on a queue and have a separate "receiver" program which
will read the objects off the queue and write them to wherever they should
go.

When creating a message queue, I believe you can specify whether or not the
messages written should be recoverable in the event of a reboot or crash -
obviously if they are, then it takes longer to write them onto the queue in
the first place, but it is still faster than writing to database.

Jon

"Jet Leung" <xi**@tom.com > wrote in message
news:es******** *****@TK2MSFTNG P14.phx.gbl...
Hi all,
Where is the MSMQ use for? For example, I have a client program to control
the database and how can I use MSMQ in my program? When I should use it?
For example I have a method to insert new record to the database and how can I use MSMQ in this method?

Nov 16 '05 #8
Hi,
Sorry,I can't clearly get what your mean. Could you give me an
example code?
As you said, if an object include data, I can send the object on
queue right? So if I have an dataset or only a command object how can I
send it on queue? After I send it on queue and the revicer get it how
does the revicer know how to handler these data?
e.g an dataset just send it on queue is ok?
e.g an command object how to send it on queue?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!
Nov 16 '05 #9
Jon
We do it something like this:

To add item to queue:

MessageQueue queue = new MessageQueue(pa th);
queue.DefaultPr opertiesToSend. Recoverable = false;
queue.DefaultPr opertiesToSend. Priority = MessagePriority .Normal;
queue.Formatter = new BinaryMessageFo rmatter();
queue.Send(myob ject);

Note that "myobject" must be serializable for this to work.

When reading from the queue you can do it synchronously or asynchronously -
depends on your app. If you have a dedicated app reading a single queue you
could go for synchronously. We have a dedicated app but it reads multiple
queues, so we use the asynchronous method which. This, however, is how to do
it synchronously:

MessageQueue queue = new MessageQueue(pa th);
queue.Formatter = new BinaryMessageFo rmatter();
Object received = queue.Receive() ;

At this point, you can determine what type of object you are dealing with
using the normal is, as or casting methods (eg "if (received is MyClass)"
etc. You can then take the appropriate action for the specific object you
have received.

Looking at MSDN, DataSet is marked as serializable so I don't see why this
wouldn't work with that. SqlCommand isn't serializable so it wouldn't work
(what would be your aim in doing this, as I can't think of a use for it?).

Hope this helps,
Jon

"Jet Leung" <xi**@tom.com > wrote in message
news:Oz******** ******@TK2MSFTN GP10.phx.gbl...
Hi,
Sorry,I can't clearly get what your mean. Could you give me an
example code?
As you said, if an object include data, I can send the object on
queue right? So if I have an dataset or only a command object how can I
send it on queue? After I send it on queue and the revicer get it how
does the revicer know how to handler these data?
e.g an dataset just send it on queue is ok?
e.g an command object how to send it on queue?

*** Sent via Developersdex http://www.developersdex.com ***
Don't just participate in USENET...get rewarded for it!

Nov 16 '05 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
1286
by: bettina | last post by:
On my server I have all my site under /public_html... where should I put my DB?
5
8613
by: Kevin | last post by:
Dear all, Could you please advise where should I put the Oracle JDBC driver (classes12.zip or classes12.jar) under Windows XP with Tomcat 4.1? Do I need to set classpath? Many thanks. Kevin.
3
1653
by: Zhigang Cui | last post by:
Hi, When I saw 'global static', the first response was there was no such term. But I realized it's an idiom later. When we learn C language, when we study C standard, when we study compiler, we use 'linkages of identifiers', 'storage-class specifier'. One of my friends said maybe we could use 'local static', :-) Who could tell me...
1
939
by: Kachna | last post by:
I have the Visual C++ 6.0, and where should I start? Is there any tutorial explaining Windows API functions, its' arguments, and so on? So that I will gain some base knowledge?
5
1781
by: ypul | last post by:
the code below given is connection class ... now I want to use the connection in another class , by using the getConnection method. where should I call con.dispose() ? in connection class or in the caller class ? if I call con.dispose in connection class as given below ..will I be able to use the connection in the other class where I am...
4
1055
by: Umut Tezduyar | last post by:
I have generated a control that simpifies most of the layout problems that asp.net 1.1 and 1.0 face. I want to submit it to microsoft for the investigation. Does anybody know where should I submit my control?
3
1808
by: CCJohn | last post by:
Hi, I find that while I can use the "Namespace...End Namespace" inside my code, there is also a "Root namespace" field in the project properties dialog box under General. So where should I put my REAL root namespace, or should I leave it blank, or should I create any at all? Please advice. Thanks in advance. CCJohn
9
2899
by: vivekian | last post by:
Have a couple of global variables of a class type which i have declared and defined in the application. 1. Not sure where should the global variables be placed ? 2. Would i need to forward declare the class before the global variable is declared ? Thanks, vivekian
6
5470
by: kentdahlgren | last post by:
Hi, I have a rather advanced MS Access 2002 solution where I use the RecordsAffected property of the Execute method for a Querydef. I’m using it all over the solution and it has worked as expected for years. Suddenly it does not in parts of the code, since it returns zero even when it should not. In the example below the record is there in...
1
1305
by: shapper | last post by:
Hello, On my ASP.NET MVC project I create ViewData classes to pass information from the controller to the view. Where should I place the view data classes? Since they kind of reshape the classes created by the LINQ to SQL I added them do the models. Not sure if this is the best place to add these classes or even the best way to do this.
0
7467
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main...
0
7401
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language...
0
7656
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
1
5326
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
4944
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
0
3450
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in...
0
3442
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
1879
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1014
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.