What is Microsoft Message Queuing (MSMQ)? How does it work?

前端 未结 9 947
悲哀的现实
悲哀的现实 2021-01-30 04:05

I need to work with MSMQ (Microsoft Message Queuing). What is it, what is it for, how does it work? How is it different from web services?

相关标签:
9条回答
  • 2021-01-30 04:26

    Transactional Queue Management 101

    A transactional queue is a middleware system that asynchronously routes messages of one sort of another between hosts that may or may not be connected at any given time. This means that it must also be capable of persisting the message somewhere. Examples of such systems are MSMQ and IBM MQ

    A Transactional Queue can also participate in a distributed transaction, and a rollback can trigger the disposal of messages. This means that a message is guaranteed to be delivered with at-most-once semantics or guaranteed delivery if not rolled back. The message won't be delivered if:

    • Host A posts the message but Host B is not connected

    • Something (possibly but not necessarily initiated from Host A) rolls back the transaction

    • B connects after the transaction is rolled back

    In this case B will never be aware the message even existed unless informed through some other medium. If the transaction was rolled back, this probably doesn't matter. If B connects and collects the message before the transaction is rolled back, the rollback will also reverse the effects of the message on B.

    Note that A can post the message to the queue with the guarantee of at-most-once delivery. If the transaction is committed Host A can assume that the message has been delivered by the reliable transport medium. If the transaction is rolled back, Host A can assume that any effects of the message have been reversed.

    Web Services

    A web service is remote procedure call or other service (e.g. RESTFul API's) published by a (typically) HTTP Server. It is a synchronous request/response protocol and has no guarantee of delivery built into the protocol. It is up to the client to validate that the service has been correctly run. Typically this will be through a reply to the request or timeout of the call.

    In the latter case, web services do not guarantee at-most-once semantics. The server can complete the service and fail to deliver a response (possibly through something outside the server going wrong). The application must be able to deal with this situation.

    IIRC, RESTFul services should be idempotent (the same state is achieved after any number of invocations of the same service), which is a strategy for dealing with this lack of guaranteed notification of success/failure in web service architectures. The idea is that conceptually one writes state rather than invoking a service, so one can write any number of times. This means that a lack of feedback about success can be tolerated by the application as it can re-try the posting until it gets a 'success' message from the server.

    0 讨论(0)
  • 2021-01-30 04:26

    MSMQ- Microsoft Message Queuing:
    • MSMQ is a message queue implementation developed by Microsoft.
    • It deployed in its Windows Server operating systems.
    • It is a messaging protocol that allows applications running on separate servers/processes to communicate in a failsafe manner.
    • MSMQ has commonly been used in enterprise for software built.
    • MSMQ ensures reliable delivery by placing messages that fail to reach their intended destination in a queue and then resending them once the destination is reachable.
    • MSMQ also supports transactions. It permits multiple operations on multiple queues, with all of the operations wrapped in a single transaction, thus ensuring that either all or none of the operations will take effect.
    • Message Queuing (MSMQ) technology enables applications running at different times to communicate across heterogeneous networks and systems that may be temporarily offline.
    The following ports are used for Microsoft Message Queuing operations:
    • TCP: 1801
    • RPC: 135, 2101*, 2103*, 2105*
    • UDP: 3527, 1801

    0 讨论(0)
  • 2021-01-30 04:27

    As its name states, it's just a queue manager.

    You can Send objects (serialized) to the queue where they will stay until you Receive them. It's normally used to send messages or objects between applications in a decoupled way

    It has nothing to do with webservices, they are two different things

    Info on MSMQ:

    https://msdn.microsoft.com/en-us/library/ms711472(v=vs.85).aspx

    Info on WebServices:

    http://msdn.microsoft.com/en-us/library/ms972326.aspx

    0 讨论(0)
  • 2021-01-30 04:33

    Actually there is no relation between MSMQ and WebService. Using MSMQ for interprocess communication (you can use also sockets, windows messaging, mapped memory). it is a windows service that responsible for keeping messages till someone dequeue them. you can say it is more reliable than sockets as messages are stored on a harddisk but it is slower than other IPC techniques.

    You can use MSMQ in dotnet with small lines of code, Just Declare your MessageQueue object and call Receive and Send methods. The Message itself can be normal string or binary data.

    0 讨论(0)
  • With all due respect to @Juan's answer, both are ways of exchanging data between two disconnected processes, i.e. interprocess communication channels (IPC). Message queues are asynchronous, while webservices are synchronous. They use different protocols and back-end services to do this so they are completely different in implementation, but similar in purpose.

    You would want to use message queues when there is a possibility that the other communicating process may not be available, yet you still want to have the message sent at the time of the client's choosing. Delivery will occur the when process on the other end wakes up and receives notification of the message's arrival.

    0 讨论(0)
  • 2021-01-30 04:39

    Note that you can use Windows Communication Foundation (WCF) as an abstraction layer above MSMQ. This gives you the feel of working with a service - with only one-way operations.

    For more information, see: http://msdn.microsoft.com/en-us/library/ms789048.aspx

    --larsw

    0 讨论(0)
提交回复
热议问题