SlideShare uma empresa Scribd logo
1 de 19
Spring JMS with
ActiveMQ
ENTERPRISE MESSAGING
Point-to-Point messaging
Queue’s
Messages are delivered once and only once
◦ Kept in the queue when listener is not available
◦ Sent to only one consumer when multiple are available
◦ Client acknowledge: wait for consumer to acknowledge before removing the message
◦ Prefetch: multiple messages can be reserved for a consumer
◦ Client timeout: if no ack or reject is received, queue will consider the consumer dead
◦ Order not guaranteed with multiple queue’s
◦ Redelivery Policy
◦ Set on client side
◦ Retry after reject or use Dead Letter Queue
Selectors and Message Groups
Selectors: Server side filtering
◦ Consumer can register a filter when connecting
◦ Filtering will be done on the server
◦ ActiveMQ supports selectors for JMS Headers and XPaths for XML Messages.
◦ No JSON
Message Groups: guaranteed ordering
◦ If messages are correlated and relative order is important
◦ Add JMSXGroupID Header
◦ All messages with the same groupId will be processed by the same consumer
◦ Group mappings are kept in-memory on the server.
◦ Need to close groups properly
◦ Could fail after a failover
Publish/Subscribe
Topics
Write one message, will be received by all subscribers.
◦ Looser coupling between producer and consumer
When no subscribers are available, the message is not saved.
Perfect for frontend – backend communication
◦ Backend post a teaserChange on a topic
◦ All frontends showing the teaserList are subscribed on that topic
Not suited for server – to – server communication
◦ Clustered service will receive each messages on every node
CompositeTopic a.k.a. VirtualTopic
Configure queue’s on the server which listen to a topic
◦ Queue’s will buffer messages when subscribers are temporary offline
◦ Messages will be received exactly once per Queue
◦ Queue per interested service
◦ Decouple producer from consumer
◦ Unless queue’s are full :-)
<virtualDestinations>
<compositeTopic name="redsys.publishing.publishfeed">
<forwardTo>
<queue physicalName="redsys.moonriser.consumer.publishing.publishfeed"/>
<queue physicalName="redsys.sitemanagement.consumer.publishing.publishfeed"/>
<queue physicalName="redsys.publishingeventprocessor.consumer.publishing.publisheventfeed"/>
</forwardTo>
</compositeTopic>
ActiveMQ Storage configuration
ActiveMQ will try to keep as much messages in memory as possible
Flushes to disk if one queue goes over 69% mem, or total mem usage goes over 80%
If disk storage gets over 80%, producers are first slowed down, then blocked
Selectors don’t work on flushed messages
◦ Need to wait until other messages are consumed
JMS API
Spring JMS
Synchronous Messaging
// Use the default destination
jmsTemplate.convertAndSend("Hello World!");
// Use a different destination
jmsTemplate.convertAndSend(“TEST.BAR”, “Hello World!”);
// Use a default destination
String textMessage1 = (String) jmsTemplate.receiveAndConvert();
// Use a different destination
String textMessage2 = (String) jmsTemplate.receiveAndConvert(“TEST.BAR”);
<bean id="connectionFactory"
class="org.apache.activemq.ActiveMQConnectionFactory"
p:brokerURL="tcp://localhost:61616" />
<bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate"
p:connectionFactory-ref="connectionFactory"
p:defaultDestination-ref="destination" />
MessageConvertors
Maps java objects to message payloads
◦ ObjectMessage: java serialization
◦ TextMessage: Jackson (JSON) or Jaxb (XML)
◦ Jackson inserts a JMS Header with the fully qualified classname by default
◦ Can reuse Spring MVC ObjectMapper
Asynchronous Messaging
class MyMessageListener{
public Result onMessage(Action a){ // input parameters will be unmarshalled if necessary (jackson/jaxb)
// can also receive message headers as input parameters
// non-void results will be sent to a response queue
// auto-acknowledges if no exceptions thrown
}
}
<bean id="connectionFactory"
class="org.apache.activemq.ActiveMQConnectionFactory"
p:brokerURL="tcp://localhost:61616" />
<bean id="messageListener“ class="org.bsnyder.spring.jms.listener.MyMessageListener" />
<jms:listener-container concurrency="5-10“container-type=“simple|default”>
<jms:listener destination="FOO.TEST" ref="messageListener“ method=“onMessage”/>
</jms:listener-container>
MessageListenerContainer options
• DefaultMessageListenerContainer
– Spring launches threads
◦ while(…){ consumer.receive(); }
– Allows for dynamic scaling of queue consumers
– Participates in external transactions
• SimpleMessageListenerContainer
– consumer.setMessageListener(myListener);
◦ JMS Provider manages ThreadPool
– No external transaction support
– Works better with MockRunner JMS
JMS Resource Pooling
Managed ConnectionFactory
◦ JCA Resource Adapter in JBoss
◦ ConnectionFactory bound in JNDI, no pooling in application
Unmanaged broker
◦ Define pure ActiveMQConnectionFactory in Spring
◦ Wrap in org.apache.activemq.pool.PooledConnectionFactory
◦ Also possible: Spring CachingConnectionFactory
◦ Caches Sessions, too
ActiveMQ Client Configuration
ActiveMQ namespace for spring configuration
Same configuration format as server
<connectionFactory xmlns="http://activemq.apache.org/schema/core"
brokerURL="${activeMQ.brokerURL}"
userName="${activeMQ.username}"
password="${activeMQ.password}">
<redeliveryPolicyMap>
<redeliveryPolicyMap>
<defaultEntry>
<redeliveryPolicy maximumRedeliveries="2"/>
</defaultEntry>
</redeliveryPolicyMap>
</redeliveryPolicyMap>
</connectionFactory>
Transactions
JmsTransactionManager
◦ Injected in JmsTemplate and (Default)MessageListenerContainers
◦ Transactional behaviour across JMS Senders/Receivers
◦ All calls use the same JMS Session
◦ Acknowledgements are only processed when whole session is committed
JtaTransactionManager
◦ JMS Sessions are synchronized with XA Database transactions
◦ Here be dragons…
Testing
Unit tests
◦ Call message listeners directly
◦ Mockito.mock(JmsTemplate.class)
Component Integration Tests
◦ Use mockrunner-jms
System Tests
◦ Use embedded ActiveMQ broker
<amq:broker persistent="false" useJmx="false" id="embeddedBroker">
<amq:transportConnectors>
<amq:transportConnector uri="tcp://localhost:#{freePortSelector}"/>
</amq:transportConnectors>
</amq:broker>
<amq:connectionFactory id="jmsFactory" brokerURL="vm://localhost"/>
@Bean
public JMSMockObjectFactory jmsMockObjectFactory() { return new JMSMockObjectFactory();}
@Bean
public ConnectionFactory connectionFactory() { return jmsMockObjectFactory().getMockConnectionFactory();}
@Bean
public JMSTestModule jmsTestModule() { return new JMSTestModule(jmsMockObjectFactory());}
Q&A

