Module 6 Message-Driven Beans. History Introduced in EJB 2.0 –Supports processing of asynchronous messages from a JMS provider Definition expanded in.

Slides:



Advertisements
Similar presentations
J0 1 Marco Ronchetti - Basi di Dati Web e Distribuite – Laurea Specialistica in Informatica – Università di Trento.
Advertisements

16 Copyright © 2005, Oracle. All rights reserved. Developing Message-Driven Beans.
11 Copyright © 2005, Oracle. All rights reserved. Creating the Business Tier: Enterprise JavaBeans.
Copyright © 2012, Oracle and/or its affiliates. All rights reserved. Insert Information Protection Policy Classification from Slide 13 1.
Enterprise JavaBeans 2.0 Wu Lu (Cont’d). EJB2.0 Query Language EJB QL is a declarative language similar in many respects to SQL Is intended to be portable.
A Study in JMS (Java Messaging Service) Chad Beaudin CS 522 Fall Semester 2002.
1 James Lynn Hewlett-Packard Middleware Division EJB Architecture Design Strategies and Performance Optimizations.
Introduction to Enterprise JavaBeans. Integrating Software Development Server-side Component Model Distributed Object Architecture –CORBA –DCOM –Java.
Java Messaging Service Notes prepared from GBC Professional Development Seminar :Understanding the Java Messaging Service David Chappell & Rick Kuzyk,
A Study in JMS (Java Messaging Service) Chad Beaudin CS 522 Fall Semester 2002.
Module 5 Session Beans. Topics to be Covered: Purpose and Types of Session Beans Stateless Session Beans Stateful Session Beans Session Bean Design Deployment.
Java Message Service API CSE 487/587 Feb 17, 2005 References: JRun Programmer’s Guide.
JMS Java Message Service Instructor Professor: Charles Tappert By Student: Amr Fouda.
ECSE Software Engineering 1I HO 7 © HY 2012 Lecture 7 Publish/Subscribe.
Enterprise Java Beans (EJB)
EEC-681/781 Distributed Computing Systems Lecture 6 Wenbing Zhao Department of Electrical and Computer Engineering Cleveland State University
J2EE Kenneth M. Anderson CSCI Web Technologies October 3, 2001.
Introduction to EJB INFORMATICS ENGINEERING – UNIVERSITY OF BRAWIJAYA Eriq Muhammad Adams J
Sending and receiving XML in a Java application Sean C. Sullivan sean seansullivan com September 2003.
Messaging in Java Rafał Witkowski Marek Kałużny.
EJB Fundamentals Celsina Bignoli
1 The JNDI ENC and Injection Every EJB container that is deployed in an application server has its own personal internal registry called the Enterprise.
1 Security Most Java EE applications need to provide identity to users who access them and security for that access. Applications may want to prevent hostile.
Ing. Ignacio Roqueta ARTech GeneXus and J2EE.
Java Message Service - What and Why? Bill Kelly, Silvano Maffeis SoftWired AG, Zürich
Enterprise JavaBeans EJB Container Services. EJB container Enterprise JavaBeans are deployed in an EJB container within the application server EJB container.
1 Message-Driven Beans The message-driven bean was introduced in EJB 2.0 to support the processing of asynchronous messages from a JMS provider. EJB 2.1.
Advanced Java Session 7 New York University School of Continuing and Professional Studies.
Java Message Service Sangeetha Chavala. What is Messaging? Method of Communication between software components/applications peer-to-peer facility Not.
September 16, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser
1 Stateful Session Beans Stateless Session Beans Michael Brockway Sajjad Shami Northumbria University School of Computing, Engineering & Information Sciences.
1 Timer Service Regardless of the software, scheduling systems are used in many different scenarios: In a credit card processing system, credit card charges.
Enterprise Java Bean Matt. 2 J2EE 3 J2EE Overview.
1 SOA and Enterprise Computing Enterprise Java Beans.
EJB Framework.  As we know, EJB is the center of the J2EE architecture that provides a sturdy framework for building enterprise applications. The major.
Message-Driven Beans and EJB Security Lesson 4B / Slide 1 of 37 J2EE Server Components Objectives In this lesson, you will learn about: Identify features.
J2EE Structure & Definitions Catie Welsh CSE 432
Message Driven Beans & Web Services INFORMATICS ENGINEERING – UNIVERSITY OF BRAWIJAYA Eriq Muhammad Adams J
25 September 2007Kaiser: COMS W4156 Fall COMS W4156: Advanced Software Engineering Prof. Gail Kaiser
Java Messaging Service. An Abstraction for using Messaging Oriented Middleware Purpose is to provide a sophisticated, yet straightforward way to exchange.
1 Java Message Service Манин П Enterprise messaging Key concept: 1. Messages are delivered asynchronously 2. Sender is not required to wait for.
Enterprise JavaBeans Understanding EJB Components Version 0.1 Kamal Wickramanayake
1 Architectural Overview For application developers, assembling enterprise beans requires little or no expertise in the complex system-level issues that.
1 Session Beans Entity beans provide an object-oriented model that makes it easier for developers to create, modify, and delete data from the database.
Collaborate Lesson 4C / Slide 1 of 22 Collaborate Knowledge Byte In this section, you will learn about: The EJB timer service Message linking in EJB 2.1.
JMS (Java Messaging Service)
Java Message Service (JMS) Web Apps and Services.
OCT 1 Master of Information System Management Distributed Systems Lecture 19: Enterprise Java Beans.
Enterprise JavaBeans Session Beans. Session beans are a type of Enterprise JavaBean component designed to implement business logic responsible for managing.
Session Beans Based on: Patel, Brose, Silverman, Mastering Enterprise JavaBeans 3.0.
Enterprise JavaBeans 3.0. What is EJB 3.0 -Reusable server-side component framework-technology -Designed to support building demanding enterprise – level.
Introduction to EJB. What is an EJB ?  An enterprise java bean is a server-side component that encapsulates the business logic of an application. By.
Java Programming: Advanced Topics 1 Enterprise JavaBeans Chapter 14.
Enterprise Java Beans N.V.RAJASEKHAR REDDY. Definition of EJB EJBs are the components that are the set of classes and interfaces deployed within a container.
Enterprise Java Beans Ye Zhou CS6704 Presentation Virginia Tech.
Middleware Technology (J2EE/EJB) EJB Fundamentals.
Copyright © 2014, Oracle and/or its affiliates. All rights reserved. | Think Async Masoud Kalali, Software Engineer, Embrace and.
EJB Enterprise Java Beans JAVA Enterprise Edition
DEVELOPING ENTERPRISE APPLICATIONS USING EJB JAVA MESSAGE SERVICE – JMS MESSAGE DRIVEN BEAN – MDB.
Java Message Service Introduction to JMS API. JMS provides a common way for Java programs to create, send, receive and read an enterprise messaging system’s.
September 28, 2010COMS W41561 COMS W4156: Advanced Software Engineering Prof. Gail Kaiser
Slide No. 1 of 111 JMS ( J AVA M ESSAGE S ERVICE ) -Dhananjay Singh.
Enterprise Java Beans. Contents  Understanding EJBs  Practice Section.
Java Messaging Service (JMS)
null, true, and false are also reserved.
Harjutus 3: Aünkroonne hajussüsteemi päring
Lab 6 – EJB User Managment
J2EE Lecture 13: JMS and WebSocket
Enterprise Java Beans.
Presentation transcript:

