• No results found

Messaging in Java 24.04.2012

N/A
N/A
Protected

Academic year: 2020

Share "Messaging in Java 24.04.2012"

Copied!
50
0
0

Loading.... (view fulltext now)

Full text

(1)

Messaging in Java

24.04.2012

(2)

Agenda

Enterprise Application Integration

Messaging Overview

JMS Architecture

DEMO(s)

1. Instant Messaging

(3)
(4)

Enterprise Application Integration

Integration Challenge

Systems that need to be linked together very often: - reside on different operating systems

- use different database solutions and different

computer languages

(5)

Enterprise Application Integration

EAI definition, by Gartner Group

„Unrestricted sharing of data and business processes

among any connected application or data sources in the enterprise.”

Messaging plays a key role in heterogeneous integration

(6)
(7)

What’s messaging?

• Messaging approach will mean that two or more

applications will exchange information in the form of messages.

A message is a self-contained package of business data and network routing headers.

• The business data contained in a message can be anything - usually contains information about some business transaction.

(8)

Messaging advantages

• Heterogeneous Integration • Reduce System Bottlenecks • Increase Scalability

(9)
(10)

Message-Oriented Middleware

• Allows two or more applications to exchange information in the form of messages

Provides a mechanism for integrating applications in a loosely coupled, flexible manner.

Provide asynchronous delivery of data between applications on a

store and forward basis. The applications do not communicate

directly with each other, but instead communicate with the MOM, which acts as an intermediary.

Provides assured delivery of messages and relieves application programmers from knowing the details of remote procedure calls (RPC) and networking/communications protocols.

Usually provide fault tolerance, load balancing, scalability, and transactional support for enterprises that need to reliably

(11)

Centralized architecture

Typically, a centralized architecture uses a

hub-and-spoke topology.

(12)

Message Oriented Middleware Vendors

Open Source

• Apache ActiveMQ

• Glassfish Open Message Queue

• Object Web JORAM

Commercial

• BEA Systems MessageQ

• IBM MQSeries

• TIBCO Rendezvous Software Bus

• Progress SonicMQ

(13)

Messaging c.d.

• Applications exchange messages through virtual channels called destinations.

Message being sent is addressed to a destination not a specific application.

• Any application that subscribes or registers an interest in that destination may receive the message

(14)

Messaging Models

1. Point to Point

(15)

Point to Point

• Allows JMS clients to send and receive messages both

synchronously and asynchronously via virtual channels

known as queues.

Message producers are called senders and message consumers are called receivers.

Messages sent to a queue are received by one and only

one receiver, even though there may be many receivers

(16)

Point to Point

Point-to-point messaging supports asynchronous “fire

and forget” messaging as well as synchronous request/reply messaging.

The point-to-point model supports load balancing, which allows multiple receivers to listen on the same queue, therefore distributing the load.

• JMS provider takes care of managing the queue,

ensuring that each message is consumed once and only

once by the next available receiver in the group.

• Point-to-point also offers other features, such as a

queue browser that allows a client to view the contents

(17)

Publish and Subscribe

• Messages are published to a virtual channel called a

topic.

Message producers are called publishers, whereas message consumers are called subscribers.

• Messages published to a topic using the

publish-and-subscribe model can be received by multiple subscribers

(18)

Publish and Subscribe

The pub/sub model tends to be more decoupled than the p2p model in that the message publisher is

generally unaware of how many subscribers there are or what those subscribers do with the message.

Nondurable subscribers are temporary subscriptions

that receive messages only when they are actively listening on the topic.

Durable subscribers will receive a copy of every

(19)

19

What is MQ?

•Most large organizations today have IT systems from various

manufacturers.... makes it difficult to share communications and data across systems.

•These organizations need to communicate and share data with suppliers and customers, who might also have disparate systems.

•Handy to have a messaging tool that could receive data from one type of system and send that data to another type.

•WebSphere MQ facilitates application integration by passing messages between applications and web services.