Mais conteúdo relacionado

Mais procurados

JMS Providers Overview
JMS Providers OverviewJMS Providers Overview
JMS Providers OverviewVadym Lotar
 
Apache ActiveMQ and Apache ServiceMix
Apache ActiveMQ and Apache ServiceMixApache ActiveMQ and Apache ServiceMix
Apache ActiveMQ and Apache ServiceMixBruce Snyder
 
Messaging With ActiveMQ
Messaging With ActiveMQMessaging With ActiveMQ
Messaging With ActiveMQBruce Snyder
 
NServiceBus workshop presentation
NServiceBus workshop presentationNServiceBus workshop presentation
NServiceBus workshop presentationTomas Jansson
 
Scalable Persistent Message Brokering with WSO2 Message Broker
Scalable Persistent Message Brokering with WSO2 Message BrokerScalable Persistent Message Brokering with WSO2 Message Broker
Scalable Persistent Message Brokering with WSO2 Message BrokerSrinath Perera
 
ActiveMQ In Action - ApacheCon 2011
ActiveMQ In Action - ApacheCon 2011ActiveMQ In Action - ApacheCon 2011
ActiveMQ In Action - ApacheCon 2011Bruce Snyder
 
WebLogic JMS System Best Practices
WebLogic JMS System Best PracticesWebLogic JMS System Best Practices
WebLogic JMS System Best PracticesTrivadis
 
Introduction to NServiceBus
Introduction to NServiceBusIntroduction to NServiceBus
Introduction to NServiceBusAdam Fyles
 
