sra1_jms
TRANSCRIPT
-
8/6/2019 sra1_jms
1/34
-
8/6/2019 sra1_jms
2/34
JMS and JTA With MQ
-
8/6/2019 sra1_jms
3/34
www.clickandbuy.com E_mail : [email protected]
AGENDA
What is Java Messaging Service
What is Java Transaction API
Features of MessageQueue
Sample JMS Application with JTA and MQ
-
8/6/2019 sra1_jms
4/34
www.clickandbuy.com E_mail : [email protected]
What is Java Messaging Service
Messaging systems allow you to loosely couple heterogeneoussystems together. Which offers reliability, transactions ,durability anddelivery guarantees. JMS is an Message-Oriented-Middle ware(MOM) provide a common reliable way for programs to create, send,receive and read messages in any distributed Enterprise System.MOM ensures fast, reliable asynchronous electronic communication,guaranteed message delivery, receipt notification and transactioncontrol. The most common messaging models are:
P oint-To- P oint MessagingP ublish-Subscribe Messaging
-
8/6/2019 sra1_jms
5/34
www.clickandbuy.com E_mail : [email protected]
POINT-TO-POINT MESSAGING
When one process needs to send a message to another process, P oint-To- P oint Messagingcan be used. However, this may or may not be a one-way relationship. The client to aMessaging system may only send messages, only receive messages, or send and receivemessages. At the same time, another client can also send and/or receive messages. In thesimplest case, one client is the Sender of the message and the other client is the Receiver of the message.
-
8/6/2019 sra1_jms
6/34
www.clickandbuy.com E_mail : [email protected]
PUBLISH-SUBSCRIBE MESSAGING
When multiple applications need to receive the same messages, P ublish-Subscribe Messaging is used. The central concept in a P ublish-Subscribemessaging system is the Topic. Multiple P ublishers may send messages to aTopic, and all Subscribers to that Topic receive all the messages sent to thatTopic.
-
8/6/2019 sra1_jms
7/34
J AVA MESSAGE SERVICE API
JMS Parent Publisher-SubscribeDomain Point-To-point Domain
D estination Topic Queue
ConnectionFactory TopicConnectionFactory QueueConnectionFactor y
Connection TopicConnection QueueConnection
Session TopicSession QueueSession
Message P roducer Topic P ublisher QueueSender
MessageConsumer TopicSubscriber QueueReciever ,QueueBrowser
www.clickandbuy.com E_mail : [email protected]
-
8/6/2019 sra1_jms
8/34
www.clickandbuy.com E_mail : [email protected]
Java Transaction API (JTA)The Java Transaction A P I (JTA) is part of the J2EE platform. The A P I gives you
the ability to perform distributed transactions, that is, an application can use the AP I to perform transactions on more than one data store in the network at thesame time. But to do this efficiently, it helps to have another componentoperating in the application server: a J2EE transaction manager. A transactionmanager helps to efficiently schedule and execute the potentially large number of transactions coming in through the application server.
-
8/6/2019 sra1_jms
9/34
www.clickandbuy.com E_mail : [email protected]
Transaction Strategies* The Local Transaction model
* The P rogrammatic Transaction model* The D eclarative Transaction model
The Local Transaction model gets its name from the factthat transactions are managed by the underlying databaseresource manager, not the container or framework your applicationis running in.
The P rogrammatic Transaction model gets its namefrom the fact that the developer is responsible for managing thetransaction. In the P rogrammatic Transaction model, unlike theLocal Transaction model, you manage transactions and areisolated from the underlying database connections.
The D eclarative Transaction model, otherwise known as
Container Managed Transactions (CMT), is the most commontransaction model in the Java platform. In this model, the container environment takes care of starting, committing, and rolling backthe transaction. The developer is responsible only for specifyingthe transactions' behavior.
-
8/6/2019 sra1_jms
10/34
www.clickandbuy.com E_mail : [email protected]
C ollaboration of JMS with JTA
All JMS Sessions support local transactions. That is, callingcommit() and rollback() directly on the JMS Session object. Local transactionsonly affect the JMS session, nothing else. Local transactions have nothing to dowith and are independent from the JTA transactions used by container (CMT) or by bean managed transactions (BMT)
JTA transactions are the ones used by the container. Alsotransactions controlled through the UserTransaction object for bean managed
transactions are JTA. JTA transactions can span multiple resources (D
Bconnections, JMS sessions, any other resource adapters (RAR) that supporttransactions).
You may use local transaction for simple cases. Actually almost allsample code I found on the web uses local transactions for JMS. But in robustreal-world applications you will need JTA transactions, as JMS will rarely be your only resource during a transaction. Using JTA means that messages you sendfrom a session bean get really sent only with the commit (along with your D Bchanges etc.), and are discarded if you rollback.
-
8/6/2019 sra1_jms
11/34
JMS APPLI C ATION DEPLOYMENT IN JBOSS
In JBoss 4.x the JMS configuration (in jms/jbossmq-destinations-service.xml)
queue/MyQueue100003
jboss.mq:service= D estinationManager
In Our Java Code:
InitialContext iniCtx = new InitialContext();Object tmp = iniCtx.lookup("ConnectionFactory");QueueConnectionFactory qcf = (QueueConnectionFactory) tmp;conn = qcf.createQueueConnection();que = (Queue) iniCtx.lookup("queue/MyQueue");session = conn.createQueueSession(false,QueueSession.AUTO_ACKNOWLE DG E);conn.start();
Ways of JMS Application Deployment
www.clickandbuy.com E_mail : [email protected]
-
8/6/2019 sra1_jms
12/34
www.clickandbuy.com E_mail : [email protected]
J MS APPLICATION DEPLOYMENT IN WEBLOGIC
In JBoss 8.x the JMS configuration (in weblogic-ejb-jar.xml)
jms/testQueueweblogic.jndi.WLInitialContextFactoryjms/connectionFactory20
In Java Code :
Context ctx = getInitialContext("t3://localhost:7001");QueueConnectionFactoryqconFactory=(QueueConnectionFactory)ctx.lookup(jms/connectionFactory);QueueConnection connection = qconFactory.createQueueConnection();QueueSession session = connection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);Queue queue = (Queue) ctx.lookup("jms/testQueue");
Most of the Messaging runs on Different Protocols like TCP/IP, SSL ,T3 ,HTTP
-
8/6/2019 sra1_jms
13/34
J MS APPLICATION WITH OPEN MESSAGE QUEUE
Message Queue is a messaging middleware product that implements theJava Message Service (JMS) standard. In addition, Message Queue provides enterprise-
strength capabilities, including advanced integration, administration, security, and high-availability features.
www.clickandbuy.com E_mail : [email protected]
-
8/6/2019 sra1_jms
14/34
-
8/6/2019 sra1_jms
15/34
MOM SYSTEM
www.clickandbuy.com E_mail : [email protected]
-
8/6/2019 sra1_jms
16/34
Persistence Services
File -Bas ed P er s ist ence
File-based persistence is a mechanism that uses individual files to store persistent data.File-based persistence is generally faster that JDBC-based persistence
J DBC-Bas ed P er s ist ence
JDBC-Based persistence uses a Java Database Connectivity (JDBCTM)interface to connect the broker to a JDBC-compliant data store. To have the broker access a data store through a JDBC
www.clickandbuy.com E_mail : [email protected]
-
8/6/2019 sra1_jms
17/34
C lustering
Message Queue supports the use of broker clusters: groupsof brokers working together to provide message delivery services toclients. Clusters enable a Message Queue service to scale messaging
operations by distributing client connections among multiple brokers.Because a cluster consists of multiple brokers, the cluster helps protectagainst individual broker failure. Two cluster models provide different levelsof message service availability.
C onventional C lusters
Enhanced C lusters
www.clickandbuy.com E_mail : [email protected]
-
8/6/2019 sra1_jms
18/34
C onventional C lustersA conventional broker cluster provides for service availability. When a
broker or a connection fails, clients connected to the failed broker reconnect to another broker inthe cluster. However, messages and state information stored in the failed broker cannot berecovered until the failed broker is brought back online. The broker or connection failure cantherefore result in a significant delay and in messages being delivered out of order.
www.clickandbuy.com E_mail : [email protected]
-
8/6/2019 sra1_jms
19/34
Enhanced C luster An enhanced broker cluster provides for data availability in addition to
service availability. When a broker or a connection fails, another broker takes over the pending work of thefailed broker. The failover broker has access to the failed broker's messages and state information. Clientsconnected to the failed broker reconnect to the failover broker. In an enhanced cluster, as compared to aconventional cluster, a broker or connection failure rarely results in significant delays in message deliveryand messages are always delivered in order.
www.clickandbuy.com E_mail : [email protected]
-
8/6/2019 sra1_jms
20/34
Sample JMS Application
-
8/6/2019 sra1_jms
21/34
www.clickandbuy.com E_mail : [email protected]
Opening an admin C onsole from Terminal
-
8/6/2019 sra1_jms
22/34
www.clickandbuy.com E_mail : [email protected]
Admin C onsole
-
8/6/2019 sra1_jms
23/34
www.clickandbuy.com E_mail : [email protected]
Admin C onsole Services
-
8/6/2019 sra1_jms
24/34
-
8/6/2019 sra1_jms
25/34
www.clickandbuy.com E_mail : [email protected]
Log file when the Broker is in Listen state
-
8/6/2019 sra1_jms
26/34
www.clickandbuy.com E_mail : [email protected]
C onfig.prperties file for cluster path specification
-
8/6/2019 sra1_jms
27/34
www.clickandbuy.com E_mail : [email protected]
C luster.properties which holds persistence store
-
8/6/2019 sra1_jms
28/34
www.clickandbuy.com E_mail : [email protected]
Sample code in execution with an output
-
8/6/2019 sra1_jms
29/34
www.clickandbuy.com E_mail : [email protected]
Updated Log file after the sample code execution
-
8/6/2019 sra1_jms
30/34
www.clickandbuy.com E_mail : [email protected]
Updated Admin console after the sample code execution
-
8/6/2019 sra1_jms
31/34
-
8/6/2019 sra1_jms
32/34
Transaction Support
The JMS specification also supports distributed transactions. Thatis, the production and consumption of messages can be part of a larger,distributed transaction that includes operations involving other resource
managers, such as database systems. A distributed transaction manager,like the one supplied by the Sun Java System Application Server, must beavailable to support distributed transactions.
www.clickandbuy.com E_mail : [email protected] .com E_mail : [email protected]
-
8/6/2019 sra1_jms
33/34
C onclusion
By Collaborating JMS MessageQueues with G lobal Transactions we canavoid many pitfalls:
Reduce Fail over concepts
Delivery Gaurantee
Data Backup
Two-phase C ommit Protocol
Safe and Secure
www.clickandbuy.com E_mail : [email protected] .com E_mail : [email protected]
-
8/6/2019 sra1_jms
34/34
www.clickandbuy.com E_mail : [email protected]
ANY QUERIES?