Interface JmsClient
JmsClient with common send and receive operations against a JMS
destination, dealing with Spring's common Message or with payload values.
This is effectively an alternative to JmsMessagingTemplate, also
delegating to Spring's JmsTemplate for performing actual operations.
Note: Operations in this interface throw MessagingException instead of
the JMS-specific JmsException, aligning with the
spring-messaging module and its other client operation handles.
Message conversion is preferably done through the common MessageConverter
but can also be customized at the JmsTemplate.setMessageConverter(MessageConverter) level.
This client provides reusable operation handles which can be configured with
custom QoS settings. Note that any use of such explicit settings will override
administrative provider settings (see JmsTemplate.setExplicitQosEnabled(boolean)).
An example for sending a converted payload to a queue:
client.destination("myQueue")
.withTimeToLive(1000)
.send("myPayload"); // optionally with a headers Map next to the payload
An example for receiving a converted payload from a queue:
Optional<String> payload = client.destination("myQueue")
.withReceiveTimeout(1000)
.receive(String.class);
An example for sending a message with a payload to a queue:
Message<?> message =
MessageBuilder.withPayload("myPayload").build(); // optionally with headers
client.destination("myQueue")
.withTimeToLive(1000)
.send(message);
An example for receiving a message with a payload from a queue:
Optional<Message<?>> message = client.destination("myQueue")
.withReceiveTimeout(1000)
.receive();
- Since:
- 7.0
- Author:
- Juergen Hoeller, Brian Clozel
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interfaceA mutable builder for creating aJmsClient.static interfaceCommon JMS send and receive operations with various settings. -
Method Summary
Modifier and TypeMethodDescriptionstatic JmsClient.Builderbuilder(jakarta.jms.ConnectionFactory connectionFactory) Obtain aJmsClientbuilder that will use the given connection factory for JMS connections.static JmsClient.Builderbuilder(JmsOperations jmsTemplate) Obtain aJmsClientbuilder based on the configuration of the givenJmsTemplate.static JmsClientcreate(jakarta.jms.ConnectionFactory connectionFactory) Create a newJmsClientfor the givenConnectionFactory.static JmsClientcreate(JmsOperations jmsTemplate) Create a newJmsClientfor the givenJmsOperations.destination(jakarta.jms.Destination destination) Provide an operation handle for the given JMS destination.destination(String destinationName) Provide an operation handle for the specified JMS destination.
-
Method Details
-
destination
Provide an operation handle for the given JMS destination.- Parameters:
destination- the JMSDestinationobject- Returns:
- a reusable operation handle bound to the destination
- See Also:
-
destination
Provide an operation handle for the specified JMS destination.- Parameters:
destinationName- a name resolving to a JMSDestination- Returns:
- a reusable operation handle bound to the destination
- See Also:
-
create
Create a newJmsClientfor the givenConnectionFactory.- Parameters:
connectionFactory- the factory to obtain JMS connections from
-
create
Create a newJmsClientfor the givenJmsOperations.- Parameters:
jmsTemplate- theJmsTemplateto use for performing operations (can be a customJmsOperationsimplementation as well)
-
builder
Obtain aJmsClientbuilder that will use the given connection factory for JMS connections.- Parameters:
connectionFactory- the factory to obtain JMS connections from- Returns:
- a
JmsClientbuilder that uses the given connection factory.
-
builder
Obtain aJmsClientbuilder based on the configuration of the givenJmsTemplate.- Parameters:
jmsTemplate- theJmsTemplateto use for performing operations (can be a customJmsOperationsimplementation as well)- Returns:
- a
JmsClientbuilder that uses the given JMS template.
-