Presentation is loading. Please wait.

Presentation is loading. Please wait.

J2EE Lecture 13: JMS and WebSocket

Similar presentations


Presentation on theme: "J2EE Lecture 13: JMS and WebSocket"— Presentation transcript:

1 J2EE Lecture 13: JMS and WebSocket
Dr. Ming Qiu Xiamen University Software School

2 13.1 Introduction to MDB How to implement messaging
Mastering EJB3.0, Chap 7 13.1 Introduction to MDB How to implement messaging An overview of asynchronous behavior and message-oriented middleware (MOM) How to use the Java Message Service(JMS), MOM framework for JMS-based message-driven beans The features of message-driven beans Compared with entity and session beans How to develop message-driven beans

3 13.1 Introduction to MDB Motivations for Messaging
Mastering EJB3.0, Chap 7 13.1 Introduction to MDB Motivations for Messaging Several areas are challenging for RMI-IIOP Asynchrony Decoupling Reliability Support for multiple senders and receivers

4 Mastering EJB3.0, Chap 7 13.1 Introduction to MDB

5 EJB in Action, Chap 4 13.1 Introduction to MDB

6 13.1 Motivations for Messaging
Mastering EJB3.0, Chap 7 13.1 Motivations for Messaging Message-oriented middleware(MOM) Tibco Rendezvous IBM WebSphere MQ BEA Tuxedo/Q Sun Java System Messaging Server Microsoft MSMQ JBoss MQ RabbitMQ ActiveMQ

7 13.2 The Java Message Service (JMS)
Mastering EJB3.0, Chap 7 13.2 The Java Message Service (JMS) A messaging standard, which has two parts an API Write code to send and receive messages A Service Provider Interface (SPI) Plug in JMS provider Know how to talk to specific MOM implementation

8 13.2 The Java Message Service (JMS)

9 13.2 The Java Message Service (JMS)
Message Domains Publish/subscribe (pub/sub)

10 13.2 The Java Message Service (JMS)
Point-to-point (PTP)

11 13.2 The Java Message Service (JMS)
Mastering EJB3.0, Chap 7 13.2 The Java Message Service (JMS) EJB in Action, Chap 4 JMS API Locate the JMS Provider’s ConnectionFactory instance (javax.jms.ConnectionFactory) Look it up in JNDI Create a JMS connection (javax.jms.Connection) A active connection to the JMS provider Thread-safe and designed to be sharable Create a JMS session (javax.jms.Session) provides a single-threaded, task-oriented context for sending and receiving messages.

12 13.2 The Java Message Service (JMS)
Mastering EJB3.0, Chap 7 13.2 The Java Message Service (JMS) Locate the JMS Destination The channel to which you’re sending or from with you’re receiving messages Set up by deployer in advances Looked up from JNDI Create a JMS Producer or a JMS Consumer JMS Producer Call it to pass your message JMS Consumer Call it to ask for a message Send or receive your message

13 Mastering EJB3.0, Chap 7

14 13.2 The Java Message Service (JMS)
Mastering EJB3.0, Chap 7 13.2 The Java Message Service (JMS)

15 Mastering EJB3.0, Chap 7

16 13.2 The Java Message Service (JMS)
Mastering EJB3.0, Chap 7 13.2 The Java Message Service (JMS)

17 13.2 The Java Message Service (JMS)
EJB in Action, Chap 4 13.2 The Java Message Service (JMS)

18 13.3 Working with MDB What is a Message-Driven Bean?
Mastering EJB3.0, Chap 7 13.3 Working with MDB EJB in Action, Chap 4 What is a Message-Driven Bean? EJB components designed to consume the asynchronous messages Does not have a remote or local business interface Support generic listener methods for message delivery Called by an EJB container upon arrival of a message Do not have return values and not send exceptions back to clients Message-driven beans are stateless Message-driven beans are single-threaded The container is responsible for serializing messages The container provide concurrent message consumption by pooling multiple message-driven beans

19 EJB in Action, Chap 4 13.3 Working with MDB

