Chapter 23 874 Loosely-Coupled Systems Another good use for messaging in enterprise applications is to loosen the connection between parts of the program. In a loosely-coupled system, when one part of the system malfunctions it does not crash the rest of the system. In the online store example, if the ShoppingCart bean makes a procedure call to the InventoryManagement bean and the InventoryManagement bean has a bug that causes the bean to crash, then the ShoppingCart bean will also be affected by the problem. It might also crash and the customer won't get the items he ordered. However, if the ShoppingCart bean sends a message instead of making a procedure call it is not immediately affected by the InventoryManagement bean's failure. The ShoppingCart continues with its processing. The inventory count is incorrect but at least the ShoppingCart got the customer checked out. When the web shop's employees notice the InventoryManagement bean crash, they have a chance to correct the entries in the inventory item database. As well as making the program more robust, the loose coupling between parts of the program simplifies development. The parts of the application become more independent. Because of this independence a team working on one part of the program is less likely to cause a problem in another part of the program. Also, communication problems between two parts of the program are more easily isolated. Enterprise Application Integration A third common use of messaging is for the connection of two independent systems, even two systems written in different languages. Two systems written in different languages cannot make procedure calls to each other, but if a vendor creates a messaging system that enables them to send messages to each other they can write messages that are equivalent to making procedure calls. A product that allows systems written in different languages to communicate is called an Enterprise Application Integration (EAI) product. EAI products can even be used to connect legacy systems to new systems. For example, a legacy program written in C or FORTRAN may be web-enabled using messaging. Developers can use Java to write the web interface and messaging to retrieve data to display on the Web from the legacy system. We discuss legacy integration and EAI products more in the "Legacy Integration" section of this chapter. A Common Messaging Model In the most common messaging model there is a message broker that acts as an intermediary for all messages. Both the message sender and the message recipient are clients of the message broker. The message sender is called the message producer. The message recipient is called the message consumer. In the e-mail example the person who writes the e-mail is the message producer and the person who receives it is the message consumer. The e-mail server is the message broker. The following figure shows the message broker model: