SlideShare ist ein Scribd-Unternehmen logo
1 von 31
Spring way of messaging
JMS Basics
 The application hands the message to be send to a
message broker.
 The message broker ensures the message delivery to
the specified destination.
 JMS messages are addressed with a destination.
 Destination are of two types: queues (point-to-point
model) and topics (publish-subscribe model).
Point-to-point & Publish-subscribe
 Point-to-Point:
 Each message has exactly one sender and one receiver.
 When a receiver asks for the next message in the queue, the
message is removed from the queue and delivered to the
receiver.
 Each message in a message queue is delivered to only one
receiver.
 Publish-Subscribe:
 Messages are sent to a topic which is listened by multiple
receivers.
 All subscribers to a topic will receive a copy of the message.
Benefits of JMS
 The client doesn’t need to wait around for it to be
processed or even delivered.
 JMS messages are data-centric and the client isn’t fixed
to a specific method signature.
 JMS clients are unaware of service location and only
know the queue or topic through which the messages
will be sent.
 JMS clients are assured of guaranteed message delivery
even if the service is unavailable when a message is
sent and is stored until the service is available again.
Setting up ActiveMQ in Spring
 Add the incubator-activemq-4.1.0.jar to the application’s
classpath to access ActiveMQ’s API.
 ActiveMQConnectionFactory is the JMS connection factory
for ActiveMQ, to send messages through the message
broker.
 <bean id="connectionFactory"
 class="org.apache.activemq.ActiveMQConnectionFactory">
 <property name="brokerURL"
value="tcp://localhost:61616"/>
 </bean>
 The brokerURL property tells the connection factory where
the message broker is located
Declaring an ActiveMQ message
destination
 A message destination is declared either a queue or topic, for
passing on the messages.
 ActiveMQ queue Declaration:
 <bean id="rantzDestination"
 class="org.apache.activemq.command.ActiveMQQueue">
 <constructor-arg index="0" value="rantz.marketing.queue"/>
 </bean>
 ActiveMQ topic Declaration:
 <bean id="rantzDestination"
 class="org.apache.activemq.command.ActiveMQTopic">
 <constructor-arg index="0" value="rantz.marketing.topic"/>
 </bean>
