Module 11 Developing Message-Driven Beans

Similar documents
Java TM. Message-Driven Beans. Jaroslav Porubän 2007

133 July 23, :01 pm

Module 10 Developing Java EE Applications using Messaging

What s up with JMS 2.1?

Asynchrone Kommunikation mit Message Driven Beans

Example simple-mdb can be browsed at

Example Purchase request JMS & MDB. Example Purchase request. Agenda. Purpose. Solution. Enterprise Application Development using J2EE

Web Design and Applications

EJB 3.1 vs Contexts and Dependency Injection (CDI) and Dependency Injection for Java in Java EE 6. Jacek Laskowski.

EJB - DEPENDENCY INJECTION

Red Hat JBoss Enterprise Application Platform 7.0

Using Message Driven Beans.

Chapter 1 Introducing EJB 1. What is Java EE Introduction to EJB...5 Need of EJB...6 Types of Enterprise Beans...7

Red Hat JBoss Enterprise Application Platform 7.1

Basics of programming 3. Java Enterprise Edition

The Java EE 6 Tutorial

Communication Technologies MoM JMS.NET. Part VI. Message-Oriented Middleware

"Charting the Course... Mastering EJB 3.0 Applications. Course Summary

Reactive Java EE - Let Me Count the Ways!

Distributed Systems. Messaging and JMS Distributed Systems 1. Master of Information System Management

Deccansoft Software Services. J2EE Syllabus

Solace JMS Integration with JBoss Application Server EAP 6.2

Oracle Exam 1z0-895 Java EE 6 Enterprise JavaBeans Developer Certified Expert Exam Version: 14.0 [ Total Questions: 90 ]

Java Enterprise Edition

Enterprise JavaBeans, Version 3 (EJB3) Programming

Exam Questions 1Z0-895

Java EE 6: Develop Business Components with JMS & EJBs

Oracle EXAM - 1Z Java EE 6 Enterprise JavaBeans Developer Certified Expert Exam. Buy Full Product.

Enterprise JavaBeans 3.1

Oracle Banking APIs. Part No. E Third Party Simulation Guide Release April 2018

Fast Track to EJB 3.0 and the JPA Using JBoss

J2EE. Enterprise Architecture Styles: Two-Tier Architectures:

Module 8 The Java Persistence API

Enterprise Messaging With ActiveMQ and Spring JMS

Web Application Development Using JEE, Enterprise JavaBeans and JPA

EJB ENTERPRISE JAVA BEANS INTRODUCTION TO ENTERPRISE JAVA BEANS, JAVA'S SERVER SIDE COMPONENT TECHNOLOGY. EJB Enterprise Java

@Stateless. To avoid that use openejb.offline property and set it to true. See Server Configuration for more detail.

Enterprise JavaBeans

Distributed Systems/Middleware JMS

IBM Techdoc: Date last updated: 31-Aug-2016

Web Application Development Using JEE, Enterprise JavaBeans and JPA

Developing Message-Driven Beans for Oracle WebLogic Server c (12.1.3)

Web Applications 2. Java EE Martin Klíma. WA2 Slide 1

CO Java EE 7: Back-End Server Application Development

This page intentionally left blank

Developing a Basic JMS Application

SCBCD EXAM STUDY KIT. Paul Sanghera CX JAVA BUSINESS COMPONENT DEVELOPER CERTIFICATION FOR EJB MANNING. Covers all you need to pass

Oracle - Developing Applications for the Java EE 7 Platform Ed 1 (Training On Demand)

J2EE 1.4. Magnus Larsson. Callista Enterprise AB.

CHAPTER 3 SESSION BEANS

Struts: Struts 1.x. Introduction. Enterprise Application

OCP JavaEE 6 EJB Developer Study Notes

Vendor: Oracle. Exam Code: 1Z Exam Name: Java Platform, Enterprise Edition 6 Enterprise JavaBeans Developer Certified Expert Exam.

Enterprise Java Beans

Speakers qualifications

User Guide. The mom4j development team

Red Hat JBoss A-MQ 6.1

Java EE 7: Back-End Server Application Development

V3 EJB Test One Pager

