GH-3181: MQTT: Support MANUAL Acks
Resolves https://github.com/spring-projects/spring-integration/issues/3181 * Doc polishing * Rework acknowledgment into the existing `AcknowledgmentCallback`. * Fix javadocs and doc linFix javadocs and doc linkk * Doc polishing; explain uses of `ACKNOWLEDGMENT_CALLBACK` header.
This commit is contained in:
@@ -74,6 +74,7 @@ import org.springframework.context.ApplicationEventPublisher;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.integration.StaticMessageHeaderAccessor;
|
||||
import org.springframework.integration.channel.NullChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.handler.MessageProcessor;
|
||||
@@ -85,6 +86,7 @@ import org.springframework.integration.mqtt.event.MqttSubscribedEvent;
|
||||
import org.springframework.integration.mqtt.inbound.MqttPahoMessageDrivenChannelAdapter;
|
||||
import org.springframework.integration.mqtt.outbound.MqttPahoMessageHandler;
|
||||
import org.springframework.integration.mqtt.support.DefaultPahoMessageConverter;
|
||||
import org.springframework.integration.mqtt.support.MqttHeaderAccessor;
|
||||
import org.springframework.integration.test.util.TestUtils;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHandlingException;
|
||||
@@ -264,6 +266,7 @@ public class MqttAdapterTests {
|
||||
|
||||
MqttPahoMessageDrivenChannelAdapter adapter = new MqttPahoMessageDrivenChannelAdapter("foo", "bar", factory,
|
||||
"baz", "fix");
|
||||
adapter.setManualAcks(true);
|
||||
QueueChannel outputChannel = new QueueChannel();
|
||||
adapter.setOutputChannel(outputChannel);
|
||||
ThreadPoolTaskScheduler taskScheduler = new ThreadPoolTaskScheduler();
|
||||
@@ -290,6 +293,11 @@ public class MqttAdapterTests {
|
||||
assertThat(outMessage).isNotNull();
|
||||
assertThat(outMessage.getPayload()).isEqualTo("qux");
|
||||
|
||||
StaticMessageHeaderAccessor.getAcknowledgment(outMessage).acknowledge();
|
||||
verify(client).setManualAcks(true);
|
||||
verify(client)
|
||||
.messageArrivedComplete(MqttHeaderAccessor.id(outMessage), MqttHeaderAccessor.receivedQos(outMessage));
|
||||
|
||||
MqttIntegrationEvent event = events.poll(10, TimeUnit.SECONDS);
|
||||
assertThat(event).isInstanceOf(MqttSubscribedEvent.class);
|
||||
assertThat(((MqttSubscribedEvent) event).getMessage()).isEqualTo("Connected and subscribed to [baz, fix]");
|
||||
|
||||
@@ -12,6 +12,7 @@
|
||||
|
||||
<int-mqtt:message-driven-channel-adapter id="noTopicsAdapter"
|
||||
auto-startup="false"
|
||||
manual-acks="true"
|
||||
client-id="foo"
|
||||
url="tcp://localhost:1883"
|
||||
client-factory="clientFactory"
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2019 the original author or authors.
|
||||
* Copyright 2002-2020 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -79,6 +79,7 @@ public class MqttMessageDrivenChannelAdapterParserTests {
|
||||
assertThat(TestUtils.getPropertyValue(noTopicsAdapter, "outputChannel")).isSameAs(out);
|
||||
assertThat(TestUtils.getPropertyValue(noTopicsAdapter, "clientFactory")).isSameAs(clientFactory);
|
||||
assertThat(TestUtils.getPropertyValue(this.noTopicsAdapter, "recoveryInterval")).isEqualTo(5000);
|
||||
assertThat(TestUtils.getPropertyValue(this.noTopicsAdapter, "manualAcks", Boolean.class)).isTrue();
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -89,6 +90,7 @@ public class MqttMessageDrivenChannelAdapterParserTests {
|
||||
assertThat(TestUtils.getPropertyValue(noTopicsAdapterDefaultCF, "topics", Collection.class).size())
|
||||
.isEqualTo(0);
|
||||
assertThat(TestUtils.getPropertyValue(noTopicsAdapterDefaultCF, "outputChannel")).isSameAs(out);
|
||||
assertThat(TestUtils.getPropertyValue(this.noTopicsAdapterDefaultCF, "manualAcks", Boolean.class)).isFalse();
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user