Introduction to NServiceBus
Introduction to NServiceBusIntroduction to NServiceBus
Introduction to NServiceBusEspen Ekvang
 
Architectures with Windows Azure
Architectures with Windows AzureArchitectures with Windows Azure
Architectures with Windows AzureDamir Dobric
 
Andes: a Scalable persistent Messaging System
Andes: a Scalable persistent Messaging SystemAndes: a Scalable persistent Messaging System
Andes: a Scalable persistent Messaging SystemSrinath Perera
 
Rabbit MQ introduction
Rabbit MQ introductionRabbit MQ introduction
Rabbit MQ introductionShirish Bari
 
Making communications across boundaries simple with NServiceBus
Making communications across boundaries simple with NServiceBusMaking communications across boundaries simple with NServiceBus
Making communications across boundaries simple with NServiceBusParticular Software
 
Introduction tojms
Introduction tojmsIntroduction tojms
Introduction tojmsMaya Swamy
 
NServiceBus - introduction to a message based distributed architecture
NServiceBus - introduction to a message based distributed architectureNServiceBus - introduction to a message based distributed architecture
NServiceBus - introduction to a message based distributed architectureMauro Servienti
 
RabbitMQ - message broker
RabbitMQ - message brokerRabbitMQ - message broker
RabbitMQ - message brokerVít Kutný
 

Mais procurados (20)

JMS Providers Overview
JMS Providers OverviewJMS Providers Overview
JMS Providers Overview
 
Apache ActiveMQ and Apache ServiceMix
Apache ActiveMQ and Apache ServiceMixApache ActiveMQ and Apache ServiceMix
Apache ActiveMQ and Apache ServiceMix
 
Messaging With ActiveMQ
Messaging With ActiveMQMessaging With ActiveMQ
Messaging With ActiveMQ
 
NServiceBus workshop presentation
NServiceBus workshop presentationNServiceBus workshop presentation
NServiceBus workshop presentation
 
Scalable Persistent Message Brokering with WSO2 Message Broker
Scalable Persistent Message Brokering with WSO2 Message BrokerScalable Persistent Message Brokering with WSO2 Message Broker
Scalable Persistent Message Brokering with WSO2 Message Broker
 
ActiveMQ In Action - ApacheCon 2011
ActiveMQ In Action - ApacheCon 2011ActiveMQ In Action - ApacheCon 2011
ActiveMQ In Action - ApacheCon 2011
 
WebLogic JMS System Best Practices
WebLogic JMS System Best PracticesWebLogic JMS System Best Practices
WebLogic JMS System Best Practices
 
AMQP 1.0 introduction
AMQP 1.0 introductionAMQP 1.0 introduction
AMQP 1.0 introduction
 
Introduction to NServiceBus
Introduction to NServiceBusIntroduction to NServiceBus
Introduction to NServiceBus
 
Introduction to NServiceBus
Introduction to NServiceBusIntroduction to NServiceBus
Introduction to NServiceBus
 
Differences between JMS and AMQP
Differences between JMS and AMQPDifferences between JMS and AMQP
Differences between JMS and AMQP
 
Architectures with Windows Azure
Architectures with Windows AzureArchitectures with Windows Azure
Architectures with Windows Azure
 
Rabbitmq basics
Rabbitmq basicsRabbitmq basics
Rabbitmq basics
 
Andes: a Scalable persistent Messaging System
Andes: a Scalable persistent Messaging SystemAndes: a Scalable persistent Messaging System
Andes: a Scalable persistent Messaging System
 
Rabbit MQ introduction
Rabbit MQ introductionRabbit MQ introduction
Rabbit MQ introduction
 
Making communications across boundaries simple with NServiceBus
Making communications across boundaries simple with NServiceBusMaking communications across boundaries simple with NServiceBus
Making communications across boundaries simple with NServiceBus
 
RabbitMq
RabbitMqRabbitMq
RabbitMq
 
Introduction tojms
Introduction tojmsIntroduction tojms
Introduction tojms
 
NServiceBus - introduction to a message based distributed architecture
NServiceBus - introduction to a message based distributed architectureNServiceBus - introduction to a message based distributed architecture
NServiceBus - introduction to a message based distributed architecture
 
RabbitMQ - message broker
RabbitMQ - message brokerRabbitMQ - message broker
RabbitMQ - message broker
 

Destaque

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
 
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
 

Destaque (9)

