愤怒的豆芽 · 戚庆林 QI Qinglin-机械工程及自动化学院· 8 月前 · |
善良的花卷 · 【SQL】根据一个字段分组求另一个字段的最大 ...· 1 年前 · |
年轻有为的香烟 · java 解析csv文件-掘金· 1 年前 · |
jms |
https://docs.spring.io/spring-framework/docs/current/javadoc-api/org/springframework/jms/core/JmsTemplate.html |
任性的野马
1 年前 |
If you want to use dynamic destination creation, you must specify the type of JMS destination to create, using the "pubSubDomain" property. For other operations, this is not necessary. Point-to-Point (Queues) is the default domain.
Default settings for JMS Sessions are "not transacted" and "auto-acknowledge". As defined by the Jakarta EE specification, the transaction and acknowledgement parameters are ignored when a JMS Session is created inside an active transaction, no matter if a JTA transaction or a Spring-managed transaction. To configure them for native JMS usage, specify appropriate values for the "sessionTransacted" and "sessionAcknowledgeMode" bean properties.
This template uses a
DynamicDestinationResolver
and a
SimpleMessageConverter
as default strategies for resolving a destination name or converting a message,
respectively. These defaults can be overridden through the "destinationResolver"
and "messageConverter" bean properties.
NOTE: The
ConnectionFactory
used with this template should
return pooled Connections (or a single shared Connection) as well as pooled
Sessions and MessageProducers. Otherwise, performance of ad-hoc JMS operations
is going to suffer.
The simplest option is to use the Spring-provided
SingleConnectionFactory
as a
decorator for your target
ConnectionFactory
, reusing a single
JMS Connection in a thread-safe fashion; this is often good enough for the
purpose of sending messages via this template. In a Jakarta EE environment,
make sure that the
ConnectionFactory
is obtained from the
application's environment naming context via JNDI; application servers
typically expose pooled, transaction-aware factories there.
JmsAccessor.setConnectionFactory(jakarta.jms.ConnectionFactory)
JmsDestinationAccessor.setPubSubDomain(boolean)
JmsDestinationAccessor.setDestinationResolver(org.springframework.jms.support.destination.DestinationResolver)
setMessageConverter(org.springframework.jms.support.converter.MessageConverter)
MessageProducer
MessageConsumer
RECEIVE_TIMEOUT_INDEFINITE_WAIT
,
RECEIVE_TIMEOUT_NO_WAIT
logger
JmsTemplate
(
ConnectionFactory
connectionFactory)
convertAndSend
(
Destination
destination,
Object
message,
MessagePostProcessor
postProcessor)
convertAndSend
(
Object
message)
convertAndSend
(
Object
message,
MessagePostProcessor
postProcessor)
convertAndSend
(
String
destinationName,
Object
message)
convertAndSend
(
String
destinationName,
Object
message,
MessagePostProcessor
postProcessor)
protected
QueueBrowser
createBrowser
(
Session
session,
Queue
queue,
String
messageSelector)
protected
MessageConsumer
createConsumer
(
Session
session,
Destination
destination,
String
messageSelector)
protected
MessageProducer
createProducer
(
Session
session,
Destination
destination)
protected
Object
doConvertFromMessage
(
Message
message)
protected
MessageProducer
doCreateProducer
(
Session
session,
Destination
destination)
protected
Message
doReceive
(
Session
session,
Destination
destination,
String
messageSelector)
protected
Message
doReceive
(
Session
session,
MessageConsumer
consumer)
protected void
doSend
(
MessageProducer
producer,
Message
message)
protected void
doSend
(
Session
session,
Destination
destination,
MessageCreator
messageCreator)
protected
Message
doSendAndReceive
(
Session
session,
Destination
destination,
MessageCreator
messageCreator)
Destination
and block until
a reply has been received on a temporary queue created on-the-fly.
execute
(
Destination
destination,
ProducerCallback
<T> action)
execute
(
String
destinationName,
ProducerCallback
<T> action)
execute
(
ProducerCallback
<T> action)
execute
(
SessionCallback
<T> action)
execute
(
SessionCallback
<T> action,
boolean startConnection)
protected
Connection
getConnection
(
JmsResourceHolder
holder)
getPriority
()
protected
Session
getSession
(
JmsResourceHolder
holder)
protected void
boolean
boolean
boolean
boolean
protected boolean
isSessionLocallyTransacted
(
Session
session)
receive
()
receive
(
Destination
destination)
receiveAndConvert
(
Destination
destination)
receiveAndConvert
(
String
destinationName)
receiveSelected
(
Destination
destination,
String
messageSelector)
receiveSelected
(
String
messageSelector)
receiveSelected
(
String
destinationName,
String
messageSelector)
receiveSelectedAndConvert
(
Destination
destination,
String
messageSelector)
receiveSelectedAndConvert
(
String
messageSelector)
receiveSelectedAndConvert
(
String
destinationName,
String
messageSelector)
send
(
Destination
destination,
MessageCreator
messageCreator)
send
(
String
destinationName,
MessageCreator
messageCreator)
send
(
MessageCreator
messageCreator)
sendAndReceive
(
Destination
destination,
MessageCreator
messageCreator)
sendAndReceive
(
String
destinationName,
MessageCreator
messageCreator)
sendAndReceive
(
MessageCreator
messageCreator)
setDefaultDestination
(
Destination
destination)
setDefaultDestinationName
(
String
destinationName)
setDeliveryDelay
(long deliveryDelay)
setDeliveryMode
(int deliveryMode)
setDeliveryPersistent
(boolean deliveryPersistent)
setExplicitQosEnabled
(boolean explicitQosEnabled)
setMessageConverter
(
MessageConverter
messageConverter)
setMessageIdEnabled
(boolean messageIdEnabled)
setMessageTimestampEnabled
(boolean messageTimestampEnabled)
setPriority
(int priority)
setPubSubNoLocal
(boolean pubSubNoLocal)
setQosSettings
(
QosSettings
settings)
QosSettings
to use when sending a message.
setReceiveTimeout
(long receiveTimeout)
setTimeToLive
(long timeToLive)
getDestinationResolver
,
isPubSubDomain
,
receiveFromConsumer
,
resolveDestinationName
,
setDestinationResolver
,
setPubSubDomain
afterPropertiesSet
,
convertJmsAccessException
,
createConnection
,
createSession
,
getConnectionFactory
,
getSessionAcknowledgeMode
,
isClientAcknowledge
,
isSessionTransacted
,
obtainConnectionFactory
,
setConnectionFactory
,
setSessionAcknowledgeMode
,
setSessionAcknowledgeModeName
,
setSessionTransacted
clone
,
equals
,
finalize
,
getClass
,
hashCode
,
notify
,
notifyAll
,
toString
,
wait
,
wait
,
wait
Note: The ConnectionFactory has to be set before using the instance. This constructor can be used to prepare a JmsTemplate via a BeanFactory, typically setting the ConnectionFactory via setConnectionFactory.
JmsAccessor.setConnectionFactory(jakarta.jms.ConnectionFactory)
connectionFactory
- the ConnectionFactory to obtain Connections from
JmsDestinationAccessor.setDestinationResolver(org.springframework.jms.support.destination.DestinationResolver)
setMessageConverter(org.springframework.jms.support.converter.MessageConverter)
DynamicDestinationResolver
SimpleMessageConverter
Alternatively, specify a "defaultDestinationName", to be dynamically resolved via the DestinationResolver.
send(MessageCreator)
convertAndSend(Object)
convertAndSend(Object, MessagePostProcessor)
setDefaultDestinationName(String)
Alternatively, specify a JMS Destination object as "defaultDestination".
send(MessageCreator)
convertAndSend(Object)
convertAndSend(Object, MessagePostProcessor)
JmsDestinationAccessor.setDestinationResolver(org.springframework.jms.support.destination.DestinationResolver)
setDefaultDestination(jakarta.jms.Destination)
The default converter is a SimpleMessageConverter, which is able to handle BytesMessages, TextMessages and ObjectMessages.
convertAndSend(java.lang.Object)
receiveAndConvert()
SimpleMessageConverter
This is only a hint to the JMS producer. See the JMS javadocs for details.
MessageProducer.setDisableMessageID(boolean)
This is only a hint to the JMS producer. See the JMS javadocs for details.
MessageProducer.setDisableMessageTimestamp(boolean)
Session.createConsumer(jakarta.jms.Destination, String, boolean)
The default is
JmsDestinationAccessor.RECEIVE_TIMEOUT_INDEFINITE_WAIT
, which indicates
a blocking receive without timeout.
Specify
JmsDestinationAccessor.RECEIVE_TIMEOUT_NO_WAIT
(or any other negative value)
to indicate that a receive operation should check if a message is
immediately available without blocking.
JmsDestinationAccessor.receiveFromConsumer(MessageConsumer, long)
MessageConsumer.receive(long)
MessageConsumer.receiveNoWait()
MessageConsumer.receive()
The default is -1 (no delivery delay passed on to the broker). Note that this feature requires JMS 2.0.
setDeliveryMode(int)
setPriority(int)
setTimeToLive(long)
setDeliveryMode(int)
setPriority(int)
setTimeToLive(long)
QosSettings
to use when sending a message.
settings
- the deliveryMode, priority, and timeToLive settings to use
setExplicitQosEnabled(boolean)
setDeliveryMode(int)
setPriority(int)
setTimeToLive(long)
Default is "true" a.k.a. delivery mode "PERSISTENT".
setDeliveryMode(int)
DeliveryMode.PERSISTENT
DeliveryMode.NON_PERSISTENT
Since a default value may be defined administratively, this is only used when "isExplicitQosEnabled" equals "true".
deliveryMode
- the delivery mode to use
isExplicitQosEnabled()
DeliveryMode.PERSISTENT
DeliveryMode.NON_PERSISTENT
Message.DEFAULT_DELIVERY_MODE
MessageProducer.send(jakarta.jms.Message, int, int, long)
Since a default value may be defined administratively, this is only used when "isExplicitQosEnabled" equals "true".
isExplicitQosEnabled()
Message.DEFAULT_PRIORITY
MessageProducer.send(jakarta.jms.Message, int, int, long)
Since a default value may be defined administratively, this is only used when "isExplicitQosEnabled" equals "true".
timeToLive
- the message's lifetime (in milliseconds)
isExplicitQosEnabled()
Message.DEFAULT_TIME_TO_LIVE
MessageProducer.send(jakarta.jms.Message, int, int, long)
JmsOperations
execute
in interface
JmsOperations
action
- callback object that exposes the session
JmsException
- if there is any problem
execute(SessionCallback)
,
allowing the JMS Connection to be started on the fly.
Use
execute(SessionCallback)
for the general case.
Starting the JMS Connection is just necessary for receiving messages,
which is preferably achieved through the
receive
methods.
action
- callback object that exposes the Session
startConnection
- whether to start the Connection
JmsException
- if there is any problem
execute(SessionCallback)
receive()
JmsOperations
execute
in interface
JmsOperations
action
- callback object that exposes the session/producer pair
JmsException
- checked JMSException converted to unchecked
JmsOperations
execute
in interface
JmsOperations
destination
- the destination to send messages to
action
- callback object that exposes the session/producer pair
JmsException
- checked JMSException converted to unchecked
JmsOperations
execute
in interface
JmsOperations
destinationName
- the name of the destination to send messages to
(to be resolved to an actual destination by a DestinationResolver)
action
- callback object that exposes the session/producer pair
JmsException
- checked JMSException converted to unchecked
JmsOperations
This will only work with a default destination specified!
send
in interface
JmsOperations
messageCreator
- callback to create a message
JmsException
- checked JMSException converted to unchecked
JmsOperations
send
in interface
JmsOperations
destination
- the destination to send this message to
messageCreator
- callback to create a message
JmsException
- checked JMSException converted to unchecked
JmsOperations
send
in interface
JmsOperations
destinationName
- the name of the destination to send this message to
(to be resolved to an actual destination by a DestinationResolver)
messageCreator
- callback to create a message
JmsException
- checked JMSException converted to unchecked
session
- the JMS Session to operate on
destination
- the JMS Destination to send to
messageCreator
- callback to create a JMS Message
JMSException
- if thrown by JMS API methods
producer
- the JMS MessageProducer to send with
message
- the JMS Message to send
JMSException
- if thrown by JMS API methods
JmsOperations
This will only work with a default destination specified!
convertAndSend
in interface
JmsOperations
message
- the object to convert to a message
JmsException
- converted checked JMSException to unchecked
JmsOperations
convertAndSend
in interface
JmsOperations
destination
- the destination to send this message to
message
- the object to convert to a message
JmsException
- converted checked JMSException to unchecked
JmsOperations
convertAndSend
in interface
JmsOperations
destinationName
- the name of the destination to send this message to
(to be resolved to an actual destination by a DestinationResolver)
message
- the object to convert to a message
JmsException
- checked JMSException converted to unchecked
JmsOperations
This will only work with a default destination specified!
convertAndSend
in interface
JmsOperations
message
- the object to convert to a message
postProcessor
- the callback to modify the message
JmsException
- checked JMSException converted to unchecked
JmsOperations
convertAndSend
in interface
JmsOperations
destination
- the destination to send this message to
message
- the object to convert to a message
postProcessor
- the callback to modify the message
JmsException
- checked JMSException converted to unchecked
JmsOperations
convertAndSend
in interface
JmsOperations
destinationName
- the name of the destination to send this message to
(to be resolved to an actual destination by a DestinationResolver)
message
- the object to convert to a message.
postProcessor
- the callback to modify the message
JmsException
- checked JMSException converted to unchecked
JmsOperations
This method should be used carefully, since it will block the thread until the message becomes available or until the timeout value is exceeded.
This will only work with a default destination specified!
receive
in interface
JmsOperations
null
if the timeout expires
JmsException
- checked JMSException converted to unchecked
JmsOperations
This method should be used carefully, since it will block the thread until the message becomes available or until the timeout value is exceeded.
receive
in interface
JmsOperations
destination
- the destination to receive a message from
null
if the timeout expires
JmsException
- checked JMSException converted to unchecked
JmsOperations
This method should be used carefully, since it will block the thread until the message becomes available or until the timeout value is exceeded.
receive
in interface
JmsOperations
destinationName
- the name of the destination to send this message to
(to be resolved to an actual destination by a DestinationResolver)
null
if the timeout expires
JmsException
- checked JMSException converted to unchecked
JmsOperations
This method should be used carefully, since it will block the thread until the message becomes available or until the timeout value is exceeded.
This will only work with a default destination specified!
receiveSelected
in interface
JmsOperations
messageSelector
- the JMS message selector expression (or
null
if none).
See the JMS specification for a detailed definition of selector expressions.
null
if the timeout expires
JmsException
- checked JMSException converted to unchecked
JmsOperations
This method should be used carefully, since it will block the thread until the message becomes available or until the timeout value is exceeded.
receiveSelected
in interface
JmsOperations
destination
- the destination to receive a message from
messageSelector
- the JMS message selector expression (or
null
if none).
See the JMS specification for a detailed definition of selector expressions.
null
if the timeout expires
JmsException
- checked JMSException converted to unchecked
JmsOperations
This method should be used carefully, since it will block the thread until the message becomes available or until the timeout value is exceeded.
receiveSelected
in interface
JmsOperations
destinationName
- the name of the destination to send this message to
(to be resolved to an actual destination by a DestinationResolver)
messageSelector
- the JMS message selector expression (or
null
if none).
See the JMS specification for a detailed definition of selector expressions.
null
if the timeout expires
JmsException
- checked JMSException converted to unchecked
session
- the JMS Session to operate on
destination
- the JMS Destination to receive from
messageSelector
- the message selector for this consumer (can be
null
)
null
if none
JMSException
- if thrown by JMS API methods
session
- the JMS Session to operate on
consumer
- the JMS MessageConsumer to receive with
null
if none
JMSException
- if thrown by JMS API methods
JmsOperations
This method should be used carefully, since it will block the thread until the message becomes available or until the timeout value is exceeded.
This will only work with a default destination specified!
receiveAndConvert
in interface
JmsOperations
null
if the timeout expires.
JmsException
- checked JMSException converted to unchecked
JmsOperations
This method should be used carefully, since it will block the thread until the message becomes available or until the timeout value is exceeded.
receiveAndConvert
in interface
JmsOperations
destination
- the destination to receive a message from
null
if the timeout expires.
JmsException
- checked JMSException converted to unchecked
JmsOperations
This method should be used carefully, since it will block the thread until the message becomes available or until the timeout value is exceeded.
receiveAndConvert
in interface
JmsOperations
destinationName
- the name of the destination to send this message to
(to be resolved to an actual destination by a DestinationResolver)
null
if the timeout expires.
JmsException
- checked JMSException converted to unchecked
JmsOperations
This method should be used carefully, since it will block the thread until the message becomes available or until the timeout value is exceeded.
This will only work with a default destination specified!
receiveSelectedAndConvert
in interface
JmsOperations
messageSelector
- the JMS message selector expression (or
null
if none).
See the JMS specification for a detailed definition of selector expressions.
null
if the timeout expires.
JmsException
- checked JMSException converted to unchecked
JmsOperations
This method should be used carefully, since it will block the thread until the message becomes available or until the timeout value is exceeded.
receiveSelectedAndConvert
in interface
JmsOperations
destination
- the destination to receive a message from
messageSelector
- the JMS message selector expression (or
null
if none).
See the JMS specification for a detailed definition of selector expressions.
null
if the timeout expires.
JmsException
- checked JMSException converted to unchecked
JmsOperations
This method should be used carefully, since it will block the thread until the message becomes available or until the timeout value is exceeded.
receiveSelectedAndConvert
in interface
JmsOperations
destinationName
- the name of the destination to send this message to
(to be resolved to an actual destination by a DestinationResolver)
messageSelector
- the JMS message selector expression (or
null
if none).
See the JMS specification for a detailed definition of selector expressions.
null
if the timeout expires.
JmsException
- checked JMSException converted to unchecked
message
- the JMS Message to convert (can be
null
)
null
if none
JmsOperations
MessageCreator
callback creates the message given a Session. A temporary
queue is created as part of this operation and is set in the
JMSReplyTO
header of the message.
This will only work with a default destination specified!
sendAndReceive
in interface
JmsOperations
messageCreator
- callback to create a request message
null
if the message could not be received,
for example due to a timeout
JmsException
- checked JMSException converted to unchecked
JmsOperations
MessageCreator
callback creates the message given a Session. A temporary
queue is created as part of this operation and is set in the
JMSReplyTO
header of the message.
sendAndReceive
in interface
JmsOperations
destination
- the destination to send this message to
messageCreator
- callback to create a message
null
if the message could not be received,
for example due to a timeout
JmsException
- checked JMSException converted to unchecked
JmsOperations
MessageCreator
callback creates the message given a Session. A temporary
queue is created as part of this operation and is set in the
JMSReplyTO
header of the message.
sendAndReceive
in interface
JmsOperations
destinationName
- the name of the destination to send this message to
(to be resolved to an actual destination by a DestinationResolver)
messageCreator
- callback to create a message
null
if the message could not be received,
for example due to a timeout
JmsException
- checked JMSException converted to unchecked
Destination
and block until
a reply has been received on a temporary queue created on-the-fly.
Return the response message or
null
if no message has
JMSException
- if thrown by JMS API methods
JmsOperations
browse
in interface
JmsOperations
action
- callback object that exposes the session/browser pair
JmsException
- checked JMSException converted to unchecked
JmsOperations
browse
in interface
JmsOperations
queue
- the queue to browse
action
- callback object that exposes the session/browser pair
JmsException
- checked JMSException converted to unchecked
JmsOperations
browse
in interface
JmsOperations
queueName
- the name of the queue to browse
(to be resolved to an actual destination by a DestinationResolver)
action
- callback object that exposes the session/browser pair
JmsException
- checked JMSException converted to unchecked
JmsOperations
browseSelected
in interface
JmsOperations
messageSelector
- the JMS message selector expression (or
null
if none).
See the JMS specification for a detailed definition of selector expressions.
action
- callback object that exposes the session/browser pair
JmsException
- checked JMSException converted to unchecked
JmsOperations
browseSelected
in interface
JmsOperations
queue
- the queue to browse
messageSelector
- the JMS message selector expression (or
null
if none).
See the JMS specification for a detailed definition of selector expressions.
action
- callback object that exposes the session/browser pair
JmsException
- checked JMSException converted to unchecked
JmsOperations
browseSelected
in interface
JmsOperations
queueName
- the name of the queue to browse
(to be resolved to an actual destination by a DestinationResolver)
messageSelector
- the JMS message selector expression (or
null
if none).
See the JMS specification for a detailed definition of selector expressions.
action
- callback object that exposes the session/browser pair
JmsException
- checked JMSException converted to unchecked
This implementation accepts any JMS 1.1 Connection.
holder
- the JmsResourceHolder
null
if none found
This implementation accepts any JMS 1.1 Session.
holder
- the JmsResourceHolder
null
if none found
Note: The Session's own transacted flag will already have been checked before. This method is about finding out whether the Session's transaction is local or externally coordinated.
session
- the Session to check
JmsAccessor.isSessionTransacted()
ConnectionFactoryUtils.isSessionTransactional(jakarta.jms.Session, jakarta.jms.ConnectionFactory)
Delegates to
doCreateProducer(jakarta.jms.Session, jakarta.jms.Destination)
for creation of the raw
JMS MessageProducer.
session
- the JMS Session to create a MessageProducer for
destination
- the JMS Destination to create a MessageProducer for
JMSException
- if thrown by JMS API methods
setMessageIdEnabled(boolean)
setMessageTimestampEnabled(boolean)
This implementation uses JMS 1.1 API.
session
- the JMS Session to create a MessageProducer for
destination
- the JMS Destination to create a MessageProducer for
JMSException
- if thrown by JMS API methods
This implementation uses JMS 1.1 API.
session
- the JMS Session to create a MessageConsumer for
destination
- the JMS Destination to create a MessageConsumer for
messageSelector
- the message selector for this consumer (can be
null
)
JMSException
- if thrown by JMS API methods
Delegates to
doCreateProducer(jakarta.jms.Session, jakarta.jms.Destination)
for creation of the raw
JMS MessageProducer.
session
- the JMS Session to create a QueueBrowser for
queue
- the JMS Queue to create a QueueBrowser for
messageSelector
- the message selector for this consumer (can be
null
)
JMSException
- if thrown by JMS API methods
setMessageIdEnabled(boolean)
setMessageTimestampEnabled(boolean)