Class JmsMessageSender
- All Implemented Interfaces:
org.springframework.beans.factory.InitializingBean, WebServiceMessageSender
WebServiceMessageSender implementation that uses JMS Messages. Requires
a JMS ConnectionFactory to operate.
This message sender supports URI's of the following format:
jms:<destination>[?param-name=param-value][¶m-name=param-value]
where the characters :, ?, and & stand for
themselves. The <destination> represents the name of the Queue or
Topic that will be resolved by the destination
resolver. Valid param-name include:
| param-name | Description |
|---|---|
deliveryMode |
Indicates whether the request message is persistent or not. This may be
PERSISTENT or NON_PERSISTENT. See
MessageProducer.setDeliveryMode(int) |
messageType |
The message type. This may be BINARY_MESSAGE (the default) or
TEXT_MESSAGE |
priority |
The JMS priority (0-9) associated with the request message. See
MessageProducer.setPriority(int) |
replyToName |
The name of the destination to which the response message must be sent, that will
be resolved by the destination resolver |
timeToLive |
The lifetime, in milliseconds, of the request message. See
MessageProducer.setTimeToLive(long) |
If the replyToName is not set, a temporary queue is used.
This class uses BytesMessage messages by default, but can be
configured to send TextMessage messages instead. Note that
BytesMessages are preferred, since TextMessages do not support
attachments and character encodings reliably.
Some examples of JMS URIs are:
jms:SomeQueue
jms:SomeTopic?priority=3&deliveryMode=NON_PERSISTENT
jms:RequestQueue?replyToName=ResponseQueueName
jms:Queue?messageType=TEXT_MESSAGE
Any jms: URI supplied by the application is accepted. A URI supplied by a
remote peer, such as a WS-Addressing ReplyTo or
FaultTo address, is only accepted when a DestinationPolicy accepts it; without a policy, every remote destination is rejected.
Use JmsDestinationPolicies.allowedDestinationNames(String...) for the common
case. Remember that both the destination name and the replyToName are handed to
the destination resolver, so a policy has to
constrain both. That matters most when the resolver performs a JNDI lookup, as it then
treats either name as a lookup key.
- Since:
- 1.5.0
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from interface WebServiceMessageSender
WebServiceMessageSender.DestinationDescriptor, WebServiceMessageSender.DestinationPolicy<D>, WebServiceMessageSender.UriSource -
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final longDefault timeout for receive operations: -1 indicates a blocking receive without timeout.static final StringDefault encoding used to read from and write toTextMessagemessages.Fields inherited from class org.springframework.jms.support.destination.JmsDestinationAccessor
RECEIVE_TIMEOUT_INDEFINITE_WAIT, RECEIVE_TIMEOUT_NO_WAITFields inherited from class org.springframework.jms.support.JmsAccessor
logger -
Constructor Summary
ConstructorsConstructorDescriptionCreate a newJmsMessageSenderJmsMessageSender(jakarta.jms.ConnectionFactory connectionFactory) Create a newJmsMessageSender, given a ConnectionFactory. -
Method Summary
Modifier and TypeMethodDescriptioncreateConnection(URI uri) Create a newWebServiceConnectionto the specified URI.voidsetDestinationPolicy(WebServiceMessageSender.DestinationPolicy<JmsDestinationDescriptor> destinationPolicy) Set theWebServiceMessageSender.DestinationPolicythat decides which destinations this sender may open a connection to.voidsetPostProcessor(org.springframework.jms.core.MessagePostProcessor postProcessor) Sets the optionalMessagePostProcessorto further modify outgoing messages after the XML contents has been set.voidsetReceiveTimeout(long receiveTimeout) Set the timeout to use for receive calls.voidsetTextMessageEncoding(String textMessageEncoding) Sets the encoding used to read fromTextMessagemessages.booleansupports(URI uri, WebServiceMessageSender.UriSource uriSource) Whether this sender supports the given URI for the suppliedWebServiceMessageSender.UriSource.booleanWhether this sender is configured to accept destinations supplied by a remote peer at all.Methods inherited from class org.springframework.jms.support.destination.JmsDestinationAccessor
getDestinationResolver, isPubSubDomain, receiveFromConsumer, resolveDestinationName, setDestinationResolver, setPubSubDomainMethods inherited from class org.springframework.jms.support.JmsAccessor
afterPropertiesSet, convertJmsAccessException, createConnection, createSession, getConnectionFactory, getSessionAcknowledgeMode, isClientAcknowledge, isSessionTransacted, obtainConnectionFactory, setConnectionFactory, setSessionAcknowledgeMode, setSessionAcknowledgeModeName, setSessionTransactedMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface WebServiceMessageSender
supports
-
Field Details
-
DEFAULT_RECEIVE_TIMEOUT
public static final long DEFAULT_RECEIVE_TIMEOUTDefault timeout for receive operations: -1 indicates a blocking receive without timeout.- See Also:
-
DEFAULT_TEXT_MESSAGE_ENCODING
Default encoding used to read from and write toTextMessagemessages.- See Also:
-
-
Constructor Details
-
JmsMessageSender
public JmsMessageSender()Create a newJmsMessageSenderNote: 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
JmsAccessor.setConnectionFactory(ConnectionFactory).- See Also:
-
JmsMessageSender
public JmsMessageSender(jakarta.jms.ConnectionFactory connectionFactory) Create a newJmsMessageSender, given a ConnectionFactory.- Parameters:
connectionFactory- the ConnectionFactory to obtain Connections from
-
-
Method Details
-
setReceiveTimeout
public void setReceiveTimeout(long receiveTimeout) Set the timeout to use for receive calls. The default is -1, which means no timeout.- See Also:
-
setTextMessageEncoding
Sets the encoding used to read fromTextMessagemessages. Defaults toUTF-8. -
setPostProcessor
public void setPostProcessor(org.springframework.jms.core.MessagePostProcessor postProcessor) Sets the optionalMessagePostProcessorto further modify outgoing messages after the XML contents has been set. -
setDestinationPolicy
public void setDestinationPolicy(WebServiceMessageSender.DestinationPolicy<JmsDestinationDescriptor> destinationPolicy) Set theWebServiceMessageSender.DestinationPolicythat decides which destinations this sender may open a connection to.A policy is required to send to a
WebServiceMessageSender.UriSource.REMOTEdestination, such as a WS-AddressingReplyToorFaultToaddress: when none is configured, every remote destination is rejected.- Parameters:
destinationPolicy- the policy to apply- Since:
- 3.1.9
-
createConnection
Description copied from interface:WebServiceMessageSenderCreate a newWebServiceConnectionto the specified URI.- Specified by:
createConnectionin interfaceWebServiceMessageSender- Parameters:
uri- the URI to open a connection to- Returns:
- the new connection
- Throws:
IOException- in case of I/O errors
-
supports
Description copied from interface:WebServiceMessageSenderWhether this sender supports the given URI for the suppliedWebServiceMessageSender.UriSource.A URI is supported when this sender handles its transport and the configured
WebServiceMessageSender.DestinationPolicyaccepts it. When no policy is configured,WebServiceMessageSender.UriSource.APPLICATIONdestinations are accepted andWebServiceMessageSender.UriSource.REMOTEdestinations are rejected: only the application knows which peer-supplied destinations are legitimate, so there is no safe default.- Specified by:
supportsin interfaceWebServiceMessageSender- Parameters:
uri- the URI to be checkeduriSource- whether the URI is application-controlled or remote-influenced- Returns:
trueif this sender accepts the URI for that source
-
supportsRemoteDestinations
public boolean supportsRemoteDestinations()Description copied from interface:WebServiceMessageSenderWhether this sender is configured to accept destinations supplied by a remote peer at all.Return
falsewhen the sender rejects everyWebServiceMessageSender.UriSource.REMOTEdestination out of hand, typically because noWebServiceMessageSender.DestinationPolicyis configured.- Specified by:
supportsRemoteDestinationsin interfaceWebServiceMessageSender- Returns:
falseif no remote destination can ever be accepted
-