Module 6 Message-Driven Beans

History Introduced in EJB 2.0 –Supports processing of asynchronous messages from a JMS provider Definition expanded in EJB 2.1 –Supports any messaging system Annotations introduced in EJB 3.0

JMS and Message-Driven Beans All EJB 3.0 vendors must support a JMS provider JMS –Vendor neutral API used to access enterprise messaging systems –Similar in concept to JDBC

JMS Terminology JMS Client –Applications that use JMS JMS Provider –System that handles routing and delivery of messages JMS Application –Business system composed of many JMS clients and typically one JMS provider Producer –JMS client that sends a message Consumer –JMS client that receives a message

JMS in Action EJBs of all type can use JMS to send messages Messages consumed by other application or message-driven beans

Example using JMS private ConnectionFactory private Topic public TicketDO bookFlight (CreditCardDO card, double price) throws IncompleteConversationalState { if(customer == null || flight == null || seat == null) throw new IncompleteConversationalState();

Example using JMS TravelAgentBean try { Reservation reservation = new Reservation( customer, flight, seat, price, new Date()); entityManager.persist(reservation); process.byCredit(customer,card,price); TicketDO ticket = new TicketDO(customer, flight, seat, price); Connection connect = connectionFactory.createConnection(); Session session = connect.createSession(true,0); MessageProducer producer = session.createProducer(topic); TextMessage textMsg = session.createTextMessage(); textMsg.setText(ticket.description); producer.send(textMsg); connect.close(); return ticket; } catch(Exception e) { throw new EJBException(e); }

Message Types JMS Message is a Java Object –Header Delivery Information and Metadata –Message Body Text Serializable Objects Byte Streams Other application data

Example using MapMessage TravelAgentBean try { …… TicketDO ticket = new TicketDO(customer, flight, seat, price); …… MessageProducer producer = session.createProducer(topic); MapMessage mapMsg = session.createMapMessage(); mapMsg.setInt(“CustomerID”, ticket.customerID.intValue()); mapMsg.setInt(“FlightID”, ticket.flightID.intValue()); mapMsg.setInt(“SeatID”, ticket.seatID.intValue()); mapMsg.setDouble(“Price”, ticket.price); producer.send(mapMsg); …… }

JMS is Asynchronous JMS client can send a message without having to wait for a reply Synchronous communication requires tight coupling between client and EJB Asynchronous communication decouples senders from receivers

JMS Messaging Models Publish-and-Subscribe (pub/sub) –One-to-Many broadcast –Topic –Push-based model Point-to-Point (p2p) –One-to-One delivery –Queue –Pull- or Polling-based model

Session Beans Should not Receive Messages Session beans (or entities) cannot be programmed to respond to JMS messages Can set up a business method that attempts to consume a JMS message but: –Method must be invoked synchronously from EJB client –Method prone to blocking if no message available Bottom Line: Use Message-Driven Beans instead!

Message-Driven Beans EJB –But no remote or local interface Stateless Server-Side Transaction-Aware Processes Asynchronous Messages Concurrent behavior because container creates numerous instances

Message-Driven Bean ReservationProcessorBean package edu.weber.reservationprocessor; import javax.jms.*; import edu.weber.domain.*; import edu.weber.processpayment.*; import edu.weber.travelagent.*; import java.util.Date; import javax.ejb.*; import javax.annotation.*; propertyName=“destinationType”, propertyName=“messageSelector”, propertyValue=“MessageFormat=‘Version propertyName=“acknowledgeMode”, propertyValue=“Auto-acknowledge”)})

