SlideShare a Scribd company logo
1 of 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

More Related Content

What's hot

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ý
 

What's hot (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
 

Viewers also liked

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
 

Viewers also liked (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
 

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

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

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

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

Recently uploaded

Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Alan Dix
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitecturePixlogix Infotech
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024BookNet Canada
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?XfilesPro
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsMemoori
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Paola De la Torre
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationRadu Cotescu
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...HostedbyConfluent
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphNeo4j
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxMalak Abu Hammad
 

Recently uploaded (20)

Pigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping ElbowsPigging Solutions Piggable Sweeping Elbows
Pigging Solutions Piggable Sweeping Elbows
 
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...Swan(sea) Song – personal research during my six years at Swansea ... and bey...
Swan(sea) Song – personal research during my six years at Swansea ... and bey...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
Pigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food ManufacturingPigging Solutions in Pet Food Manufacturing
Pigging Solutions in Pet Food Manufacturing
 
Understanding the Laravel MVC Architecture
Understanding the Laravel MVC ArchitectureUnderstanding the Laravel MVC Architecture
Understanding the Laravel MVC Architecture
 
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
#StandardsGoals for 2024: What’s new for BISAC - Tech Forum 2024
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?How to Remove Document Management Hurdles with X-Docs?
How to Remove Document Management Hurdles with X-Docs?
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
AI as an Interface for Commercial Buildings
AI as an Interface for Commercial BuildingsAI as an Interface for Commercial Buildings
AI as an Interface for Commercial Buildings
 
Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101Salesforce Community Group Quito, Salesforce 101
Salesforce Community Group Quito, Salesforce 101
 
Scaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organizationScaling API-first – The story of a global engineering organization
Scaling API-first – The story of a global engineering organization
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
Transforming Data Streams with Kafka Connect: An Introduction to Single Messa...
 
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge GraphSIEMENS: RAPUNZEL – A Tale About Knowledge Graph
SIEMENS: RAPUNZEL – A Tale About Knowledge Graph
 
The Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptxThe Codex of Business Writing Software for Real-World Solutions 2.pptx
The Codex of Business Writing Software for Real-World Solutions 2.pptx
 

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