Spring Boot JMS Topicο
ActiveMQ Publish Subscribe Topicο
Spring Boot ActiveMQ Configurationο
Note: we can create a publish subscribe broker by setting the
spring.jms.pub-sub-domain
totrue
. This specifies that the default destination is a topic. Another thing to notice is we created concurrent listeners. We configured this concurrent listeners using thespring.jms.concurrency
andspring.jms.max-concurrency
properties. The first property configures the minimum number of concurrent consumers. The latter configures the maximum number of concurrent consumers.
Resultsο
JmsController
JmsReceiver
JMS Validate Messagesο
JMS Validate Messages using JSR-303 Bean Validationο
JSR-303 Bean Validation
Order -> @NotNull
JmsListenerConfig#validatorFactory -> HibernateValidator
Custom External Bean Validation
OrderValidator
JmsListenerConfig#methodFactory
JMS Error Handlingο
JmsConsumerConfig#queueListenerFactory -> setErrorHandler
OrderProcessingException
JMS Message Header Propertiesο
Setting JMS Message Header Propertiesο
In this MessagePostProcessor
we are able to access the core JMS Message
object which we can set the default JMS headers or add custom headers to the message.
JMSDestination
β the destination where the message is sent.JMSReplyTo
β the JMS destination where the reply message should be sent.JMSDeliveryMode
β the delivery mode of the message. can be one of the following:PERSISTENT
β signifies the messages are stored and forwardedNON_PERSISTENT
β messages are not stored and may be lost due to failures in transmission.
JMSMessageID
β the unique ID of the message.JMSTimestamp
β the time a message was handed off to a JMS provider to be sent. The time expressed at the amount of time, in milliseconds.JMSExpiration
β the expiration time of the message.JMSRedelivered
β typically this item is set when the JMS provider has delivered the message at least once before.JMSPriority
β the priority of the message. Priority is a value from 0-9. Higher numbers signify a higher priority (that is, 9 is a higher priority than 8).JMSCorrelationID
β this ID is used to link a response message with its related request message. This is usually the message ID of a request message when this field is found in a reply message.JMSType
β the JMS provider-supplied string to describe the type of the message. Some JMS providers use this property to define messages in the providerβs repository. See the JMS provider documentation for more information about the use of this field.
Accessing JMS Header Informationο
The @JmsListener
annotation marks a method to be the target of a JMS message listener on the specified destination
. We can access the JMS Message Headers using one of the following.
@Header
-annotated method arguments to extract specific header values, including standard JMS headers defined byJmsHeaders
.@Headers
-annotated method argument that must also be assignable toMap
for obtaining access to all headers.MessageHeaders
arguments for obtaining access to all headers.MessageHeaderAccessor
orJmsMessageHeaderAccessor
for convenient access to all method arguments.