EJB Development Using Borland JBuilder 6 and Borland Enterprise Server 5

Introduction... xv SECTION 1: DEVELOPING DESKTOP APPLICATIONS USING JAVA Chapter 1: Getting Started with Java... 1

Copyright UTS Faculty of Information Technology 2002 EJB2 EJB-3. Use Design Patterns 1 to re-use well known programming techniques.

Developing EJB Applications with Eclipse

Project Stage 3 Purchase order submission, invoice receipt and matching

Developing Applications for the Java EE 7 Platform 9-2

CONFIGURING A SPRING DEVELOPMENT ENVIRONMENT

JBoss to Geronimo - EJB-MDB Migration

[ ANATOMY OF A PROCESS IN ORACLE SOA SUTE] July 20, 2011

Java Programming Language

Topics. Advanced Java Programming. Legacy Systems and Java. Legacy Systems. Topics. Approaches

(800) Toll Free (804) Fax Introduction to Java and Enterprise Java using Eclipse IDE Duration: 5 days

Connecting Enterprise Systems to WebSphere Application Server

Module 3 Web Component

1. A developer is writing a Web service operation namedgetquote?select the proper code to obtain the HTTP Query String used in the request:

CHAPTER 1 FUNDAMENTALS

ITcertKing. The latest IT certification exam materials. IT Certification Guaranteed, The Easy Way!

Introduction to Programming Using Java (98-388)

Specialized - Mastering JEE 7 Web Application Development

2.0 Technical Description of the new features

Introduction to Messaging using JMS

Objects and Iterators

Deployment. See Packaging and deployment processes

JAVA RMI. Remote Method Invocation

JMS Frequently Asked Questions

IBM WebSphere Application Server. J2EE Programming Model Best Practices

CHAPTER 1 FUNDAMENTALS

java message service marek konieczny

BEAWebLogic. Event Server. Creating WebLogic Event Server Applications

JAC444 - Lecture 4. Segment 1 - Exception. Jordan Anastasiade Java Programming Language Course

JVA-163. Enterprise JavaBeans

CHAPTER 1 FUNDAMENTALS

Practice Test. Oracle 1z Java Enterprise Edition 5 Business Component Developer Certified Professional Upgrade Exam. Version: 14.

Introduction to Spring Framework: Hibernate, Web MVC & REST

<Insert Picture Here> Productive JavaEE 5.0 Development

Patterns and Best Practices for dynamic OSGi Applications

Figure 1: OpenJMS Integration using GenericJMS RA

preface xvii acknowledgments xix about this book xxi about the cover illustration 1.1 The challenge: solving the right problem right 5

Type of Classes Nested Classes Inner Classes Local and Anonymous Inner Classes

J2EE - Version: 25. Developing Enterprise Applications with J2EE Enterprise Technologies

COMP-202. Exceptions. COMP Exceptions, 2011 Jörg Kienzle and others

Transcription:

Module 11 Developing Message-Driven Beans Objectives Describe the properties and life cycle of message-driven beans Create a JMS message-driven bean Create lifecycle event handlers for a JMS message-driven bean 303 Ω Omega Ω 1

Introducing Message-Driven Beans Message-driven beans are intended as an asynchronous message consumer. Message-driven beans implement a message listener interface: For example, JMS message-driven beans implement the JMS API MessageListener interface. The bean designer is responsible for the message listener method code. The deployer supplies information for the container to register the message-driven bean as a message listener with the destination. 304 Ω Omega Ω Java EE Technology Client View of Message-Driven Beans Containers can create and pool multiple instances of messagedriven beans to service the same message destination. 305 Ω Omega Ω 2

Life Cycle of a Message-Driven Bean 306 Ω Omega Ω Types of Message-Driven Beans JMS message-driven beans: Are annotated with @javax.ejb.messagedriven and implement the javax.jms.messagelistener interface. Application server can integrate support or use connector. Non JMS message-driven beans: Are annotated with @javax.ejb.messagedriven and implement a message listener interface specific to the messaging service. Application server requires a connector. 307 Ω Omega Ω 3