Spring JMS
Spring JMSSpring JMS
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
 
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
 

Semelhante a Spring JMS and ActiveMQ

Introduction to Kafka and Event-Driven
Introduction to Kafka and Event-DrivenIntroduction to Kafka and Event-Driven
Introduction to Kafka and Event-DrivenDimosthenis Botsaris
 
Introduction to Kafka and Event-Driven
Introduction to Kafka and Event-DrivenIntroduction to Kafka and Event-Driven
Introduction to Kafka and Event-Drivenarconsis
 
Mule message processor or routers
Mule message processor or routersMule message processor or routers
Mule message processor or routerssathyaraj Anand
 
Message processor in mule
Message processor in muleMessage processor in mule
Message processor in muleSon Nguyen
 
Linked In Stream Processing Meetup - Apache Pulsar
Linked In Stream Processing Meetup - Apache PulsarLinked In Stream Processing Meetup - Apache Pulsar
Linked In Stream Processing Meetup - Apache PulsarKarthik Ramasamy
 
Controlling Message Flow - Mule ESB
Controlling Message Flow - Mule ESBControlling Message Flow - Mule ESB
Controlling Message Flow - Mule ESBMani Rathnam Gudi
 
Distributed messaging with Apache Kafka
Distributed messaging with Apache KafkaDistributed messaging with Apache Kafka
Distributed messaging with Apache KafkaSaumitra Srivastav
 
Mule message processor or routers
Mule message processor or routersMule message processor or routers
Mule message processor or routersSon Nguyen
 
Ranker jms implementation
Ranker jms implementationRanker jms implementation
Ranker jms implementationEosSoftware
 
Scaling customer engagement with apache pulsar
Scaling customer engagement with apache pulsarScaling customer engagement with apache pulsar
Scaling customer engagement with apache pulsarStreamNative
 
Apache Kafka Introduction
Apache Kafka IntroductionApache Kafka Introduction
Apache Kafka IntroductionAmita Mirajkar
 
Understanding JMS Integration Patterns
Understanding JMS Integration Patterns Understanding JMS Integration Patterns
Understanding JMS Integration Patterns WSO2
 
JMS Introduction
JMS IntroductionJMS Introduction
JMS IntroductionAlex Su
 
Using the JMS 2.0 API with Apache Pulsar - Pulsar Virtual Summit Europe 2021
Using the JMS 2.0 API with Apache Pulsar - Pulsar Virtual Summit Europe 2021Using the JMS 2.0 API with Apache Pulsar - Pulsar Virtual Summit Europe 2021
Using the JMS 2.0 API with Apache Pulsar - Pulsar Virtual Summit Europe 2021StreamNative
 
Introduction to apache zoo keeper
Introduction to apache zoo keeper Introduction to apache zoo keeper
Introduction to apache zoo keeper Omid Vahdaty
 
Copy of Kafka-Camus
Copy of Kafka-CamusCopy of Kafka-Camus
Copy of Kafka-CamusDeep Shah
 

Semelhante a Spring JMS and ActiveMQ (20)

Introduction to Kafka and Event-Driven
Introduction to Kafka and Event-DrivenIntroduction to Kafka and Event-Driven
Introduction to Kafka and Event-Driven
 
Introduction to Kafka and Event-Driven
Introduction to Kafka and Event-DrivenIntroduction to Kafka and Event-Driven
Introduction to Kafka and Event-Driven
 
Mule message processor or routers
Mule message processor or routersMule message processor or routers
Mule message processor or routers
 
Message processor in mule
Message processor in muleMessage processor in mule
Message processor in mule
 
Linked In Stream Processing Meetup - Apache Pulsar
Linked In Stream Processing Meetup - Apache PulsarLinked In Stream Processing Meetup - Apache Pulsar
Linked In Stream Processing Meetup - Apache Pulsar
 
Controlling Message Flow - Mule ESB
Controlling Message Flow - Mule ESBControlling Message Flow - Mule ESB
Controlling Message Flow - Mule ESB
 
Controlling message flow
Controlling message flowControlling message flow
Controlling message flow
 
Distributed messaging with Apache Kafka
Distributed messaging with Apache KafkaDistributed messaging with Apache Kafka
Distributed messaging with Apache Kafka
 
Mule message processor or routers
Mule message processor or routersMule message processor or routers
Mule message processor or routers
 
