While using synchronous calling mechanism, is there any reason where we should use MOM instead of RMI?
There is only one: non-technical managers influenced by certain sales-people love a certain MOM product... ;-)
Usually there are no asynchronous situations in computing: mostly there is a user waiting for the computer's reaction (an exception is the user doing something different while waiting for an email, which is an asynchronous situation).
Of course there is a certain load-balancing done by queuing within the socket layer, but this is not the application layer's business (as it were if you used MOM).
And does MOM do marshalling for you?
I disagree with Juergen's assertion that there are usually no asynchronous situations in computing. This might be (not neccesarily) true from a user's perspective, but there is much more to software than what the user sees. Asynchronous communication is usefull for a variety of circumstances, such as:
- observer/observable patterns: update local caches, react according to some business logic to changes in an entity, alert user/administrator/perform logging.
- managed concurrent execution: a useful way to generate concurrent processing of a request by multiple components in a managed environment is to invoke them asynchronously.
- decouple component instances/implementations through the use of a queue/topic.
That said, MOM is not a magic charm that you should use whenever you need communication. Use MOM when you need one of it's inherent advantages (such as the ones listed above). If you don't need them, RMI (or a different synchronous approach) would probably be simpler to implement and provide the same level of functionality.
Most of the MOMs can do data transformation. Few of their transformation capabilities are out-of-the-box and they might name it as 'adapters'.
Few instances where MOMs are used over RMI are:
- Guaranteed message delivery for a Reqest/Reply operation is still not sufficient to achive the business needs (this sounds bad !!??).
- Need for introspecting the synchronous messages/operations. Just as Gal Binyamini has put, implementing specific design patterns, over a evolving system, can become more complex with RMI.
- Systems involved in the synchronous operations keep changing and the transformation logic for making meaningful conversions are predicted to become complex.
If the synchronous activity takes more time than the JTA timeout period, EJBs would timeout. So, RMI might not be a good choice. Yet, this still doesn't demand the usage of MOMs.
The funny part is that not all the MOMs are XA compliant. So, their support for 'Request/Reply' functionality could still be insufficent for implementing a resilient, yet fault-tolerant, system.