(20)

20

What is MQ?

•Message queues, and the software that manages them enable program-to-program communication.

•Messaging and Queuing an be understood as follows:

• Messaging means that programs communicate by sending each other

messages (data) rather than by calling each other.

• Queuing means messages are placed on queues in storage,

•Programs can run independently of each other, at different speeds and times,in different locations, and without having a logical connection

(21)

21

(22)

22

Synchronous Communication

•Program A prepares a message and puts it on Queue 1.

•Program B gets the message from Queue 1 and processes it.

•Both Program A and Program B use an application programming interface (API) to put messages on a queue and get messages from a queue.

•The MQ API is called the Message Queue Interface (MQI).

•When Program A puts a message on Queue 1, Program B might not be running. The queue stores the message safely until Program B starts and is ready to get the message.

•When Program B gets the message from Queue1, Program A might no longer be running. For this model, there is no requirement for two

(23)

23

(24)

24

Asynchronous Communication

•Using the asynchronous model, Program A puts messages on Queue 1 for Program B to process

•Program B sends the responses to Queue 2

•It is Program C, acting asynchronously to Program A, gets the replies from Queue 2 and processes them.

(25)
(26)

What is JMS?

The Java Message Service specification 1.1 states:

“JMS is a set of interfaces and associated semantics that define how a JMS client accesses the facilities of an

(27)

Java Message Service c.d.

• JMS provides a standard, portable way for Java programs to send and receive messages through a MOM product

• Programs written with JMS can run on any MOM that implements the JMS standard.

• Portability - JMS API is provided by Oracle as a set of interfaces, MOM providers implement these interfaces. • As a developer, you build a JMS application by defining

(28)

JMS Objectives

• Define a common set of messaging concepts and facilities.

• Minimize the concepts a programmer must learn to use enterprise messaging.

• Maximize the portability of messaging applications. • Minimize the work needed to implement a provider. • Provide client interfaces for both point-to-point and

(29)

What JMS does not provide

JMS providers are free to implement these features in any manner they please, if at all:

•Load balancing and fault tolerance

•Error and advisory system messages and notification •Administration

•Security

•Wire protocol

(30)

JMS Application Components

JMS clients. Java programs that send and receive

messages using the JMS API.

Messages. The format and content of messages to be

exchanged by JMS and non-JMS clients is integral to the design of a JMS application.

JMS provider. Supplied concrete implementations of

JMS interfaces specific to given MOM product.

Administered objects. An administrator of a

(31)

Administered Objects

JMS Portability – objects that implement the JMS

interfaces must be isolated from a provider’s proprietary technologies (which is achieved by

administered objects).

Administered Objects that implement JMS interfaces,

(32)

Administered Objects c.d.

There are two types of administered objects:

•ConnectionFactory: Used to create a connection to the

provider's underlying messaging system.

•Destination: Used by the JMS client to specify the

destination of messages being sent or the source of messages being received.

(33)

Message

Message is divided into three constituent parts:

• The header is a standard set of fields that are used by both clients andvproviders to identify and route messages. • Properties provide a facility for adding optional header fields to a message.

• The body of the message contains the content to be delivered to a receiving application. Each message

(34)

Message types

• StreamMessage: Contains a stream of Java primitive values that are filled and read sequentially using standard stream operations.

• MapMessage: Contains a set of name-value pairs; the names are of type string and the values are Java

primitives.

• TextMessage: Contains a String.

(35)

JMS Interfaces

JMS Common Interface Peer to Peer Publish and Subscribe

ConnectionFactory QueueConnectionFactory TopicConnectionFactory

Connection QueueConnection TopicConnection

Destination Queue Topic

Session QueueSession TopicSession

MessageProducer QueueSender TopicPublisher

MessageConsumer QueueReceiver,

(36)

JMS Interfaces

ConnectionFactory

ConnectionFactory is an administered object that is

retrieved from JNDI to create a connection to a provider. It contains a createConnection() method, which