20 13.4 Developing Message-Driven Beans
EJB in Action, Chap 4 13.4 Developing Message-Driven Beans MDBs must follow these rules Must implement javax.jms.MessageListener Must be concrete. It cannot be either a final or an abstract class. Must be a POJO class and not a subclass of another MDB. Must be declared public. Must have a no-argument constructor. Cannot define a finalize method in the bean class. Must not throw the javax.rmi.RemoteException or any runtime exceptions.

21 13.4 Developing Message-Driven Beans
EJB in Action, Chap 4 13.4 Developing Message-Driven Beans

22 13.4 Developing Message-Driven Beans
EJB in Action, Chap 4 13.4 Developing Message-Driven Beans

23 13.4 Developing Message-Driven Beans
EJB in Action, Chap 4 13.4 Developing Message-Driven Beans

24 13.4 Developing Message-Driven Beans
Mastering EJB3.0, Chap 7 13.4 Developing Message-Driven Beans

25 13.4 Developing Message-Driven Beans
EJB in Action, Chap 4 13.4 Developing Message-Driven Beans acknowledgeMode Messages are not actually removed from the queue until the consumer acknowledges them.

26 13.4 Developing Message-Driven Beans
EJB in Action, Chap 4 13.4 Developing Message-Driven Beans subscriptionDurability specify whether the topic subscription is durable or nondurable durable subscription all messages sent to the topic are guaranteed to be delivered to that consumer

27 Spring Framework Doc 13.5 Spring JMS Provides a JMS integration framework that simplifies the use of the JMS API JmsTemplate Message-Driven POJOS (MDPs)

28 13.5 Spring JMS Sending a Message - JmsTemplate
Spring Framework Doc 13.5 Spring JMS Sending a Message - JmsTemplate the central class in the JMS core package Requires a reference to a ConnectionFactory. ConnectionFactory is used by the client application as a factory to create connections with the JMS provider and encapsulates various configuration parameters.

29 Spring Framework Doc

30 Spring Framework Doc 13.5 Spring JMS

31 Spring Framework Doc 13.5 Spring JMS

32 Spring Framework Doc 13.5 Spring JMS

33 Spring Framework Doc

34 Spring Framework Doc 13.5 Spring JMS Receiving a Message - MDPs

35 Spring Framework Doc 13.5 Spring JMS

36 13.6 WebSocket HTTP Protocol

37 13.6 WebSocket HTTP Protocol

38 13.6 WebSocket WebSocket is a protocol which communicates between browser and web server. works over TCP protocol. opens a socket connection between browser and web server and start communication.

39 13.6 WebSocket

40 13.6 WebSocket SockJS is a java script library which provides websocket like object for browsers. provides cross browser compatibility and supports STOMP protocol to communicate with any message broker. works in the way that we need to provide URL to connect with message broker and then get the stomp client to communicate.

41 13.6 WebSocket STOMP is Streaming Text Oriented Messaging Protocol.
A STOMP client communicates to a message broker which supports STOMP protocol. STOMP uses different commands like connect, send, subscribe, disconnect etc to communicate.

42 13.6 WebSocket Configuration Class to Support Spring 4 WebSocket

43 13.6 WebSocket

44 13.6 WebSocket @EnableWebSocketMessageBroker
enables a configuration class to support WebSocket AbstractWebSocketMessageBrokerConfigurer is extended by WebSocket Configuration class

45 13.6 WebSocket MessageBrokerRegistry helps to register message broker.
topic : there are more than one subscribers for a message. queue : peer to peer communication. StompEndpointRegistry register an end point for the STOMP over WebSocket.

46 13.6 WebSocket Controller class for WebSocket

47 13.6 WebSocket STOMP Client

48 13.6 WebSocket

49 13.6 WebSocket

50 13.6 WebSocket

51 13.6 WebSocket

52 13.6 WebSocket The return value from method is converted with a MessageConverter and used as the body of a new message that is then sent, by default, to the "brokerChannel" with the same destination as the client message but using the prefix "/topic" by default. message level annotation can be used to specify any other destination instead.

53

54 13.6 WebSocket Flow of Messages


Download ppt "J2EE Lecture 13: JMS and WebSocket"

Similar presentations


Ads by Google