• No results found

Spring & JMS

N/A
N/A
Protected

Academic year: 2021

Share "Spring & JMS"

Copied!
28
0
0

Loading.... (view fulltext now)

Full text

(1)

Welcome to

Spring Forward

(2)
(3)

Introduction to Spring JMS

Mark Pollack Principal

CodeStreet LLC

Speaker\u2019s Qualifications

Mark Pollack is a founding partner at CodeStreet LLC, a software and consulting firm in the

financial services industry.

.NET and J2EE architect and developer

specializing in financial front office solutions, EAI, and message based middleware

TIBCO

(4)
(5)

Speaker\u2019s Qualifications

Mark Pollack is a founding partner at CodeStreet LLC, a software and consulting firm in the

financial services industry.

.NET and J2EE architect and developer

specializing in financial front office solutions, EAI, and message based middleware

TIBCO

Spring Developer (2003)

\ u 2 0 2 2 JmsTemplate

Contributing author

\ u 2 0 2 2 Java Development with the Spring Framework

\ u 2 0 1 3 JMS Section

Founder and Co-lead of Spring.NET (2004)

Outline

What is Messaging Middleware?

Introduction to JMS

Spring’s JMS goals

Sending Messages

(6)
(7)

Outline

What is Messaging Middleware?

Introduction to JMS

Spring’s JMS goals

Sending Messages

Consuming Messages

.NET/Java interoperability

Messaging Middleware

Communication styles

• Synchronous: “request/reply” • Asynchronous

Messaging styles: “domains”

• Point-to-Point: “queues”

(8)
(9)

Messaging Middleware

Communication styles

• Synchronous: “request/reply” • Asynchronous

Messaging styles: “domains”

• Point-to-Point: “queues” • Publish-Subscribe: “topics”

Important characteristics

• • •

Broker responsible for delivery

QOS – persistence, priority and time to live. Producer decoupled from Subscriber

Messaging Middleware

Popular before Java/J2EE

• • • • IBM – MQ-Series TIBCO Microsoft – MSMQ Others…

Heterogeneous

(10)
(11)

Messaging Middleware

Popular before Java/J2EE

• • • • IBM – MQ-Series TIBCO Microsoft – MSMQ Others…

Heterogeneous

• Platform and Language

What is JMS?

JCP specification for messaging

• 1.0.2 (2000), part of J2EE 1.3

• 1.1 (2002), part of J2EE 1.4

Common API and behavior across vendors

Vendor differentiate on primarily non-functional features

(12)
(13)

What is JMS?

JCP specification for messaging

• 1.0.2 (2000), part of J2EE 1.3

• 1.1 (2002), part of J2EE 1.4

Common API and behavior across vendors

Vendor differentiate on primarily non-functional features • • • • • Administration Security Failover Language bindings

Alternative Ack modes and Message types

What is JMS

Specs distinguishes between

• Non-J2EE “stand alone” environment

– Typically a custom server

– You define lifecycle of objects – Fair amount of boiler-plate code – Access to full JMS functionality/API

(14)
(15)

What is JMS

Specs distinguishes between

• Non-J2EE “stand alone” environment

– Typically a custom server

– You define lifecycle of objects – Fair amount of boiler-plate code – Access to full JMS functionality/API

– Typically no connection/session/producer pooling • J2EE/EJB 2.0 app server environment

– – –

Lifecycle of EJB component model Restricts functionality available

Configuration based async consumers

Whirlwind tour of the JMS API

Important JMS classes

• ConnectionFactory

– creates connections

– Administered JNDI object

• Connection

– Socket that communicates to broker

• Session

– Create messages, producers, and consumer

• MessageProducer

(16)
(17)

Whirlwind tour of the JMS API

Important JMS classes

• ConnectionFactory

– creates connections

– Administered JNDI object

• Connection

– Socket that communicates to broker

• Session

– Create messages, producers, and consumer

• MessageProducer

– Sends message - ‘async’ to consumer - ‘sync’ to broker.

• MessageConsumer

– ‘sync’ receive

• Register MessageListener with MessageConsumer

– ‘async’ receive

• Destination

– Where to send the message (topics/queues)

– Administered JNDI object

(18)
(19)