Conventional JMS Sender
 ConnectionFactory cf =
 new ActiveMQConnectionFactory("tcp://localhost:61616");
 try {
 conn = cf.createConnection();
 session = conn.createSession(false,
 Session.AUTO_ACKNOWLEDGE);
 Destination destination = new ActiveMQQueue("myQueue");
 MessageProducer producer =
 session.createProducer(destination);
 TextMessage message = session.createTextMessage();
 message.setText("Hello world!");
 producer.send(message);
 } catch (JMSException e) { // handle Message}
Conventional JMS Receiver
 ConnectionFactory cf =
 new ActiveMQConnectionFactory("tcp://localhost:61616");
 try {
 conn = cf.createConnection();
 session = conn.createSession(false,
 Session.AUTO_ACKNOWLEDGE);
 Destination destination = new ActiveMQQueue("myQueue");
 MessageConsumer consumer = session.createConsumer(destination);
 conn.start();
 Message message = consumer.receive();
 TextMessage textMessage = (TextMessage) message;
 System.out.println("GOT A MESSAGE: " + textMessage.getText());
 } catch (JMSException e) { // handle Message}
 } finally { … }
JMS Template
 JMS Template handles creating a connection,
obtaining a session, and the actual sending and
receiving of messages.
 It handles any clumsy JMSException that may be
thrown along the way.
 When JMSException is thrown, JmsTemplate will
catch it and rethrow it as one of the unchecked
subclasses of JmsException in
org.springframework.jms.* package.
Wiring the JMS Template
 JmsTemplate needs to get connections to the message
broker, and hence sets a connectionFactory property
with a bean that implements JMS’s ConnectionFactory
interface.
 <bean id="jmsTemplate"
 class="org.springframework.jms.core.JmsTemplate">
 <property name="connectionFactory"
ref="connectionFactory" />
 </bean>
Sending Messages with JMS Templates
 public void sendMotoristInfo(final Motorist motorist) {
 jmsTemplate.send( destination, new MessageCreator() {
 public Message createMessage(Session session)
 throws JMSException {
 MapMessage message = session.createMapMessage();
 message.setString("Name", motorist.getName());
 return message;
 }
 });
 }
 private JmsTemplate jmsTemplate; // Injected
 private Destination destination; // Injected
Setting a default destination
 <bean id="jmsTemplate"
 class="org.springframework.jms.core.JmsTemplate">
 <property name="connectionFactory" ref="connectionFactory" />
 <property name="defaultDestination" ref="rantzDestination" />
 </bean>
 The call to JmsTemplate’s send() method can be simplified slightly by
removing the first parameter:
 jmsTemplate.send(
 new MessageCreator() {
 …
 });
 JmsTemplate assumes that the message sent to the default destination
when the send() method only takes a MessageCreator.
Consuming messages
 public SpammedMotorist receiveSpammedMotorist() {
 MapMessage message = (MapMessage) jmsTemplate.receive();
 SpammedMotorist motorist = new SpammedMotorist();
 try {
 motorist.setFirstName(message.getString("firstName"));
 motorist.setLastName(message.getString("lastName"));
 motorist.setEmail(message.getString("email"));
 } catch (JMSException e) {
 throw JmsUtils.convertJmsAccessException(e);
 }
 return motorist;
 }
 private JmsTemplate jmsTemplate; //injected
Consuming messages: Timeout
 JmsTemplate’s receive() method is synchronous, blocking the call
until a message appears on the destination.
 The receiveTimeout property can be used to configure
JmsTemplate to time out on receives after specified time interval.
 <bean id="jmsTemplate"
 class="org.springframework.jms.core.JmsTemplate">
 <property name="connectionFactory" ref="connectionFactory" />
 <property name="defaultDestination" ref="rantzDestination" />
 <property name="receiveTimeout" value="60000" />
 </bean>
Converting messages
 Spring supports message conversion through its
MessageConverter interface:
 public interface MessageConverter {
 public Message toMessage(Object object, Session session);
 public Object fromMessage(Message message);
 }
 For sending messages, the toMessage() method converts an
object to a Message.
 On the receiving end, the fromMessage() method converts
an incoming Message into an Object.
Implementation of MessageConverter
 public class MotoristMessageConverter implements MessageConverter {
 public Object fromMessage(Message message) throws JMSException, MessageConversionException {
 if(!(message instanceof MapMessage)) {
 throw new MessageConversionException("Message isn't a MapMessage"); }
 MapMessage mapMessage = (MapMessage) message;
 SpammedMotorist motorist = new SpammedMotorist();
 motorist.setFirstName(mapMessage.getString("firstName"));
 return motorist;
 }
 public Message toMessage(Object object, Session session) throws JMSException,
MessageConversionException {
 if(!(object instanceof Motorist)) {
 throw new MessageConversionException("Object isn't a Motorist"); }
 Motorist motorist = (Motorist) object;
 MapMessage message = session.createMapMessage();
 message.setString("firstName", motorist.getFirstName());
 return message;
 }
 }
Sending/Receiving converted messages
 The convertAndSend() method of JmsTemplate can be
simply called instead of explicitly calling the toMessage()
method before sending a message.
 JmsTemplate’s convertAndSend() method automatically
calls the toMessage() method before sending the message
to the destination.
 The receiveAndConvert() method of JmsTemplate can be
simply called instead of explicitly calling the fromMessage()
to convert the message returned from JmsTemplate’s
receive().
 Unless specified, both the convertAndSend() and
receiveAndConvert(), send and receive messages
respectively from the default destination.
Wiring a message converter
 <bean id="motoristConverter"
 class="com.roadrantz.marketing.MotoristMessageConverter" /
 <bean id="jmsTemplate"
 class="org.springframework.jms.core.JmsTemplate">
 <property name="connectionFactory" ref="connectionFactory" />
 <property name="defaultDestination" ref="rantzDestination" />
 <property name="messageConverter"
 ref="motoristConverter" />
 </bean>
Spring JMS Gateway Support
 public class RantzMarketingGatewayImpl extends JmsGatewaySupport
 implements RantzMarketingGateway {
 public void sendMotoristInfo(final Motorist motorist) {
 getJmsTemplate().send("rantz.marketing.queue",
 new MessageCreator() {
 public Message createMessage(Session session)
 throws JMSException {
 MapMessage message = session.createMapMessage();
 message.setString("firstName", motorist.getFirstName());
 return message;
 }
 });
 }
 }
Spring JMS Gateway Support
 A JmsTemplate object can be directly injected into the
jmsTemplate property, or by wiring the connection factory
into the connectionFactory property.
 JmsGatewaySupport automatically creates a JmsTemplate
object based on the injected connection factory bean wired
into the connectionFactory property.
 Shortcomings to wiring connection factory are as follows:
 Can only specify a default destination on a JmsTemplate.
 Can only wire a message converter into a JmsTemplate.
Spring Message Driven Beans
 public class MarketingMdp implements MessageListener {
 public void onMessage(Message message) {
 MapMessage mapMessage = (MapMessage) message;
 try {
 SpammedMotorist motorist = new SpammedMotorist();
 motorist.setFirstName(mapMessage.getString("firstName"));
 motorist.setLastName(mapMessage.getString("lastName"));
 motorist.setEmail(mapMessage.getString("email"));
 processMotoristInfo(motorist);
 } catch (JMSException e) { // handle—somehow }
 }
 private void processMotoristInfo(SpammedMotorist motorist) { … }
 }
 <bean id="rantzMdp“ class="com.roadrantz.marketing.MarketingMdp" />
Message Listener Container
 A message listener container watches a JMS destination for
messages and retrieves the messages on arrival.
 The retrieved messages are passed on to a MessageListener
implementation by calling the onMessage() method.
 onMessage() method is to receive and translate the message.
 SimpleMessageListenerContainer is the simplest of the message
listener containers, configured as follows:
 <bean class="org.springframework.jms.listener.
 ➥ SimpleMessageListenerContainer">
 <property name="connectionFactory" ref="connectionFactory" />
 <property name="destination" ref="rantzDestination" />
 <property name="messageListener" ref="rantzMdp" />
 </bean>
Spring Message Listener Containers
Container class
org.springframework.jms.listener.*
Operation
SimpleMessageListenerContainer This is the simplest message listener
container. It works with a fixed number of
JMS sessions and does not support
transactions.
DefaultMessageListenerContainer This message listener container builds upon
SimpleMessageListenerContainer by
adding support for transactions
serversession.ServerSessionMessage
ListenerContainer
This is the most powerful of the message
listener containers. Like
DefaultMessageListenerContainer, it
supports transactions. However it is unique
in that it allows for dynamic management
of JMS sessions.
Transactional MDPs
 DefaultMessageListenerContainer adds transaction support to the
SimpleMessageListenerContainer.
 <bean class="org.springframework.jms.listener.➥ DefaultMessageListenerContainer">
 <property name="connectionFactory" ref="connectionFactory" />
 <property name="destination" ref="rantzDestination" />
 <property name="messageListener" ref="rantzMdp" />
 <property name="transactionManager" ref="jmsTransactionManager" />
 </bean>
 The transactionManager property is wired with a reference to a transaction manager such
as JmsTransactionManager:
 <bean id="jmsTransactionManager“ class="org.springframework.jms.connection.
 ➥ JmsTransactionManager">
 <property name="connectionFactory" ref="connectionFactory" />
 </bean>
 The transactionManager property of DefaultMessageListenerContainer is optional.
Pure POJO MDP
 The message listener container calls the onMessage() method
when a message arrives, when its messageListener property
being wired with an implementation of MessageListener.
 <bean class="org.springframework.jms.listener.
 ➥ SimpleMessageListenerContainer">
 <property name="connectionFactory" ref="connectionFactory"
/>
 <property name="destination" ref="rantzDestination" />
 <property name="messageListener" ref="purePojoMdp" />
 </bean>
MessageListenerAdapter
 MessageListenerAdapter is a MessageListener that delegates to a bean and
method.
 By default, MessageListenerAdapter calls a handleMessage() method
when a message arrives.
 <bean id="purePojoMdp“
class="org.springframework.jms.listener.adapter.
 ➥ MessageListenerAdapter">
 <property name="delegate" ref="rantzMdp" />
 <property name="defaultListenerMethod“ value="processMotoristInfo" />
 </bean>
 The MessageListenerAdapter above calls the processMotoristInfo()
method (as it’s the defaultListenerMethod) on the rantzMdp bean when a
message arrives on the destination.
 When MessageListenerAdapter receives a message, it considers the
message type and the value of the defaultListenerMethod and tries to find
an appropriate listener method signature to invoke.
Mapping of JMS Message to MDP
Message type Method parameter
TextMessage String or TextMessage
MapMessage java.util.Map or MapMessage
BytesMessage byte[] or BytesMessage
ObjectMessage java.io.Serializable or ObjectMessage
 The listener method can be written to take either
the original JMS message or a simpler type.
Converting MDP messages
 Spring message converters are used to translate messages to and
from domain-specific Java types.
 MessageListenerAdapter has a messageConverter property to set
the corresponding message converter.
 <bean id="purePojoMdp“
 class="org.springframework.jms.listener.adapter.
 ➥ MessageListenerAdapter">
 <property name="delegate" ref="rantzMdp" />
 <property name="defaultListenerMethod“
value="processMotoristInfo" />
 <property name="messageConverter" ref="motoristConverter" />
 </bean>
Lingo
 Lingo is a Spring-based remoting option that bridges
the gap between RPC and asynchronous messaging.
 Lingo provides a service exporter to export bean
functionality as a Lingo service and a clientside proxy
to transparently wire a reference to a remote Lingo
service on the calling side.
 Lingo remoting carries information over a JMS queue
or topic, making the service call held in the
queue/topic until the service is available again.
Exporting Lingo Service
 Lingo provides JmsServiceExporter, a service exporter, were
services are made available through JMS.
 The service implementation implements serviceInterface and is a
pure POJO wired into a MessageListenerAdapter to be used as
message-driven POJO.
 <bean id="server"
 class="org.logicblaze.lingo.jms.JmsServiceExporter">
 <property name="connectionFactory" ref="connectionFactory" />
 <property name="destination" ref="destination" />
 <property name="service" ref="rantzMdp" />
 <property name="serviceInterface"
 value="com.roadrantz.marketing.MarketingService" />
 </bean>
Lingo JMS Proxy
 Lingo provides JmsProxyFactoryBean, a proxy factory bean that
produces proxies to remote Lingo-exported services.
 <bean id="marketing"
 class="org.logicblaze.lingo.jms.JmsProxyFactoryBean">
 <property name="connectionFactory" ref="connectionFactory" />
 <property name="destination" ref="destination" />
 <property name="serviceInterface"
 value="com.roadrantz.marketing.MarketingService" />
 </bean>
 Invoking a Lingo-exported service is no different from invoking an
RMI service, a web service, or even a method on another bean.

Weitere ähnliche Inhalte

Was ist angesagt? (20)

Hunting for security bugs in AEM webapps
Hunting for security bugs in AEM webappsHunting for security bugs in AEM webapps
Hunting for security bugs in AEM webapps
 
Nuxt.js - Introduction
Nuxt.js - IntroductionNuxt.js - Introduction
Nuxt.js - Introduction
 
Workshop 21: React Router
Workshop 21: React RouterWorkshop 21: React Router
Workshop 21: React Router
 
Spring Security 5
Spring Security 5Spring Security 5
Spring Security 5
 
Intro to React
Intro to ReactIntro to React
Intro to React
 
Express js
Express jsExpress js
Express js
 
An introduction to React.js
An introduction to React.jsAn introduction to React.js
An introduction to React.js
 
Express node js
Express node jsExpress node js
Express node js
 
Angular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP ServicesAngular - Chapter 7 - HTTP Services
Angular - Chapter 7 - HTTP Services
 
Webpack Introduction
Webpack IntroductionWebpack Introduction
Webpack Introduction
 
Web api
Web apiWeb api
Web api
 
Introduction to Hibernate Framework
Introduction to Hibernate FrameworkIntroduction to Hibernate Framework
Introduction to Hibernate Framework
 
Learn react-js
Learn react-jsLearn react-js
Learn react-js
 
Angular modules in depth
Angular modules in depthAngular modules in depth
Angular modules in depth
 
Spring Boot and REST API
Spring Boot and REST APISpring Boot and REST API
Spring Boot and REST API
 
Neat tricks to bypass CSRF-protection
Neat tricks to bypass CSRF-protectionNeat tricks to bypass CSRF-protection
Neat tricks to bypass CSRF-protection
 
Spring Framework - Data Access
Spring Framework - Data AccessSpring Framework - Data Access
Spring Framework - Data Access
 
TypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the painTypeScript: coding JavaScript without the pain
TypeScript: coding JavaScript without the pain
 
Angular
AngularAngular
Angular
 
Spring annotation
Spring annotationSpring annotation
Spring annotation
 

Andere mochten auch

Spring JMS and ActiveMQ
Spring JMS and ActiveMQSpring JMS and ActiveMQ
Spring JMS and ActiveMQGeert Pante
 
Enterprise Messaging With ActiveMQ and Spring JMS
Enterprise Messaging With ActiveMQ and Spring JMSEnterprise Messaging With ActiveMQ and Spring JMS
Enterprise Messaging With ActiveMQ and Spring JMSBruce Snyder
 
Introduction to JMS and Message-Driven POJOs
Introduction to JMS and Message-Driven POJOsIntroduction to JMS and Message-Driven POJOs
Introduction to JMS and Message-Driven POJOsMatt Stine
 
Enterprise Messaging With Spring JMS
Enterprise Messaging With Spring JMSEnterprise Messaging With Spring JMS
Enterprise Messaging With Spring JMSBruce Snyder
 
Log management with ELK
Log management with ELKLog management with ELK
Log management with ELKGeert Pante
 
jpa-hibernate-presentation
jpa-hibernate-presentationjpa-hibernate-presentation
jpa-hibernate-presentationJohn Slick
 
Spring + JPA + DAO Step by Step
Spring + JPA + DAO Step by StepSpring + JPA + DAO Step by Step
Spring + JPA + DAO Step by StepGuo Albert
 
JPA - Java Persistence API
JPA - Java Persistence APIJPA - Java Persistence API
JPA - Java Persistence APIThomas Wöhlke
 
Java Persistence API (JPA) - A Brief Overview
Java Persistence API (JPA) - A Brief OverviewJava Persistence API (JPA) - A Brief Overview
Java Persistence API (JPA) - A Brief OverviewCraig Dickson
 
Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepGuo Albert
 

Andere mochten auch (11)

Spring JMS and ActiveMQ
Spring JMS and ActiveMQSpring JMS and ActiveMQ
Spring JMS and ActiveMQ
 
Enterprise Messaging With ActiveMQ and Spring JMS
Enterprise Messaging With ActiveMQ and Spring JMSEnterprise Messaging With ActiveMQ and Spring JMS
Enterprise Messaging With ActiveMQ and Spring JMS
 
Introduction to JMS and Message-Driven POJOs
Introduction to JMS and Message-Driven POJOsIntroduction to JMS and Message-Driven POJOs
Introduction to JMS and Message-Driven POJOs
 
Enterprise Messaging With Spring JMS
Enterprise Messaging With Spring JMSEnterprise Messaging With Spring JMS
Enterprise Messaging With Spring JMS
 
Log management with ELK
Log management with ELKLog management with ELK
Log management with ELK
 
jpa-hibernate-presentation
jpa-hibernate-presentationjpa-hibernate-presentation
jpa-hibernate-presentation
 
Spring + JPA + DAO Step by Step
Spring + JPA + DAO Step by StepSpring + JPA + DAO Step by Step
Spring + JPA + DAO Step by Step
 
JPA - Java Persistence API
JPA - Java Persistence APIJPA - Java Persistence API
JPA - Java Persistence API
 
Java Persistence API (JPA) - A Brief Overview
Java Persistence API (JPA) - A Brief OverviewJava Persistence API (JPA) - A Brief Overview
Java Persistence API (JPA) - A Brief Overview
 
Java Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By StepJava Persistence API (JPA) Step By Step
Java Persistence API (JPA) Step By Step
 
Support JEE Spring Inversion de Controle IOC et Spring MVC
Support JEE Spring Inversion de Controle IOC et Spring MVCSupport JEE Spring Inversion de Controle IOC et Spring MVC
Support JEE Spring Inversion de Controle IOC et Spring MVC
 

Ähnlich wie Spring JMS (20)

Jms
JmsJms
Jms
 
Jms
JmsJms
Jms
 
Jms
JmsJms
Jms
 
Jms intro
Jms introJms intro
Jms intro
 
Jms
JmsJms
Jms
 
Jms
JmsJms
Jms
 
4Developers: Dominik Przybysz- Message Brokers
4Developers: Dominik Przybysz- Message Brokers4Developers: Dominik Przybysz- Message Brokers
4Developers: Dominik Przybysz- Message Brokers
 
Send Sms with SmsManager Api In Android with Kotlin
Send Sms with SmsManager Api In Android with KotlinSend Sms with SmsManager Api In Android with Kotlin
Send Sms with SmsManager Api In Android with Kotlin
 
Jms слайды
Jms слайдыJms слайды
Jms слайды
 
Weblogic - Introduction to configure JMS
Weblogic  - Introduction to configure JMSWeblogic  - Introduction to configure JMS
Weblogic - Introduction to configure JMS
 
Jsr120 sup
Jsr120 supJsr120 sup
Jsr120 sup
 
Test DB user
Test DB userTest DB user
Test DB user
 
test validation
test validationtest validation
test validation
 
Mule jms
Mule   jmsMule   jms
Mule jms
 
Spring ws
Spring wsSpring ws
Spring ws
 
Automapper
AutomapperAutomapper
Automapper
 
Message processor in mule
Message processor in muleMessage processor in mule
Message processor in mule
 
Mule message processor or routers
Mule message processor or routersMule message processor or routers
Mule message processor or routers
 
Jms introduction
Jms introductionJms introduction
Jms introduction
 
Jms topics
Jms topicsJms topics
Jms topics
 

Mehr von Emprovise

Highlights of AWS ReInvent 2023 (Announcements and Best Practices)
Highlights of AWS ReInvent 2023 (Announcements and Best Practices)Highlights of AWS ReInvent 2023 (Announcements and Best Practices)
Highlights of AWS ReInvent 2023 (Announcements and Best Practices)Emprovise
 
Leadership and Success Lessons for Life/Business
Leadership and Success Lessons for Life/BusinessLeadership and Success Lessons for Life/Business
Leadership and Success Lessons for Life/BusinessEmprovise
 
Secure socket layer
Secure socket layerSecure socket layer
Secure socket layerEmprovise
 
Effective java
Effective javaEffective java
Effective javaEmprovise
 
EJB3 Advance Features
EJB3 Advance FeaturesEJB3 Advance Features
EJB3 Advance FeaturesEmprovise
 
Enterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business LogicEnterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business LogicEmprovise
 
RESTful WebServices
RESTful WebServicesRESTful WebServices
RESTful WebServicesEmprovise
 
J2EE Patterns
J2EE PatternsJ2EE Patterns
J2EE PatternsEmprovise
 
Spring Web Services
Spring Web ServicesSpring Web Services
Spring Web ServicesEmprovise
 
Spring Web Webflow
Spring Web WebflowSpring Web Webflow
Spring Web WebflowEmprovise
 
Spring Web Views
Spring Web ViewsSpring Web Views
Spring Web ViewsEmprovise
 
Enterprise Spring
Enterprise SpringEnterprise Spring
Enterprise SpringEmprovise
 
Spring Basics
Spring BasicsSpring Basics
Spring BasicsEmprovise
 
Apache Struts 2 Advance
Apache Struts 2 AdvanceApache Struts 2 Advance
Apache Struts 2 AdvanceEmprovise
 
Apache Struts 2 Framework
Apache Struts 2 FrameworkApache Struts 2 Framework
Apache Struts 2 FrameworkEmprovise
 
Java Servlets
Java ServletsJava Servlets
Java ServletsEmprovise
 
Java Advance Concepts
Java Advance ConceptsJava Advance Concepts
Java Advance ConceptsEmprovise
 

Mehr von Emprovise (20)

Highlights of AWS ReInvent 2023 (Announcements and Best Practices)
Highlights of AWS ReInvent 2023 (Announcements and Best Practices)Highlights of AWS ReInvent 2023 (Announcements and Best Practices)
Highlights of AWS ReInvent 2023 (Announcements and Best Practices)
 
Leadership and Success Lessons for Life/Business
Leadership and Success Lessons for Life/BusinessLeadership and Success Lessons for Life/Business
Leadership and Success Lessons for Life/Business
 
Secure socket layer
Secure socket layerSecure socket layer
Secure socket layer
 
Effective java
Effective javaEffective java
Effective java
 
EJB3 Advance Features
EJB3 Advance FeaturesEJB3 Advance Features
EJB3 Advance Features
 
Enterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business LogicEnterprise Java Beans 3 - Business Logic
Enterprise Java Beans 3 - Business Logic
 
EJB3 Basics
EJB3 BasicsEJB3 Basics
EJB3 Basics
 
RESTful WebServices
RESTful WebServicesRESTful WebServices
RESTful WebServices
 
J2EE Patterns
J2EE PatternsJ2EE Patterns
J2EE Patterns
 
JMS
JMSJMS
JMS
 
Spring Web Services
Spring Web ServicesSpring Web Services
Spring Web Services
 
Spring Web Webflow
Spring Web WebflowSpring Web Webflow
Spring Web Webflow
 
Spring Web Views
Spring Web ViewsSpring Web Views
Spring Web Views
 
Spring MVC
Spring MVCSpring MVC
Spring MVC
 
Enterprise Spring
Enterprise SpringEnterprise Spring
Enterprise Spring
 
Spring Basics
Spring BasicsSpring Basics
Spring Basics
 
Apache Struts 2 Advance
Apache Struts 2 AdvanceApache Struts 2 Advance
Apache Struts 2 Advance
 
Apache Struts 2 Framework
Apache Struts 2 FrameworkApache Struts 2 Framework
Apache Struts 2 Framework
 
Java Servlets
Java ServletsJava Servlets
Java Servlets
 
Java Advance Concepts
Java Advance ConceptsJava Advance Concepts
Java Advance Concepts
 

Kürzlich hochgeladen

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamUiPathCommunity
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...apidays
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsNanddeep Nachan
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Orbitshub
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024The Digital Insurer
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDropbox
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native ApplicationsWSO2
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Victor Rentea
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfOverkill Security
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobeapidays
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAndrey Devyatkin
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfOverkill Security
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfOrbitshub
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...Zilliz
 

Kürzlich hochgeladen (20)

TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 AmsterdamDEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
DEV meet-up UiPath Document Understanding May 7 2024 Amsterdam
 
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
Apidays New York 2024 - Accelerating FinTech Innovation by Vasa Krishnan, Fin...
 
MS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectorsMS Copilot expands with MS Graph connectors
MS Copilot expands with MS Graph connectors
 
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
Navigating the Deluge_ Dubai Floods and the Resilience of Dubai International...
 
AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024AXA XL - Insurer Innovation Award Americas 2024
AXA XL - Insurer Innovation Award Americas 2024
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Architecting Cloud Native Applications
Architecting Cloud Native ApplicationsArchitecting Cloud Native Applications
Architecting Cloud Native Applications
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Cyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdfCyberprint. Dark Pink Apt Group [EN].pdf
Cyberprint. Dark Pink Apt Group [EN].pdf
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
AWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of TerraformAWS Community Day CPH - Three problems of Terraform
AWS Community Day CPH - Three problems of Terraform
 
Ransomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdfRansomware_Q4_2023. The report. [EN].pdf
Ransomware_Q4_2023. The report. [EN].pdf
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ..."I see eyes in my soup": How Delivery Hero implemented the safety system for ...
"I see eyes in my soup": How Delivery Hero implemented the safety system for ...
 

Spring JMS

  • 1. Spring way of messaging
  • 2. JMS Basics  The application hands the message to be send to a message broker.  The message broker ensures the message delivery to the specified destination.  JMS messages are addressed with a destination.  Destination are of two types: queues (point-to-point model) and topics (publish-subscribe model).
  • 3. Point-to-point & Publish-subscribe  Point-to-Point:  Each message has exactly one sender and one receiver.  When a receiver asks for the next message in the queue, the message is removed from the queue and delivered to the receiver.  Each message in a message queue is delivered to only one receiver.  Publish-Subscribe:  Messages are sent to a topic which is listened by multiple receivers.  All subscribers to a topic will receive a copy of the message.
  • 4. Benefits of JMS  The client doesn’t need to wait around for it to be processed or even delivered.  JMS messages are data-centric and the client isn’t fixed to a specific method signature.  JMS clients are unaware of service location and only know the queue or topic through which the messages will be sent.  JMS clients are assured of guaranteed message delivery even if the service is unavailable when a message is sent and is stored until the service is available again.
  • 5. Setting up ActiveMQ in Spring  Add the incubator-activemq-4.1.0.jar to the application’s classpath to access ActiveMQ’s API.  ActiveMQConnectionFactory is the JMS connection factory for ActiveMQ, to send messages through the message broker.  <bean id="connectionFactory"  class="org.apache.activemq.ActiveMQConnectionFactory">  <property name="brokerURL" value="tcp://localhost:61616"/>  </bean>  The brokerURL property tells the connection factory where the message broker is located
  • 6. Declaring an ActiveMQ message destination  A message destination is declared either a queue or topic, for passing on the messages.  ActiveMQ queue Declaration:  <bean id="rantzDestination"  class="org.apache.activemq.command.ActiveMQQueue">  <constructor-arg index="0" value="rantz.marketing.queue"/>  </bean>  ActiveMQ topic Declaration:  <bean id="rantzDestination"  class="org.apache.activemq.command.ActiveMQTopic">  <constructor-arg index="0" value="rantz.marketing.topic"/>  </bean>
  • 7. Conventional JMS Sender  ConnectionFactory cf =  new ActiveMQConnectionFactory("tcp://localhost:61616");  try {  conn = cf.createConnection();  session = conn.createSession(false,  Session.AUTO_ACKNOWLEDGE);  Destination destination = new ActiveMQQueue("myQueue");  MessageProducer producer =  session.createProducer(destination);  TextMessage message = session.createTextMessage();  message.setText("Hello world!");  producer.send(message);  } catch (JMSException e) { // handle Message}
  • 8. Conventional JMS Receiver  ConnectionFactory cf =  new ActiveMQConnectionFactory("tcp://localhost:61616");  try {  conn = cf.createConnection();  session = conn.createSession(false,  Session.AUTO_ACKNOWLEDGE);  Destination destination = new ActiveMQQueue("myQueue");  MessageConsumer consumer = session.createConsumer(destination);  conn.start();  Message message = consumer.receive();  TextMessage textMessage = (TextMessage) message;  System.out.println("GOT A MESSAGE: " + textMessage.getText());  } catch (JMSException e) { // handle Message}  } finally { … }
  • 9. JMS Template  JMS Template handles creating a connection, obtaining a session, and the actual sending and receiving of messages.  It handles any clumsy JMSException that may be thrown along the way.  When JMSException is thrown, JmsTemplate will catch it and rethrow it as one of the unchecked subclasses of JmsException in org.springframework.jms.* package.
  • 10. Wiring the JMS Template  JmsTemplate needs to get connections to the message broker, and hence sets a connectionFactory property with a bean that implements JMS’s ConnectionFactory interface.  <bean id="jmsTemplate"  class="org.springframework.jms.core.JmsTemplate">  <property name="connectionFactory" ref="connectionFactory" />  </bean>
  • 11. Sending Messages with JMS Templates  public void sendMotoristInfo(final Motorist motorist) {  jmsTemplate.send( destination, new MessageCreator() {  public Message createMessage(Session session)  throws JMSException {  MapMessage message = session.createMapMessage();  message.setString("Name", motorist.getName());  return message;  }  });  }  private JmsTemplate jmsTemplate; // Injected  private Destination destination; // Injected
  • 12. Setting a default destination  <bean id="jmsTemplate"  class="org.springframework.jms.core.JmsTemplate">  <property name="connectionFactory" ref="connectionFactory" />  <property name="defaultDestination" ref="rantzDestination" />  </bean>  The call to JmsTemplate’s send() method can be simplified slightly by removing the first parameter:  jmsTemplate.send(  new MessageCreator() {  …  });  JmsTemplate assumes that the message sent to the default destination when the send() method only takes a MessageCreator.
  • 13. Consuming messages  public SpammedMotorist receiveSpammedMotorist() {  MapMessage message = (MapMessage) jmsTemplate.receive();  SpammedMotorist motorist = new SpammedMotorist();  try {  motorist.setFirstName(message.getString("firstName"));  motorist.setLastName(message.getString("lastName"));  motorist.setEmail(message.getString("email"));  } catch (JMSException e) {  throw JmsUtils.convertJmsAccessException(e);  }  return motorist;  }  private JmsTemplate jmsTemplate; //injected
  • 14. Consuming messages: Timeout  JmsTemplate’s receive() method is synchronous, blocking the call until a message appears on the destination.  The receiveTimeout property can be used to configure JmsTemplate to time out on receives after specified time interval.  <bean id="jmsTemplate"  class="org.springframework.jms.core.JmsTemplate">  <property name="connectionFactory" ref="connectionFactory" />  <property name="defaultDestination" ref="rantzDestination" />  <property name="receiveTimeout" value="60000" />  </bean>
  • 15. Converting messages  Spring supports message conversion through its MessageConverter interface:  public interface MessageConverter {  public Message toMessage(Object object, Session session);  public Object fromMessage(Message message);  }  For sending messages, the toMessage() method converts an object to a Message.  On the receiving end, the fromMessage() method converts an incoming Message into an Object.
  • 16. Implementation of MessageConverter  public class MotoristMessageConverter implements MessageConverter {  public Object fromMessage(Message message) throws JMSException, MessageConversionException {  if(!(message instanceof MapMessage)) {  throw new MessageConversionException("Message isn't a MapMessage"); }  MapMessage mapMessage = (MapMessage) message;  SpammedMotorist motorist = new SpammedMotorist();  motorist.setFirstName(mapMessage.getString("firstName"));  return motorist;  }  public Message toMessage(Object object, Session session) throws JMSException, MessageConversionException {  if(!(object instanceof Motorist)) {  throw new MessageConversionException("Object isn't a Motorist"); }  Motorist motorist = (Motorist) object;  MapMessage message = session.createMapMessage();  message.setString("firstName", motorist.getFirstName());  return message;  }  }
  • 17. Sending/Receiving converted messages  The convertAndSend() method of JmsTemplate can be simply called instead of explicitly calling the toMessage() method before sending a message.  JmsTemplate’s convertAndSend() method automatically calls the toMessage() method before sending the message to the destination.  The receiveAndConvert() method of JmsTemplate can be simply called instead of explicitly calling the fromMessage() to convert the message returned from JmsTemplate’s receive().  Unless specified, both the convertAndSend() and receiveAndConvert(), send and receive messages respectively from the default destination.
  • 18. Wiring a message converter  <bean id="motoristConverter"  class="com.roadrantz.marketing.MotoristMessageConverter" /  <bean id="jmsTemplate"  class="org.springframework.jms.core.JmsTemplate">  <property name="connectionFactory" ref="connectionFactory" />  <property name="defaultDestination" ref="rantzDestination" />  <property name="messageConverter"  ref="motoristConverter" />  </bean>
  • 19. Spring JMS Gateway Support  public class RantzMarketingGatewayImpl extends JmsGatewaySupport  implements RantzMarketingGateway {  public void sendMotoristInfo(final Motorist motorist) {  getJmsTemplate().send("rantz.marketing.queue",  new MessageCreator() {  public Message createMessage(Session session)  throws JMSException {  MapMessage message = session.createMapMessage();  message.setString("firstName", motorist.getFirstName());  return message;  }  });  }  }
  • 20. Spring JMS Gateway Support  A JmsTemplate object can be directly injected into the jmsTemplate property, or by wiring the connection factory into the connectionFactory property.  JmsGatewaySupport automatically creates a JmsTemplate object based on the injected connection factory bean wired into the connectionFactory property.  Shortcomings to wiring connection factory are as follows:  Can only specify a default destination on a JmsTemplate.  Can only wire a message converter into a JmsTemplate.
  • 21. Spring Message Driven Beans  public class MarketingMdp implements MessageListener {  public void onMessage(Message message) {  MapMessage mapMessage = (MapMessage) message;  try {  SpammedMotorist motorist = new SpammedMotorist();  motorist.setFirstName(mapMessage.getString("firstName"));  motorist.setLastName(mapMessage.getString("lastName"));  motorist.setEmail(mapMessage.getString("email"));  processMotoristInfo(motorist);  } catch (JMSException e) { // handle—somehow }  }  private void processMotoristInfo(SpammedMotorist motorist) { … }  }  <bean id="rantzMdp“ class="com.roadrantz.marketing.MarketingMdp" />
  • 22. Message Listener Container  A message listener container watches a JMS destination for messages and retrieves the messages on arrival.  The retrieved messages are passed on to a MessageListener implementation by calling the onMessage() method.  onMessage() method is to receive and translate the message.  SimpleMessageListenerContainer is the simplest of the message listener containers, configured as follows:  <bean class="org.springframework.jms.listener.  ➥ SimpleMessageListenerContainer">  <property name="connectionFactory" ref="connectionFactory" />  <property name="destination" ref="rantzDestination" />  <property name="messageListener" ref="rantzMdp" />  </bean>
  • 23. Spring Message Listener Containers Container class org.springframework.jms.listener.* Operation SimpleMessageListenerContainer This is the simplest message listener container. It works with a fixed number of JMS sessions and does not support transactions. DefaultMessageListenerContainer This message listener container builds upon SimpleMessageListenerContainer by adding support for transactions serversession.ServerSessionMessage ListenerContainer This is the most powerful of the message listener containers. Like DefaultMessageListenerContainer, it supports transactions. However it is unique in that it allows for dynamic management of JMS sessions.
  • 24. Transactional MDPs  DefaultMessageListenerContainer adds transaction support to the SimpleMessageListenerContainer.  <bean class="org.springframework.jms.listener.➥ DefaultMessageListenerContainer">  <property name="connectionFactory" ref="connectionFactory" />  <property name="destination" ref="rantzDestination" />  <property name="messageListener" ref="rantzMdp" />  <property name="transactionManager" ref="jmsTransactionManager" />  </bean>  The transactionManager property is wired with a reference to a transaction manager such as JmsTransactionManager:  <bean id="jmsTransactionManager“ class="org.springframework.jms.connection.  ➥ JmsTransactionManager">  <property name="connectionFactory" ref="connectionFactory" />  </bean>  The transactionManager property of DefaultMessageListenerContainer is optional.
  • 25. Pure POJO MDP  The message listener container calls the onMessage() method when a message arrives, when its messageListener property being wired with an implementation of MessageListener.  <bean class="org.springframework.jms.listener.  ➥ SimpleMessageListenerContainer">  <property name="connectionFactory" ref="connectionFactory" />  <property name="destination" ref="rantzDestination" />  <property name="messageListener" ref="purePojoMdp" />  </bean>
  • 26. MessageListenerAdapter  MessageListenerAdapter is a MessageListener that delegates to a bean and method.  By default, MessageListenerAdapter calls a handleMessage() method when a message arrives.  <bean id="purePojoMdp“ class="org.springframework.jms.listener.adapter.  ➥ MessageListenerAdapter">  <property name="delegate" ref="rantzMdp" />  <property name="defaultListenerMethod“ value="processMotoristInfo" />  </bean>  The MessageListenerAdapter above calls the processMotoristInfo() method (as it’s the defaultListenerMethod) on the rantzMdp bean when a message arrives on the destination.  When MessageListenerAdapter receives a message, it considers the message type and the value of the defaultListenerMethod and tries to find an appropriate listener method signature to invoke.
  • 27. Mapping of JMS Message to MDP Message type Method parameter TextMessage String or TextMessage MapMessage java.util.Map or MapMessage BytesMessage byte[] or BytesMessage ObjectMessage java.io.Serializable or ObjectMessage  The listener method can be written to take either the original JMS message or a simpler type.
  • 28. Converting MDP messages  Spring message converters are used to translate messages to and from domain-specific Java types.  MessageListenerAdapter has a messageConverter property to set the corresponding message converter.  <bean id="purePojoMdp“  class="org.springframework.jms.listener.adapter.  ➥ MessageListenerAdapter">  <property name="delegate" ref="rantzMdp" />  <property name="defaultListenerMethod“ value="processMotoristInfo" />  <property name="messageConverter" ref="motoristConverter" />  </bean>
  • 29. Lingo  Lingo is a Spring-based remoting option that bridges the gap between RPC and asynchronous messaging.  Lingo provides a service exporter to export bean functionality as a Lingo service and a clientside proxy to transparently wire a reference to a remote Lingo service on the calling side.  Lingo remoting carries information over a JMS queue or topic, making the service call held in the queue/topic until the service is available again.
  • 30. Exporting Lingo Service  Lingo provides JmsServiceExporter, a service exporter, were services are made available through JMS.  The service implementation implements serviceInterface and is a pure POJO wired into a MessageListenerAdapter to be used as message-driven POJO.  <bean id="server"  class="org.logicblaze.lingo.jms.JmsServiceExporter">  <property name="connectionFactory" ref="connectionFactory" />  <property name="destination" ref="destination" />  <property name="service" ref="rantzMdp" />  <property name="serviceInterface"  value="com.roadrantz.marketing.MarketingService" />  </bean>
  • 31. Lingo JMS Proxy  Lingo provides JmsProxyFactoryBean, a proxy factory bean that produces proxies to remote Lingo-exported services.  <bean id="marketing"  class="org.logicblaze.lingo.jms.JmsProxyFactoryBean">  <property name="connectionFactory" ref="connectionFactory" />  <property name="destination" ref="destination" />  <property name="serviceInterface"  value="com.roadrantz.marketing.MarketingService" />  </bean>  Invoking a Lingo-exported service is no different from invoking an RMI service, a web service, or even a method on another bean.