Using Message-Driven Beans in a Service-Oriented Architecture Dave Chappell VP & Chief Technology...
-
Upload
marylou-walton -
Category
Documents
-
view
218 -
download
0
Transcript of Using Message-Driven Beans in a Service-Oriented Architecture Dave Chappell VP & Chief Technology...
Using Message-Driven Beans in a Service-Oriented Architecture
Dave Chappell VP & Chief Technology Evangelist, Sonic Software
© 2002, Sonic Software Corporation2
© 2002, Sonic Software Corporation3
O’REILLY
© 2002, Sonic Software Corporation4
© 2002, Sonic Software Corporation5
Tell Them About
the
Book Raffle
© 2002, Sonic Software Corporation6
Sonic SoftwareSonic Software
1st J2EE 1.3 Certified MOM!
HTTP(S), XML, SOAP, WSDL, JMS, JCA
Java Message Service (JMS)
Apache Axis
Web services, JAXM, J2EE CA
XML Schema
ebXML
WS-I
Driving Industry Standards
© 2002, Sonic Software Corporation7
SonicMQ AppServer IntegrationSonicMQ AppServer Integration
Borland Appserver
HP/Bluestone Total-e-server
BEA Weblogic– CMT,Clustering, Failover/Reconnect, Design Patterns
IBM WebSphere
Oracle Appserver
MacroMedia
JBoss (soon)
© 2002, Sonic Software Corporation8
Sonic SoftwareSonic Software
Recognized: Enterprise messagingIntegration middleware
Established: Over 500 of Global 2000 rely on Sonic Software
Strong Independent operating company of Progress Backing: Software Corp. (NASDAQ: PRGS)
$170M cash, no debt Distribution in 65 countries, 24x7 world-wide support
History: SonicMQ released 12/1999, #1 JMS productToday SonicMQ 4.0, SonicXQ 1.0 Enterprise Service Bus
© 2002, Sonic Software Corporation9
AgendaAgenda
J2EE Message Driven Topology
JMS Overview
Using JMS With EJBs
JMS and XA Integration
J2EE Connector Architecture
Service Oriented Architectures and Web Services
© 2002, Sonic Software Corporation10
EJB ContainersEJB Containers
J2EE TopologyJ2EE Topology
Web ContainersWeb Containers
JSPJSP
servletservlet servletservlet
JSPJSP
servletservlet
EJBEJB
htmlhtml
gifsgifs jpegsjpegs
xmlxml
Presentation Logic Business Logic
xmlxml
EIS
DatabaseDatabaseEJBEJB
EJBEJB
EJBEJB EJBEJB
EJBEJBEJBEJB
EJBEJB
EJBEJB
Internet
© 2002, Sonic Software Corporation11
J2EE Topology – Message DrivenJ2EE Topology – Message Driven
Web Containers
Web Containers
servletservlet servletservlet
JSPJSP
gifsgifs jpegsjpegs
htmlhtml
Presentation Logic Business Logic
EIS
DatabaseDatabaseInternet
EJBContainers
EJBContainers
EJBEJB
EJBEJB
EJBEJB
MDBMDB
MDBMDB
MDBMDB
EJBContainers
EJBContainers
EJBEJB
EJBEJB
EJBEJB
MDBMDB
MDBMDB
MDBMDB
JMSJMS
© 2002, Sonic Software Corporation12
J2EE Topology – Message DrivenJ2EE Topology – Message Driven
Business Partner
EJB ServerEJB Server
EJB ServerEJB Server
EJB ServerEJB Server
BrokerBroker
Head Office
EJB ServerEJB Server
EJB ServerEJB Server
EJB ServerEJB ServerBrokerBroker
Business Partner
Trading Partner
BrokerBroker
EJB ServerEJB ServerEJB ServerEJB Server
BrokerBroker
Regional Office
© 2002, Sonic Software Corporation13
AgendaAgenda
J2EE Message Driven Topology
JMS Overview
Using JMS With EJBs
JMS and XA Integration
J2EE Connector Architecture
Service Oriented Architectures and Web Services
© 2002, Sonic Software Corporation14
Java Message Service (JMS)Java Message Service (JMS)
Sun standard
Common APIs
Loosely-coupled asynchronous processing– Senders and receivers abstractly decoupled from
each other
– Destinations administratively configurable at runtime
Point to Point and Pub/Sub messaging models
Supports synchronous or asynchronous communication
© 2002, Sonic Software Corporation15
Java Message Service (JMS)Java Message Service (JMS)
Message delivery semantics– Guaranteed Once-and-only-once
– At-most-once
Deployment architecture not addressed by specification– Vendor differentiators
© 2002, Sonic Software Corporation16
Java Message ServiceJava Message Service
BusinessApplication A
JMS Messaging API
JMS Messaging Client
…standards based API…
Messaging Components
BusinessApplication A
JMS Messaging API
JMS Messaging Client
JMSProvider
© 2002, Sonic Software Corporation17
Broad Range of Message TypesBroad Range of Message Types
BytesMessage
Message
MapMessage
ObjectMessage
StreamMessage
TextMessage
Included in JMS Specification
XMLMessage
Extensions in SonicMQ
MultiPartMessage
© 2002, Sonic Software Corporation18
JMS MessagesJMS Messages
Message
Header
Properties
Body
Used to identify and route the Used to identify and route the messagemessage
The actual “payload” of themessage (five different types,
plus XML and Multipart for SonicMQ)
Support application-specific values passed with the
message
© 2002, Sonic Software Corporation19
JMSProvider
JMSProviderPublisherPublisher SubscriberSubscriberSubscriberSubscriber
PersistentPersistentStoreStore
7. publish()method returns
2. 2. DisconnectDisconnect
5. Message retained in
persistent store
1. Subscribe6. Ack
8. Connect
10. Receive
4. Persist
3. Send
9. Retrieve
Persistent messages and durable subscriptions
JMS ReliabilityJMS Reliability
© 2002, Sonic Software Corporation20
JMS ReliabilityJMS Reliability
JMSProvider
JMSProvider
1. Send
3. commit()
2. Send
4. Receive
6. commit()
5. Receive ConsumerConsumerConsumerConsumerProducerProducerProducerProducer
Transactional Message Send and Receive
© 2002, Sonic Software Corporation21
JMS ReliabilityJMS Reliability
JMSProvider
JMSProvider
1. SendProducerProducerProducerProducer
XA Compliant Transaction Manager
ExternalResource(DB/EJB)
2. Update
commit()rollback()
© 2002, Sonic Software Corporation22
Filtering with message selectorsFiltering with message selectors
Message Server
Publisher
Departments.Sales
SubscriberDepartments.SalesPipeline > 15000
JMSPriority = 2Pipeline = 20000
delivered
SubscriberDepartments.SalesJMSPriority > 5
not delivered
SubscriberDepartments.SalesJMSPriority >= 2 AND Pipeline > 10000
delivered
SubscriberDepartments.SalesPipeline > 20000
notdelivered
© 2002, Sonic Software Corporation23
JMS as a J2EE ResourceJMS as a J2EE Resource
2 Requirements to access a Message Provider– ConnectionFactory
Creates connection to JMS providers
– Destination Object The Specific Topic or Queue
© 2002, Sonic Software Corporation24
Obtaining the ConnectionFactoryObtaining the ConnectionFactory
Resource Manager Connection Factories as Administered Objects– Specify standard mechanism for getting
connections to resources outside the J2EE component
– Enables the container to do pooling
JNDI is used for maximum portability
QueueConnectionFactory qcf = (QueueConnectionFactory) ctx.lookup("java:comp/env/jms/TrafficConFactory");
© 2002, Sonic Software Corporation25
Accessing the DestinationAccessing the Destination
The Specific Queue or Topic
Retrieved via JNDI– Specified in the Deployment Descriptor
– Binding to a real Destination done at deploy time
Topic traffic = (Topic) ctx.lookup("java:comp/env/jms/TrafficTopic");
© 2002, Sonic Software Corporation26
What the Java/API looks likeWhat the Java/API looks like
// Create a connection factoryTopicConnectionFactory factory;factory = (TopicConnectionFactory)jndi.lookup("TopicConnectionFactory");
// Create a connectionconnect = factory.createTopicConnection (username, password);
// Create a sessionsession = connect.createTopicSession(true, Session.AUTO_ACKNOWLEDGE);
// Create a topics.Topic topic = (Topic)jndi.lookup("chat");
© 2002, Sonic Software Corporation27
What the Java/API looks likeWhat the Java/API looks like
// Create Subscriber to application topics.TopicSubscriber subscriber = session.createSubscriber(topic);
// Initialize the onMessage() message handler.subscriber.setMessageListener(this);
// Create a publisherpublsher = session.createPublisher(null); // Topic will be set for each reply
// Now setup is complete, start the Connectionconnect.start();
© 2002, Sonic Software Corporation28
What the Java/API looks likeWhat the Java/API looks like
public void onMessage( javax.jms.Message message){ TextMessage textMessage = (TextMessage) message; System.out.println(textMessage.getText());}
-- OR –... while( true ){ textMessage = (javax.jms.TextMessage)qReceiver.receive(1000);...
© 2002, Sonic Software Corporation29
BreakBreak
© 2002, Sonic Software Corporation30
Do the
Book Raffle
© 2002, Sonic Software Corporation31
AgendaAgenda
J2EE Message Driven Topology
JMS Overview
Using JMS With EJBs
JMS and XA Integration
J2EE Connector Architecture
Service Oriented Architectures and Web Services
© 2002, Sonic Software Corporation32
createlookupremove
EJB Design Pattern ReminderEJB Design Pattern Reminder
client
Remote interface stubs
home
object
context
bean
Server provides resource mgmt
Container
methods
DeploymentDescriptor
Automatically invokes services based onrequirements defined in deployment descriptor
createlookupremove
methods
© 2002, Sonic Software Corporation33
MessageDrivenBeanMessageDrivenBean
EJB ContainerEJB Container
PublisherBean
PublisherBean
EJB ContainerEJB Container
SubscriberMsg-driven
Instance
SubscriberMsg-driven
Instance
DatabaseDatabaseDurableSubscription
DurableSubscription
ClientApp
ClientApp
Publishes
Acknowledges
Delivers
Stores
© 2002, Sonic Software Corporation34
ContainerContainer
Msg-driven Bean ClassMsg-driven Bean Class
JMS ProviderJMS Provider
MessageDrivenBeanMessageDrivenBean
Defined in EJB 2.x Specification
Benefits – Simple to write
– Allow for asynchronous execution
DestinationDestination
Msg-drivenBean
instances
Msg-drivenBean
instancesConsumerConsumer
© 2002, Sonic Software Corporation35
MessageDrivenBeanMessageDrivenBean Executes on receipt of a JMS message
– javax.jms.MessageListener interface Shares the following characteristics of stateless session bean
– Is stateless and relatively short- lived
– Security
– Transactions
– Concurrency
– Management
– All the other services that EJBs enjoy!
– Notable difference: No home or remote interface
© 2002, Sonic Software Corporation36
MessageDrivenBean InterfaceMessageDrivenBean Interface
javax.ejb.MessageDrivenBean– ejbCreate(), ejbRemove()
– setMessageDrivenContext()
Just like a usual javax.jms.MessageListner– onMessage(javax.jms.Message)
© 2002, Sonic Software Corporation37
MessageDrivenContextMessageDrivenContext
get/setRollbackOnly()
getUserTransaction()– For BMT only
Others inherited from EJBContext Interface, but not allowed:– getCallerPrincipal()
– isCallerInRole()
– getEJBHome(), getEJBLocalHome()
© 2002, Sonic Software Corporation38
Serialization and ConcurrencySerialization and Concurrency
Container Must Serialize all calls to an MDB– ejbCreate(), ejbRemove(), etc
– No need to be coded as re-entrant
Concurrency– Container May Launch Multiple Instances of
an MDB No guarantee of order “Cancellation” Message May Arrive Before
“Reservation” Message
© 2002, Sonic Software Corporation39
MDB ExampleMDB Example
public class SubscriberMsgBean implements MessageDrivenBean {
<… define ejbCreate(), ejbRemove() and
setMessageDrivenContext( MessageDrivenContext mdc) .. >
MessageDrivenContext mdc = null;
public void onMessage( Message inMessage) {
TextMessage msg = (TextMessage) inMessage;
try {
< look up JDBC database >
< store info from message in database >
} catch( Exception e) {
mdc. setRollbackOnly();
}
}
}
© 2002, Sonic Software Corporation40
MDB Example – Deployment DescriptorsMDB Example – Deployment Descriptors
<message-driven>
...
<ejb-class>SubscriberMsgBean</ejb-class>
<transaction-type>Container</transaction-type>
<jms-message-selector>
NewsType='Metro/Region‘
</jms-message-selector>
<message-driven-destination>
<jms-destination-type>
javax.jms.Topic
</jms-destination-type>
<jms-subscription-durability>
durable
</jms- subscription-durability>
</message-driven-destination>
...
</ message- driven>
© 2002, Sonic Software Corporation42
AgendaAgenda
J2EE Message Driven Topology
JMS Overview
Using JMS With EJBs
JMS and XA Integration
J2EE Connector Architecture
Service Oriented Architectures and Web Services
© 2002, Sonic Software Corporation43
Distributed Transaction Processing (DTP)Distributed Transaction Processing (DTP)
TM
RMRM RM
XAXA
XA
XA
XAXA
TM
RMRM
RM
RM
XAXA
XAXA
XA
XA
TM
RMRM
TM
RMRM RM
XAXA
XA
XA
XAXA
TM
RMRM RM
XAXA
XA
XA
XAXA
© 2002, Sonic Software Corporation44
A local instance of a DTP systemA local instance of a DTP system
TM
RMRMJMS Client
© 2002, Sonic Software Corporation45
Local DTP zoom inLocal DTP zoom in
EJBEJB
Application Server
SonicMQ ClientSonicMQ Client
JMSProvider
JMSProvider
TransactionManager
TransactionManager
JMS ClientJMS Client
JMS XA APIJMS XA API XA ResourceXA Resource
© 2002, Sonic Software Corporation46
XA interfacesXA interfaces
JMS XA SPI– XAConnectionFactory
– XAConnection
– XASession
– XAQueueConnectionFactory
– XAQueueConnection
– XAQueueSession
– XATopicConnectionFactory
– XATopicConnection
– XATopicSession
© 2002, Sonic Software Corporation47
AgendaAgenda
J2EE Message Driven Topology
JMS Overview
Using JMS With EJBs
JMS and XA Integration
J2EE Connector Architecture
Service Oriented Architectures and Web Services
© 2002, Sonic Software Corporation48
J2EE DirectionsJ2EE Directions
J2EE 1.3– Web Applications
– Asynchronous JMS MDB
– EJB 2.0
J2EE 1.4– SOA Platform
– Web Services JAX-RPC JSR-109
– J2EE Connector Architecture
– EJB 2.1 WSEI
© 2002, Sonic Software Corporation49
J2EE Connector Architecture OverviewJ2EE Connector Architecture Overview
Defines standard for connecting J2EE to enterprise information systems (EIS)
System contracts define interface specification with EIS– Connection, Transaction, Security
Enterprise Information
System
Resource Adapter
Application Serveror EAI Framework
System Contract
EIS Interface
© 2002, Sonic Software Corporation50
J2EE Connector Architecture OverviewJ2EE Connector Architecture Overview
Resource adapters– Implements the EIS side of the
system contracts– System-level software drivers for
connecting to an EIS– Enables vendors to create standardized
connectors to EIS
Common client interface– Standard API for applications to
interact with heterogeneous EIS
Enterprise Information
System
Resource Adapter
Application Serveror EAI Framework
System Contract
EIS Interface
© 2002, Sonic Software Corporation51
Inbound Communication ModelInbound Communication Model
ResourceAdapter
JMSDestination
EnterpriseJava
Beans
JCA Container
WorkManager
Connection PoolManager
TransactionManager
SecurityManager
WorkMgmt
JMSDisp
EJBDisp
© 2002, Sonic Software Corporation52
AgendaAgenda
J2EE Message Driven Topology
JMS Overview
Using JMS With EJBs
JMS and XA Integration
J2EE Connector Architecture
Service Oriented Architectures and Web Services
© 2002, Sonic Software Corporation53
Service-Oriented ArchitectureService-Oriented Architecture
Global Enterprise
Internet
WebService
WebService
Credit CheckWeb ServiceCredit CheckWeb Service
Supplier FulfillService
Supplier FulfillService
WebService
WebService
InvoicingService
InvoicingService
SalesServiceSales
Service
Special OrdersSpecial OrdersOrder
Processing
Order Processing
Regional Sales
Regional Sales
PartnerApp
PartnerApp
Inventory Lookup
Inventory Lookup
CustomerApp
CustomerApp
PartnerApp
PartnerApp
Check InvService
Check InvServiceOrder Entry
ServiceOrder Entry
Service
© 2002, Sonic Software Corporation54
Service-Oriented Architectures (SOA)Service-Oriented Architectures (SOA)
System design methodology using existing application components
Applications expose functionality through service interfaces– Loosely-coupled, asynchronous, coarse-grained
Distributed across internal networks or the Internet
Web services – Software services built on standards: SOAP, WSDL,
UDDI, XML, HTTP
Architecture for a Distributed World
© 2002, Sonic Software Corporation55
Web Services Technology StackWeb Services Technology Stack
Publication and Discovery(UDDI, ebXML Registry)
Description Language(WSDL)
Data Formatting(XML Dujour)
Transport(HTTP, SMTP, TCP/IP)
XML-RPC(SOAP-RPC, JAX-RPC)
XML Messaging(SOAP, ebXML,JAXM)
© 2002, Sonic Software Corporation56
Web Services Technology StackWeb Services Technology Stack
XML-RPC(SOAP-RPC, JAX-RPC)
Publication and Discovery(UDDI, ebXML Registry)
Description Language(WSDL)
Data Formatting(XML Dujour)
Transport(HTTP, SMTP, TCP/IP)
XML Messaging(SOAP, ebXML,JAXM)
Quality of ServiceJMS, ebXML-MS, HTTPR
© 2002, Sonic Software Corporation57
Connecting (Web) Services TogetherConnecting (Web) Services Together
(Web) Services aren’t Islands of Themselves Network of Cooperative Services Interfaces, Discovery, and Data Formats are only part
of the big picture– Data transformation – Intelligent Routing based on content– End-to-end guaranteed delivery– Management, configuration, and auditing – Performance and scalability – Asynchronous and synchronous messaging– Security – Deployment tools
What Else Do You Need?
© 2002, Sonic Software Corporation58
Standards Working Together...Standards Working Together...
JAXM/RPC Client
Apache Client
Servlet Container
.NET SOAP Client
JMSmessage
SOAP/HTTPSOAP/HTTP
Web Client
SOAP/HTTPSOAP/HTTP SOAP/HTTPSOAP/HTTP SOAP/HTTPSOAP/HTTP
Internet
JMS Messaging BackboneJMS Messaging Backbone
SOAP/HTTPSOAP/JMS
SOAP/HTTPSOAP/JMS
SOAP/HTTPSOAP/JMS
JMSmessage
JMSmessage
JMSmessage
JCA/EISEJB
ContainerJMS Client C++ ClientJCA/EIS
© 2002, Sonic Software Corporation59
Contact InformationContact Information
http://www.sonicsoftware.com
Integrate with Ease. Extend at WillIntegrate with Ease. Extend at WillTMTM..