JMS Object Relationships

Plain Jane JMS Hello World!

Not showing JNDI

lookup

of

ConnectionFactory and Destination

Connection connection = connectionFactory.createConnection(); Session session = connection.createSession(false,

Session.AUTO_ACKNOWLEDGE); MessageProducter producer = session.createProducer(null);

(20)
(21)

Plain Jane JMS Hello World!

Not showing JNDI

lookup

of

ConnectionFactory and Destination

Connection connection = connectionFactory.createConnection(); Session session = connection.createSession(false,

Session.AUTO_ACKNOWLEDGE); MessageProducter producer = session. (null);

Message message = session.createTextMessage(“Hello world!”); producer.send(destination, message);

createProducer

Not showing try/finally code to

close

all

intermediate objects (resources)

Spring’s JMS Goals

0 order similarity to Spring’s JDBC supportth

Remove API noise

• One-liner send/sync-receive

• Few line multithreaded asynchronous consumers Perform Resource Management

• Clean up done in case of exceptions

Shield differences between JMS 1.0.2/1.1 APIs Works with both APIs

(22)
(23)

Spring’s JMS Goals

0 order similarity to Spring’s JDBC supportth

Remove API noise

• One-liner send/sync-receive

• Few line multithreaded asynchronous consumers Perform Resource Management

• Clean up done in case of exceptions

Shield differences between JMS 1.0.2/1.1 APIs

• Works with both APIs

– 1.0.2/1.1 ‘flavored’ implementations provided

Destination Management

• In practice destinations are often created at runtime. Translation from checked to unchecked

exceptions

Spring’s JMS Goals

Integration with Spring’s transaction

management services

• JMS local transactions

– Group multiple send/receive operations • XA distributed transactions

– Group message consumption and database access

(24)
(25)

Spring’s JMS Goals

Integration with Spring’s transaction

management services

• JMS local transactions

– Group multiple send/receive operations • XA distributed transactions

– Group message consumption and database access

Facilitate Best Practices

• • •

POJO programming model Object/Message conversion

Direct support for Gateway design pattern

JmsTemplate

Common send/sync-receive tasks are one liners Familiar callback design for advanced scenarios Message conversion

Programmatic Example

• Sending a TextMessage to Queue String serverUrl = "tcp://localhost:7222";

(26)
(27)

JmsTemplate

Common send/sync-receive tasks are one liners Familiar callback design for advanced scenarios Message conversion

Programmatic Example

• Sending a TextMessage to Queue String serverUrl = "tcp://localhost:7222";

ConnectionFactory connFactory =

new TibjmsQueueConnectionFactory(serverUrl); JmsTemplate jmsTemplate = new JmsTemplate(connFactory); jmsTemplate.convertAndSend("partyline.queue",

"Hello World! @ “ + new Date());

JmsTemplate

Synchronous receiving from a queue

String reply =

(String) jmsTemplate.receiveAndConvert(“anotherqueue”);

Using callback to get at JMS objects

(28)

References

Related documents

Microsoft outlook that the issue solved by the outlook application, on outlook hangs send receive emails and tools and network admin, if windows update and articles and works in..

Formerly Vikrant Tyres limited had technical collaboration with techno – export foreign trade company, Praha, Czechoslovakia, for the manufacturing conventional tyres

Sun ONE Application Server provides support for applications that use the Java Message Service (JMS) application programming interface (API) for messaging operations.. JMS is a set

Spread is defined as the log percentage point difference between the trade price and the next unpaired interdealer trade, adjusted for intervening changes in the general bond

− Remote Callback: Check the box and select the remote systems to send a message (Not supported for the WebGuard program).. − Audio Alarm: Check the box and select the audio

Once you open the file with a double click you will be prompted to enter your previously defined password (chapter 4). PDF file has to be opened using a PDF reader

SYNC, SEND, RECEIVE: WHY CLOUD-BASED EMAIL AND STORAGE MAKE SENSE FOR YOUR BUSINESS 3 1 Infographic: SMB Cloud Adoption Trends in 2014, PC World, October 7,

Upvote if it of receiver for high quality and updates to choose the technical information has been redesigned to use citrix receiver to take all waiting for the files.. Question