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:
@@ -65,6 +65,11 @@ public class IntegrationMessageHeaderAccessor extends MessageHeaderAccessor {
|
||||
|
||||
public static final String DELIVERY_ATTEMPT = "deliveryAttempt";
|
||||
|
||||
/**
|
||||
* A callback to acknowledge message delivery. The type of the header value depends on
|
||||
* the context in which the header is used. See the reference manual for more
|
||||
* information.
|
||||
*/
|
||||
public static final String ACKNOWLEDGMENT_CALLBACK = "acknowledgmentCallback";
|
||||
|
||||
/**
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2017-2019 the original author or authors.
|
||||
* Copyright 2017-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.
|
||||
@@ -21,6 +21,7 @@ import java.util.UUID;
|
||||
import java.util.concurrent.atomic.AtomicInteger;
|
||||
|
||||
import org.springframework.integration.acks.AcknowledgmentCallback;
|
||||
import org.springframework.integration.acks.SimpleAcknowledgment;
|
||||
import org.springframework.lang.Nullable;
|
||||
import org.springframework.messaging.Message;
|
||||
import org.springframework.messaging.MessageHeaders;
|
||||
@@ -107,6 +108,12 @@ public final class StaticMessageHeaderAccessor {
|
||||
AcknowledgmentCallback.class);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
public static SimpleAcknowledgment getAcknowledgment(Message<?> message) {
|
||||
return message.getHeaders().get(IntegrationMessageHeaderAccessor.ACKNOWLEDGMENT_CALLBACK,
|
||||
SimpleAcknowledgment.class);
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Nullable
|
||||
public static <T> T getSourceData(Message<?> message) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2018-2019 the original author or authors.
|
||||
* Copyright 2018-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.
|
||||
@@ -25,7 +25,7 @@ package org.springframework.integration.acks;
|
||||
*
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface AcknowledgmentCallback {
|
||||
public interface AcknowledgmentCallback extends SimpleAcknowledgment {
|
||||
|
||||
/**
|
||||
* Acknowledge the message.
|
||||
@@ -33,6 +33,11 @@ public interface AcknowledgmentCallback {
|
||||
*/
|
||||
void acknowledge(Status status);
|
||||
|
||||
@Override
|
||||
default void acknowledge() {
|
||||
acknowledge(Status.ACCEPT);
|
||||
}
|
||||
|
||||
/**
|
||||
* Implementations must implement this to indicate when the ack has been
|
||||
* processed by the user so that the framework can auto-ack if needed.
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
/*
|
||||
* Copyright 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.acks;
|
||||
|
||||
/**
|
||||
* Opaque object for manually acknowledging.
|
||||
*
|
||||
* @author Gary Russell
|
||||
* @since 5.3
|
||||
*
|
||||
*/
|
||||
@FunctionalInterface
|
||||
public interface SimpleAcknowledgment {
|
||||
|
||||
/**
|
||||
* Acknowledge the message delivery.
|
||||
*/
|
||||
void acknowledge();
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user