Skip to content

Commit 02b0b6e

Browse files
committed
fix (dispatcher): deactivate publisher confirms (keep only publisher returns)
1 parent 87b0b41 commit 02b0b6e

4 files changed

Lines changed: 17 additions & 5 deletions

File tree

hub/dispatcher/src/main/resources/application-local.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@ spring:
22
rabbitmq:
33
host: localhost
44
port: 5671
5-
publisher-confirm-type: correlated
65
publisher-returns: true
76
template:
87
mandatory: true

hub/dispatcher/src/main/resources/application.properties

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,6 @@ spring.rabbitmq.ssl.trust-store=file:/certs/trustStore
1212
# https://docs.spring.io/spring-amqp/reference/html/#cf-pub-conf-ret
1313
# https://docs.spring.io/spring-amqp/reference/html/#template-confirms
1414
# https://github.com/spring-projects/spring-amqp-samples/tree/main/spring-rabbit-confirms-returns
15-
spring.rabbitmq.publisher-confirm-type=correlated
1615
spring.rabbitmq.publisher-returns=true
1716
spring.rabbitmq.template.mandatory=true
1817

hub/dispatcher/src/test/java/com/hubsante/hub/service/RabbitIntegrationAbstract.java

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,18 @@ public void cleanUp() throws IOException, InterruptedException {
102102

103103
protected RabbitTemplate getCustomRabbitTemplate(String p12Path, String p12Passphrase)
104104
throws Exception {
105+
return getCustomRabbitTemplate(
106+
p12Path, p12Passphrase, CachingConnectionFactory.ConfirmType.NONE);
107+
}
108+
109+
// overload for tests needing setConfirmCallback (e.g.
110+
// publishWithAuthorizedButInconsistentRoutingKeyFails) to observe a broker-side nack,
111+
// independently of the Dispatcher's own publisher-confirm-type setting
112+
protected RabbitTemplate getCustomRabbitTemplate(
113+
String p12Path,
114+
String p12Passphrase,
115+
CachingConnectionFactory.ConfirmType confirmType)
116+
throws Exception {
105117
com.rabbitmq.client.ConnectionFactory cf = new com.rabbitmq.client.ConnectionFactory();
106118
cf.setHost(rabbitMQContainer.getHost());
107119
cf.setPort(rabbitMQContainer.getAmqpsPort());
@@ -112,7 +124,7 @@ protected RabbitTemplate getCustomRabbitTemplate(String p12Path, String p12Passp
112124

113125
cf.setSaslConfig(DefaultSaslConfig.EXTERNAL);
114126
CachingConnectionFactory ccf = new CachingConnectionFactory(cf);
115-
ccf.setPublisherConfirmType(CachingConnectionFactory.ConfirmType.CORRELATED);
127+
ccf.setPublisherConfirmType(confirmType);
116128
ccf.setPublisherReturns(true);
117129

118130
return new RabbitTemplate(ccf);
@@ -152,7 +164,6 @@ public void initialize(ConfigurableApplicationContext applicationContext) {
152164

153165
// must be set to handle PublisherConfirms in other RabbitTemplates,
154166
// even if we don't use it in Dispatcher
155-
"spring.rabbitmq.publisher-confirm-type=correlated",
156167
"spring.rabbitmq.publisher-returns=true",
157168
"spring.rabbitmq.template.mandatory=true",
158169
"spring.rabbitmq.virtual-host=15-15_v2.1",

hub/dispatcher/src/test/java/com/hubsante/hub/service/RabbitIntegrationTest.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.junit.jupiter.api.*;
3232
import org.springframework.amqp.core.Message;
3333
import org.springframework.amqp.core.MessageProperties;
34+
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
3435
import org.springframework.amqp.rabbit.core.RabbitTemplate;
3536
import org.springframework.beans.factory.annotation.Autowired;
3637

@@ -72,7 +73,9 @@ public void shouldDeliverToRecipientQueue() throws Exception {
7273
@DisplayName("publish with authorized but inconsistent routing key fails")
7374
public void publishWithAuthorizedButInconsistentRoutingKeyFails() throws Exception {
7475
String p12Path = classLoader.getResource("config/certs/samuA/samuA.p12").getPath();
75-
RabbitTemplate samuA_publisher = getCustomRabbitTemplate(p12Path, "samuA");
76+
RabbitTemplate samuA_publisher =
77+
getCustomRabbitTemplate(
78+
p12Path, "samuA", CachingConnectionFactory.ConfirmType.CORRELATED);
7679

7780
samuA_publisher.setConfirmCallback(
7881
(correlationData, ack, cause) -> {

0 commit comments

Comments
 (0)