grate đậu doanh nghiệp với các gói và các ứng dụng di sản. Chương 6 thảo luận về phương pháp này hơn nữa. • Khi bạn muốn giao hàng nhắn tin để lái xe các sự kiện khác trong hệ thống. Ví dụ, các bước công việc có thể được dựa trên thực tế chỉ cung cấp tin nhắn, hoặc họ có thể dựa trên nội dung tin nhắn. | MESSAGE-DRIVEN BEANS 155 grate enterprise beans with packages and legacy applications. Chapter 6 discusses this approach further. When you want the message delivery to drive other events in the system. For example workflow steps can be based on the mere fact of message delivery or they can be based on the message content. When you want to create message selectors. A message selector is designed to take on only specific messages thus making it possible to use message-driven beans as triggers. Example Invoice Message-Driven Bean Code Example shows a message-driven bean that updates purchase orders based on invoice information received in a JMS message. The message-driven bean listens for JMS messages containing invoice data. When it receives a message its onMessage method extracts the invoice data from the message text. In this example the data has been encoded in XML which is parsed and then used to process an invoice. public class InvoiceMDB implements MessageDrivenBean MessageListener public void onMessage Message msg try String msgTxt TextMessage msg .getText Invoice invoice msgText do further processing catch . handle exceptions Code Example Message-Driven Bean Example 156 CHAPTER 5 THE ENTERPRISE JAVABEANS TIER Design Guidelines While you are free to write your application and enterprise bean code according to your own needs we do recommend certain guidelines. Keep the code in enterprise beans as client-neutral as possible. Enterprise beans are meant to contain business logic that can be used by many client types. Methods in enterprise beans that serve only one client type make any logic within that method inaccessible to other client types. Code that is specific for a particular client type belongs with the software managing that client type. In particular Web-tier and HTTP-related functions and data do not belong in an enterprise bean. Keep as much business logic as possible in the EJB tier. By doing so you take advantage of