Skip to content

Commit f4d7c4f

Browse files
artembilangaryrussell
authored andcommitted
INT-2086: JMS TemporaryTopic when replyPubSub
Fixes https://jira.spring.io/browse/INT-2086 Some JMS vendors handle differently a `TemporaryTopic` and `TemporaryQueue`, so, change a `JmsOutboundGateway` to create respective temporary destination according the `replyPubSubDomain` option set
1 parent a30dc10 commit f4d7c4f

File tree

4 files changed

+16
-4
lines changed

4 files changed

+16
-4
lines changed

spring-integration-jms/src/main/java/org/springframework/integration/jms/JmsOutboundGateway.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -502,7 +502,7 @@ private Destination determineReplyDestination(Message<?> message, Session sessio
502502
"Evaluation of replyDestinationExpression failed to produce a Destination or destination name. " +
503503
"Result was: " + result);
504504
}
505-
return session.createTemporaryQueue();
505+
return this.replyPubSubDomain ? session.createTemporaryTopic() : session.createTemporaryQueue();
506506
}
507507

508508
private Destination resolveReplyDestination(String repDestinationName, Session session) throws JMSException {
@@ -1327,7 +1327,8 @@ private static class GatewayReplyListenerContainer extends DefaultMessageListene
13271327
@Override
13281328
protected Destination resolveDestinationName(Session session, String destinationName) throws JMSException {
13291329
if (!StringUtils.hasText(destinationName)) {
1330-
this.replyDestination = session.createTemporaryQueue();
1330+
this.replyDestination =
1331+
isPubSubDomain() ? session.createTemporaryTopic() : session.createTemporaryQueue();
13311332
}
13321333
else {
13331334
this.replyDestination = super.resolveDestinationName(session, destinationName);

spring-integration-jms/src/test/java/org/springframework/integration/jms/dsl/JmsTests.java

+1
Original file line numberDiff line numberDiff line change
@@ -399,6 +399,7 @@ public IntegrationFlow jmsMessageDrivenFlowWithContainer() {
399399
public IntegrationFlow jmsOutboundGatewayFlow() {
400400
return f -> f.handle(Jms.outboundGateway(connectionFactory)
401401
.replyContainer(c -> c.idleReplyContainerTimeout(10))
402+
.replyPubSubDomain(true)
402403
.requestDestination("jmsPipelineTest"),
403404
e -> e.id("jmsOutboundGateway"));
404405
}

src/reference/asciidoc/jms.adoc

+6-2
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,9 @@ Prior to Spring Integration 2.2, if necessary, a `TemporaryQueue` was created (a
4444
Beginning with Spring Integration 2.2, you can configure the outbound gateway to use a `MessageListener` container to receive replies instead of directly using a new (or cached) `Consumer` to receive the reply for each request.
4545
When so configured, and no explicit reply destination is provided, a single `TemporaryQueue` is used for each gateway instead of one for each request.
4646

47+
Starting with version 6.0, the outbound gateway creates a `TemporaryTopic` instead of `TemporaryQueue` if `replyPubSubDomain` option is set to `true`.
48+
Some JMS vendors handle these destinations differently.
49+
4750
[[jms-inbound-channel-adapter]]
4851
=== Inbound Channel Adapter
4952

@@ -412,13 +415,13 @@ To revert to the previous behavior, set the `shutdownContainerOnStop` on the `Jm
412415
=== Outbound Gateway
413416

414417
The outbound gateway creates JMS messages from Spring Integration messages and sends them to a 'request-destination'.
415-
It then handles the JMS reply message either by using a selector to receive from the 'reply-destination' that you configure or, if no 'reply-destination' is provided, by creating JMS `TemporaryQueue` instances.
418+
It then handles the JMS reply message either by using a selector to receive from the 'reply-destination' that you configure or, if no 'reply-destination' is provided, by creating JMS `TemporaryQueue` (or `TemporaryTopic` if `replyPubSubDomain= true`) instances.
416419

417420
[[jms-outbound-gateway-memory-caution]]
418421
[CAUTION]
419422
=====
420423
Using a `reply-destination` (or `reply-destination-name`) together with a `CachingConnectionFactory` that has cacheConsumers set to `true` can cause out-of-memory conditions.
421-
This is because each request gets a new consumer with a new selector (selecting on the `correlation-key` value or, when there is no `correlation-key`, on the sent JMSMessageID).
424+
This is because each request gets a new consumer with a new selector (selecting on the `correlation-key` value or when there is no `correlation-key`, on the sent JMSMessageID).
422425
Given that these selectors are unique, they remain in the cache (unused) after the current request completes.
423426
424427
If you specify a reply destination, you are advised to not use cached consumers.
@@ -450,6 +453,7 @@ This provides a number of performance benefits as well as alleviating the cached
450453

451454
When using a `<reply-listener/>` with an outbound gateway that has no `reply-destination`, instead of creating a `TemporaryQueue` for each request, a single `TemporaryQueue` is used.
452455
(The gateway creates an additional `TemporaryQueue`, as necessary, if the connection to the broker is lost and recovered).
456+
If `replyPubSubDomain` is set to `true`, starting with version 6.0, a `TemporaryTopic` is created instead.
453457

454458
When using a `correlation-key`, multiple gateways can share the same reply destination, because the listener container uses a selector that is unique to each gateway.
455459

src/reference/asciidoc/whats-new.adoc

+6
Original file line numberDiff line numberDiff line change
@@ -129,3 +129,9 @@ See <<./jdbc.adoc#jdbc-lock-registry,JDBC Lock Registry>> for more information.
129129
The `lookupHost` property of the `AbstractConnectionFactory` and `DatagramPacketMessageMapper` is now set to `false` by default to avoid delays in the environments where DNS is not configured.
130130

131131
See <<./ip.adoc#ip,TCP and UDP Support>> for more information.
132+
133+
=== JMS Changes
134+
135+
The `JmsOutboundGateway` now creates a `TemporaryTopic` instead of `TemporaryQueue` if `replyPubSubDomain` option is set to `true`.
136+
137+
See <<./jms.adoc#jms,JMS Support>> for more information.

0 commit comments

Comments
 (0)