Creating a JMS Message-Driven Bean 1. Declare the message-driven bean class: Class must be public but not final or abstract. 2. Annotate the message-driven bean class using the MessageDriven metadata annotation Specify values with the following attributes: activationconfig = { @ActivationConfigProperty(propertyName = "acknowledgemode, propertyvalue = "Auto-acknowledge ), @ActivationConfigProperty(propertyName = "destinationtype, propertyvalue = "javax.jms.queue") 308 Ω Omega Ω Creating a JMS Message-Driven Bean 3. Optionally, use resource injection to get a MessageDrivenContext instance. 4. Include a public no-argument empty constructor. 5. Write the onmessage method of the MessageListener interface. 6. Do not define a finalize method. 309 Ω Omega Ω 4

Message-Driven Bean Class Simple Example import javax.ejb.*; import javax.jms.*; @MessageDriven(mappedName = "jms/myqueue",activationconfig = { @ActivationConfigProperty(propertyName= "acknowledgemode", propertyvalue = "Auto-acknowledge"), @ActivationConfigProperty(propertyName = "destinationtype", propertyvalue = "javax.jms.queue") ) public class SampleMDB implements MessageListener { public void onmessage(message message) { 310 Ω Omega Ω Coding the Message-Driven Bean Class import javax.ejb.*; import javax.annotation.*; import javax.naming.*; import javax.jms.*; /** * The MessageBean class is a JMS message-driven bean. It * indirectly implements javax.jms.messagelistener interface. * It is defined as public (but not final or abstract). * It defines a constructor and the onmessage method. */ @MessageDriven { mappedname="destinationtype", messagelistenerinterface = javax.jms.messagelistener, activationconfig = { @ActivationConfigProperty(propertyName="messageSelector", propertyvalue="recipient = MDB ") 311 Ω Omega Ω 5

Coding the Message-Driven Bean Class import javax.ejb.*; import javax.annotation.*; import javax.naming.*; import javax.jms.*; /** * The MessageBean class is a JMS message-driven bean. It * indirectly implements javax.jms.messagelistener interface. * It is defined as public (but not final or abstract). * It defines a constructor and the onmessage method. */ @MessageDriven { mappedname="destinationtype", messagelistenerinterface = javax.jms.messagelistener, activationconfig = { @ActivationConfigProperty(propertyName="messageSelector", propertyvalue="recipient = MDB ") 312 Ω Omega Ω Coding the Message-Driven Bean Class public class MessageBean { @Resource private MessageDrivenContext mdc = null; // Constructor, which is public and takes no arguments. public MessageBean() { System.out.println( In MessageBean.MessageBean() ); // onmessage method, public not final or static // Casts the incoming Message to a TextMessage and displays // the text. public void onmessage(message inmessage) { TextMessage msg = null; try { if (inmessage instanceof TextMessage) { msg = (TextMessage) inmessage; 313 Ω Omega Ω 6

Coding the Message-Driven Bean Class System.out.println( MESSAGE BEAN: Message + received: + msg.gettext()); else { System.out.println( Message of wrong type: + inmessage.getclass().getname()); catch (JMSException e) { System.err.println( MessageBean.onMessage: + JMSException: + e); mdc.setrollbackonly(); catch (Throwable te) { System.err.println( MessageBean.onMessage: + Exception: + te); 314 Ω Omega Ω Complex Message-Driven Bean Classes Using message header message selectors @MessageDriven( activationconfig={ @ActivationConfigProperty( propertyname= messageselector, propertyvalue= JMSType= car AND color= blue AND weight>2500 ) ) Specifying message acknowledgement @MessageDriven( activationconfig={ @ActivationConfigProperty( propertyname= acknowledgemode, propertyvalue= Dups-ok-acknowledge ) ) 315 Ω Omega Ω 7

Callback Methods in a Bean Class import javax.ejb.*; import javax.jms.*; import javax.annotation.*; @MessageDriven public class MessageBean implements MessageListener { @Resource private MessageDrivenContext mdc; public MessageBean() { // constructor @PostConstruct void obtainresources() { @PreDestroy void releaseresources() { public void onmessage(message inmessage) { 316 Ω Omega Ω 8