Message-Driven Bean ReservationProcessorBean public class ReservationProcessBean implements javax.jms.MessageListener private EntityManager private ProcessPaymentLocal private ConnectionFactory connectionFactory;

Message-Driven Bean ReservationProcessorBean public void onMessage(Message message) { try{ MapMessage reservationMsg = (MapMessage)message; int customerPk = reservationMsg.getInt(“CustomerID”); int flightPk = reservationMsg.getInt(“FlightID”); int seatPk = reservationMsg.getInt(“SeatID”); double price = reservationMsg.getDouble(“Price”); // get the credit card Date expirationDate = new Date(reservationMsg.getLong(“CreditCardExpDate”); String cardNumber = reservationMsg.getString(“CreditCardNum”); String cardType = reservationMsg.getString(“CreditCardType”); CreditCardDO card = new CreditCardDO(cardNumber, expirationDate, cardType);

Message-Driven Bean ReservationProcessorBean Customer customer = em.find(Customer.class, customerPk); Flight flight = em.find(Flight.class, flightPk); Seat seat = em.find(Seat.class, seatPk); Reservation reservation = new Reservation(customer, flight, seat, price, new Date()); em.persist(reservation); process.byCredit(customer, card, price); TicketDO ticket = new TicketDO(customer, cruise, cabin, price); deliverTicket(reservationMsg, ticket); } catch (Exception e) { throw new EJBException(e); }

MessageDrivenContext Extends EJBContext –No new methods added

Message-Driven Bean ReservationProcessorBean public void deliverTicket(MapMessage reservationMsg, TicketDO ticket) throws JMSException { Queue queue = (Queue)reservationMsg.getJMSReplyTo(); Connection connect = connectionFactory.createConnection(); Session session = connect.createSession(true, 0); MessageProducer sender = session.createProducer(queue); ObjectMessage message = session.createObjectMessage(); message.setObject(ticket); sender.send(message); connect.close(); }

Message-Driven Bean Lifecycle Does Not Exist Method-Ready Pool

Message-Driven Bean Lifecycle Does Not Exist Method-Ready Pool Class.newInstance()

Message-Driven Bean Lifecycle Does Not Exist Method-Ready

Message-Driven Bean Lifecycle Method-Ready Pool Business Methods