Ranker jms implementation
Ranker jms implementationRanker jms implementation
Ranker jms implementation
 
Scaling customer engagement with apache pulsar
Scaling customer engagement with apache pulsarScaling customer engagement with apache pulsar
Scaling customer engagement with apache pulsar
 
Apache Kafka Introduction
Apache Kafka IntroductionApache Kafka Introduction
Apache Kafka Introduction
 
Understanding JMS Integration Patterns
Understanding JMS Integration Patterns Understanding JMS Integration Patterns
Understanding JMS Integration Patterns
 
Kafka blr-meetup-presentation - Kafka internals
Kafka blr-meetup-presentation - Kafka internalsKafka blr-meetup-presentation - Kafka internals
Kafka blr-meetup-presentation - Kafka internals
 
JMS Introduction
JMS IntroductionJMS Introduction
JMS Introduction
 
Kafka Deep Dive
Kafka Deep DiveKafka Deep Dive
Kafka Deep Dive
 
Using the JMS 2.0 API with Apache Pulsar - Pulsar Virtual Summit Europe 2021
Using the JMS 2.0 API with Apache Pulsar - Pulsar Virtual Summit Europe 2021Using the JMS 2.0 API with Apache Pulsar - Pulsar Virtual Summit Europe 2021
Using the JMS 2.0 API with Apache Pulsar - Pulsar Virtual Summit Europe 2021
 
Jms using j boss
Jms using j bossJms using j boss
Jms using j boss
 
Introduction to apache zoo keeper
Introduction to apache zoo keeper Introduction to apache zoo keeper
Introduction to apache zoo keeper
 
Copy of Kafka-Camus
Copy of Kafka-CamusCopy of Kafka-Camus
Copy of Kafka-Camus
 

Mais de Geert Pante

OAuth2 and OpenID with Spring Boot
OAuth2 and OpenID with Spring BootOAuth2 and OpenID with Spring Boot
OAuth2 and OpenID with Spring BootGeert Pante
 
Kafka Introduction.pptx
Kafka Introduction.pptxKafka Introduction.pptx
Kafka Introduction.pptxGeert Pante
 
Kubernetes and Amazon ECS
Kubernetes and Amazon ECSKubernetes and Amazon ECS
Kubernetes and Amazon ECSGeert Pante
 
Docker in practice
Docker in practiceDocker in practice
Docker in practiceGeert Pante
 
Spring 4 en spring data
Spring 4 en spring dataSpring 4 en spring data
Spring 4 en spring dataGeert Pante
 
Spring and SOA (2006)
Spring and SOA (2006)Spring and SOA (2006)
Spring and SOA (2006)Geert Pante
 
Maven plugins, properties en profiles: Advanced concepts in Maven
Maven plugins, properties en profiles: Advanced concepts in MavenMaven plugins, properties en profiles: Advanced concepts in Maven
Maven plugins, properties en profiles: Advanced concepts in MavenGeert Pante
 
The glory of REST in Java: Spring HATEOAS, RAML, Temenos IRIS
The glory of REST in Java: Spring HATEOAS, RAML, Temenos IRISThe glory of REST in Java: Spring HATEOAS, RAML, Temenos IRIS
The glory of REST in Java: Spring HATEOAS, RAML, Temenos IRISGeert Pante
 
Version Management in Maven
Version Management in MavenVersion Management in Maven
Version Management in MavenGeert Pante
 

Mais de Geert Pante (10)

OAuth2 and OpenID with Spring Boot
OAuth2 and OpenID with Spring BootOAuth2 and OpenID with Spring Boot
OAuth2 and OpenID with Spring Boot
 
Kafka Introduction.pptx
Kafka Introduction.pptxKafka Introduction.pptx
Kafka Introduction.pptx
 
Kubernetes and Amazon ECS
Kubernetes and Amazon ECSKubernetes and Amazon ECS
Kubernetes and Amazon ECS
 
Docker in practice
Docker in practiceDocker in practice
Docker in practice
 
Java EE 6
Java EE 6Java EE 6
Java EE 6
 
Spring 4 en spring data
Spring 4 en spring dataSpring 4 en spring data
Spring 4 en spring data
 
Spring and SOA (2006)
Spring and SOA (2006)Spring and SOA (2006)
Spring and SOA (2006)
 
