@@ -59,8 +59,8 @@ If you created the `JmsTemplate` and specified a default destination, the
59
59
`send(MessageCreator c)` sends a message to that destination.
60
60
61
61
62
- [[jms-msg -conversion]]
63
- == Using Message Converters
62
+ [[jms-sending -conversion]]
63
+ == Using JMS Message Converters
64
64
65
65
To facilitate the sending of domain model objects, the `JmsTemplate` has
66
66
various send methods that take a Java object as an argument for a message's data
@@ -87,7 +87,7 @@ following example shows how to modify a message header and a property after a
87
87
[source,java,indent=0,subs="verbatim,quotes"]
88
88
----
89
89
public void sendWithConversion() {
90
- Map map = new HashMap();
90
+ Map<String, String> map = new HashMap<> ();
91
91
map.put("Name", "Mark");
92
92
map.put("Age", new Integer(47));
93
93
jmsTemplate.convertAndSend("testQueue", map, new MessagePostProcessor() {
@@ -120,15 +120,43 @@ MapMessage={
120
120
}
121
121
----
122
122
123
+ NOTE: This JMS-specific `org.springframework.jms.support.converter.MessageConverter`
124
+ arrangement operates on JMS message types and is responsible for immediate conversion
125
+ to `jakarta.jms.TextMessage`, `jakarta.jms.BytesMessage`, etc. For a contract supporting
126
+ generic message payloads, use `org.springframework.messaging.converter.MessageConverter`
127
+ with `JmsMessagingTemplate` or preferably `JmsClient` as your central delegate instead.
123
128
124
- [[jms-callbacks]]
125
- == Using `SessionCallback` and `ProducerCallback`
129
+
130
+ [[jms-sending-jmsclient]]
131
+ == Sending a Message with `JmsClient`
132
+
133
+ [source,java,indent=0,subs="verbatim,quotes"]
134
+ ----
135
+ // Reusable handle, typically created through JmsClient.create(ConnectionFactory)
136
+ // For custom conversion, use JmsClient.create(ConnectionFactory, MessageConverter)
137
+ private JmsClient jmsClient;
138
+
139
+ public void sendWithConversion() {
140
+ this.jmsClient.destination("myQueue")
141
+ .withTimeToLive(1000)
142
+ .send("myPayload"); // optionally with a headers Map next to the payload
143
+ }
144
+
145
+ public void sendCustomMessage() {
146
+ Message<?> message =
147
+ MessageBuilder.withPayload("myPayload").build(); // optionally with headers
148
+ this.jmsClient.destination("myQueue")
149
+ .withTimeToLive(1000)
150
+ .send(message);
151
+ }
152
+ ----
153
+
154
+
155
+ [[jms-sending-callbacks]]
156
+ == Using `SessionCallback` and `ProducerCallback` on `JmsTemplate`
126
157
127
158
While the send operations cover many common usage scenarios, you might sometimes
128
159
want to perform multiple operations on a JMS `Session` or `MessageProducer`. The
129
160
`SessionCallback` and `ProducerCallback` expose the JMS `Session` and `Session` /
130
161
`MessageProducer` pair, respectively. The `execute()` methods on `JmsTemplate` run
131
162
these callback methods.
132
-
133
-
134
-
0 commit comments