(37)

JMS Interfaces

Connection

Connection encapsulates an active connection to a provider. Methods:

•createSession(boolean, int): Returns a Session object. The

boolean parameter indicates whether the Session is transacted or not; the int indicates the acknowledgment mode.

•start(): Activates the delivery of messages from the provider.

•stop(): Temporarily stops delivery of messages; delivery can be

restarted with start().

•close(): Closes the connection to the provider and releases

(38)

JMS Interfaces

Session

Session is the single-threaded context for sending and receiving messages. Methods:

createProducer(Destination): Returns a MessageProducer

object to send messages to the specified Destination.

createConsumer(Destination): Returns a MessageConsumer

object to receive messages from the specified Destination.

commit(): Commits all consumed or produced messages for the current

transaction.

rollback(): Rolls back all consumed or produced messages for the

current transaction.

create<MessageType>Message(...): A variety of methods that

(39)

JMS Interfaces

Destination

(40)

JMS Interfaces

MessageProducer

MessageProducer is used to send messages. Methods:

send(Message): Sends the indicated Message.

setDeliveryMode(int): Sets the delivery mode for

subsequent messages sent; valid values are

DeliveryMode.PERSISTENT and DeliveryMode.NON_PERSISTENT.

setPriority(int): Sets the priority for subsequent

messages sent; valid values are 0 through 9.

setTimeToLive(long): Sets the duration before

(41)

JMS Interfaces

MessageConsumer

MessageConsumer is used to receive messages. Methods:

receive(): Returns the next message that arrives; this

method blocks until a message is available.

setMessageListener(MessageListener): Sets the

(42)

JMS Interfaces

MessageListener

MessageListener is an interface with a single method -- onMessage(Message) -- that provides asynchronous receipt and processing of messages.

This interface should be implemented by a client class and an instance of that class passed to the MessageConsumer object with the setMessageListener(MessageListener)

(43)

Developing JMS Client

1. Look up a ConnectionFactory through JNDI.

2. Look up one or more Destination s through JNDI. 3. Use the ConnectionFactory to create a Connection. 4. Use the Connection to create one or more Session’s. 5. Use a Session and a Destination to create the required

MessageProducer’s and MessageConsumer’s.

(44)

Simple scenario – MessageSender

(45)

Simple scenario – MessageSender

2. Create required JMS objects

(46)

Simple scenario – MessageReceiver

(47)

Simple scenario – MessageReceiver

2. Implement receiver interface.

(48)
(49)

REFERENCES

Java Message Service, 2nd edition, Mark Richards, Richard Monson-Haefel, and David A. Chappell by O’Reilly

Introducing the Java Message Service, Willy Farrell by

IBM

(50)

References

Related documents

Dengan adanya home page diharapkan dapat mempermudah home industry untuk menyebarkan informasi tentang produk abon yang diproduksi dan mempermudah transaksi penjualan

It draws on data collected from sandpit style events entitled Chiasma, undertaken as part of the knowledge exchange hub, Design in Action (DiA) in which

By performing task analysis for the same operation implemented in different user interfaces, we can compare user performance associated with dif- ferent user interfaces in terms of

Box Hill Central Box Hill DC Box Hill North Box Hill South Burwood Burwood East Burwood Heights Caulfield Junction Chatham Elgar Park Forest Hill Heatherdale Houston

Trumm et al (2013) assessed the impact of the advanced technology of the new ExAblate 2100 system (Insightec Ltd, Haifa, Israel) for MRI-guided focused ultrasound surgery on

UNESCO World Heritage Site’s indicators of success and the tools used to measure this mainly focus on the maintenance of the site’s Outstanding Universal Value, its

We analyze how companies which have Total Quality Management (TQM) and implanting a Reverse Logistics System (RLS) improve their recovery activities and reusability of materials and

3rd International Conference of Evidence-Based Health Care Teachers &amp; Developers Building bridges between research and teaching.. Taormina (Italy), 2nd-6th