Maven plugins, properties en profiles: Advanced concepts in Maven
Maven plugins, properties en profiles: Advanced concepts in MavenMaven plugins, properties en profiles: Advanced concepts in Maven
Maven plugins, properties en profiles: Advanced concepts in Maven
 
The glory of REST in Java: Spring HATEOAS, RAML, Temenos IRIS
The glory of REST in Java: Spring HATEOAS, RAML, Temenos IRISThe glory of REST in Java: Spring HATEOAS, RAML, Temenos IRIS
The glory of REST in Java: Spring HATEOAS, RAML, Temenos IRIS
 
Version Management in Maven
Version Management in MavenVersion Management in Maven
Version Management in Maven
 

Último

Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxRustici Software
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKJago de Vreede
 
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
 
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
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAnitaRaj43
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodJuan lago vázquez
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
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
 
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
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWERMadyBayot
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024The Digital Insurer
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesrafiqahmad00786416
 
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
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard37
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MIND CTI
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingEdi Saputra
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyKhushali Kathiriya
 

Último (20)

Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUKSpring Boot vs Quarkus the ultimate battle - DevoxxUK
Spring Boot vs Quarkus the ultimate battle - DevoxxUK
 
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
 
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...
 
AI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by AnitarajAI in Action: Real World Use Cases by Anitaraj
AI in Action: Real World Use Cases by Anitaraj
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
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
 
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
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
ICT role in 21st century education and its challenges
ICT role in 21st century education and its challengesICT role in 21st century education and its challenges
ICT role in 21st century education and its challenges
 
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
 
JohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptxJohnPollard-hybrid-app-RailsConf2024.pptx
JohnPollard-hybrid-app-RailsConf2024.pptx
 
MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024MINDCTI Revenue Release Quarter One 2024
MINDCTI Revenue Release Quarter One 2024
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 

Spring JMS and ActiveMQ

  • 3. Queue’s Messages are delivered once and only once ◦ Kept in the queue when listener is not available ◦ Sent to only one consumer when multiple are available ◦ Client acknowledge: wait for consumer to acknowledge before removing the message ◦ Prefetch: multiple messages can be reserved for a consumer ◦ Client timeout: if no ack or reject is received, queue will consider the consumer dead ◦ Order not guaranteed with multiple queue’s ◦ Redelivery Policy ◦ Set on client side ◦ Retry after reject or use Dead Letter Queue
  • 4. Selectors and Message Groups Selectors: Server side filtering ◦ Consumer can register a filter when connecting ◦ Filtering will be done on the server ◦ ActiveMQ supports selectors for JMS Headers and XPaths for XML Messages. ◦ No JSON Message Groups: guaranteed ordering ◦ If messages are correlated and relative order is important ◦ Add JMSXGroupID Header ◦ All messages with the same groupId will be processed by the same consumer ◦ Group mappings are kept in-memory on the server. ◦ Need to close groups properly ◦ Could fail after a failover
  • 6. Topics Write one message, will be received by all subscribers. ◦ Looser coupling between producer and consumer When no subscribers are available, the message is not saved. Perfect for frontend – backend communication ◦ Backend post a teaserChange on a topic ◦ All frontends showing the teaserList are subscribed on that topic Not suited for server – to – server communication ◦ Clustered service will receive each messages on every node
  • 7. CompositeTopic a.k.a. VirtualTopic Configure queue’s on the server which listen to a topic ◦ Queue’s will buffer messages when subscribers are temporary offline ◦ Messages will be received exactly once per Queue ◦ Queue per interested service ◦ Decouple producer from consumer ◦ Unless queue’s are full :-) <virtualDestinations> <compositeTopic name="redsys.publishing.publishfeed"> <forwardTo> <queue physicalName="redsys.moonriser.consumer.publishing.publishfeed"/> <queue physicalName="redsys.sitemanagement.consumer.publishing.publishfeed"/> <queue physicalName="redsys.publishingeventprocessor.consumer.publishing.publisheventfeed"/> </forwardTo> </compositeTopic>
  • 8. ActiveMQ Storage configuration ActiveMQ will try to keep as much messages in memory as possible Flushes to disk if one queue goes over 69% mem, or total mem usage goes over 80% If disk storage gets over 80%, producers are first slowed down, then blocked Selectors don’t work on flushed messages ◦ Need to wait until other messages are consumed
  • 11. Synchronous Messaging // Use the default destination jmsTemplate.convertAndSend("Hello World!"); // Use a different destination jmsTemplate.convertAndSend(“TEST.BAR”, “Hello World!”); // Use a default destination String textMessage1 = (String) jmsTemplate.receiveAndConvert(); // Use a different destination String textMessage2 = (String) jmsTemplate.receiveAndConvert(“TEST.BAR”); <bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory" p:brokerURL="tcp://localhost:61616" /> <bean id="jmsTemplate" class="org.springframework.jms.core.JmsTemplate" p:connectionFactory-ref="connectionFactory" p:defaultDestination-ref="destination" />
  • 12. MessageConvertors Maps java objects to message payloads ◦ ObjectMessage: java serialization ◦ TextMessage: Jackson (JSON) or Jaxb (XML) ◦ Jackson inserts a JMS Header with the fully qualified classname by default ◦ Can reuse Spring MVC ObjectMapper
  • 13. Asynchronous Messaging class MyMessageListener{ public Result onMessage(Action a){ // input parameters will be unmarshalled if necessary (jackson/jaxb) // can also receive message headers as input parameters // non-void results will be sent to a response queue // auto-acknowledges if no exceptions thrown } } <bean id="connectionFactory" class="org.apache.activemq.ActiveMQConnectionFactory" p:brokerURL="tcp://localhost:61616" /> <bean id="messageListener“ class="org.bsnyder.spring.jms.listener.MyMessageListener" /> <jms:listener-container concurrency="5-10“container-type=“simple|default”> <jms:listener destination="FOO.TEST" ref="messageListener“ method=“onMessage”/> </jms:listener-container>
  • 14. MessageListenerContainer options • DefaultMessageListenerContainer – Spring launches threads ◦ while(…){ consumer.receive(); } – Allows for dynamic scaling of queue consumers – Participates in external transactions • SimpleMessageListenerContainer – consumer.setMessageListener(myListener); ◦ JMS Provider manages ThreadPool – No external transaction support – Works better with MockRunner JMS
  • 15. JMS Resource Pooling Managed ConnectionFactory ◦ JCA Resource Adapter in JBoss ◦ ConnectionFactory bound in JNDI, no pooling in application Unmanaged broker ◦ Define pure ActiveMQConnectionFactory in Spring ◦ Wrap in org.apache.activemq.pool.PooledConnectionFactory ◦ Also possible: Spring CachingConnectionFactory ◦ Caches Sessions, too
  • 16. ActiveMQ Client Configuration ActiveMQ namespace for spring configuration Same configuration format as server <connectionFactory xmlns="http://activemq.apache.org/schema/core" brokerURL="${activeMQ.brokerURL}" userName="${activeMQ.username}" password="${activeMQ.password}"> <redeliveryPolicyMap> <redeliveryPolicyMap> <defaultEntry> <redeliveryPolicy maximumRedeliveries="2"/> </defaultEntry> </redeliveryPolicyMap> </redeliveryPolicyMap> </connectionFactory>
  • 17. Transactions JmsTransactionManager ◦ Injected in JmsTemplate and (Default)MessageListenerContainers ◦ Transactional behaviour across JMS Senders/Receivers ◦ All calls use the same JMS Session ◦ Acknowledgements are only processed when whole session is committed JtaTransactionManager ◦ JMS Sessions are synchronized with XA Database transactions ◦ Here be dragons…
  • 18. Testing Unit tests ◦ Call message listeners directly ◦ Mockito.mock(JmsTemplate.class) Component Integration Tests ◦ Use mockrunner-jms System Tests ◦ Use embedded ActiveMQ broker <amq:broker persistent="false" useJmx="false" id="embeddedBroker"> <amq:transportConnectors> <amq:transportConnector uri="tcp://localhost:#{freePortSelector}"/> </amq:transportConnectors> </amq:broker> <amq:connectionFactory id="jmsFactory" brokerURL="vm://localhost"/> @Bean public JMSMockObjectFactory jmsMockObjectFactory() { return new JMSMockObjectFactory();} @Bean public ConnectionFactory connectionFactory() { return jmsMockObjectFactory().getMockConnectionFactory();} @Bean public JMSTestModule jmsTestModule() { return new JMSTestModule(jmsMockObjectFactory());}
  • 19. Q&A