Add missed options and JavaDocs to AMQP Java DSL

This commit is contained in:
Artem Bilan
2018-02-09 16:20:48 -05:00
committed by Gary Russell
parent 09aeaac4da
commit d361eefa0c
7 changed files with 318 additions and 19 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2018 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,8 @@ import org.springframework.integration.amqp.inbound.AmqpInboundChannelAdapter;
import org.springframework.integration.amqp.support.AmqpHeaderMapper;
import org.springframework.integration.amqp.support.DefaultAmqpHeaderMapper;
import org.springframework.integration.dsl.MessageProducerSpec;
import org.springframework.retry.RecoveryCallback;
import org.springframework.retry.support.RetryTemplate;
/**
* The base {@link MessageProducerSpec} implementation for a {@link AmqpInboundChannelAdapter}.
@@ -28,6 +30,7 @@ import org.springframework.integration.dsl.MessageProducerSpec;
* @param <S> the target {@link AmqpBaseInboundChannelAdapterSpec} implementation type.
*
* @author Artem Bilan
*
* @since 5.0
*/
public class AmqpBaseInboundChannelAdapterSpec<S extends AmqpBaseInboundChannelAdapterSpec<S>>
@@ -74,4 +77,28 @@ public class AmqpBaseInboundChannelAdapterSpec<S extends AmqpBaseInboundChannelA
return _this();
}
/**
* Set a {@link RetryTemplate} to use for retrying a message delivery within the
* adapter.
* @param retryTemplate the template.
* @return the spec.
* @since 5.0.2
* @see AmqpInboundChannelAdapter#setRetryTemplate(RetryTemplate)
*/
public S retryTemplate(RetryTemplate retryTemplate) {
this.target.setRetryTemplate(retryTemplate);
return _this();
}
/**
* Set a {@link RecoveryCallback} when using retry within the adapter.
* @param recoveryCallback the callback.
* @since 5.0.2
* @see AmqpInboundChannelAdapter#setRecoveryCallback(RecoveryCallback)
*/
public S recoveryCallback(RecoveryCallback<?> recoveryCallback) {
this.target.setRecoveryCallback(recoveryCallback);
return _this();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2014-2016 the original author or authors.
* Copyright 2014-2018 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,8 @@ import org.springframework.integration.amqp.inbound.AmqpInboundGateway;
import org.springframework.integration.amqp.support.AmqpHeaderMapper;
import org.springframework.integration.amqp.support.DefaultAmqpHeaderMapper;
import org.springframework.integration.dsl.MessagingGatewaySpec;
import org.springframework.retry.RecoveryCallback;
import org.springframework.retry.support.RetryTemplate;
/**
* A base {@link MessagingGatewaySpec} implementation for {@link AmqpInboundGateway} endpoint options.
@@ -29,6 +31,7 @@ import org.springframework.integration.dsl.MessagingGatewaySpec;
* @param <S> the target {@link AmqpBaseInboundGatewaySpec} implementation type.
*
* @author Artem Bilan
*
* @since 5.0
*
* @see AmqpInboundGateway
@@ -60,6 +63,7 @@ public class AmqpBaseInboundGatewaySpec<S extends AmqpBaseInboundGatewaySpec<S>>
* {@link org.springframework.integration.amqp.support.DefaultAmqpHeaderMapper}.
* @param headerMapper the headerMapper.
* @return the spec.
* @see AmqpInboundGateway#setHeaderMapper(AmqpHeaderMapper)
*/
public S headerMapper(AmqpHeaderMapper headerMapper) {
this.target.setHeaderMapper(headerMapper);
@@ -70,7 +74,7 @@ public class AmqpBaseInboundGatewaySpec<S extends AmqpBaseInboundGatewaySpec<S>>
* Only applies if the default header mapper is used.
* @param headers the headers.
* @return the spec.
* @see org.springframework.integration.amqp.support.DefaultAmqpHeaderMapper#setRequestHeaderNames(String[])
* @see DefaultAmqpHeaderMapper#setRequestHeaderNames(String[])
*/
public S mappedRequestHeaders(String... headers) {
this.headerMapper.setRequestHeaderNames(headers);
@@ -81,7 +85,7 @@ public class AmqpBaseInboundGatewaySpec<S extends AmqpBaseInboundGatewaySpec<S>>
* Only applies if the default header mapper is used.
* @param headers the headers.
* @return the spec.
* @see org.springframework.integration.amqp.support.DefaultAmqpHeaderMapper#setReplyHeaderNames(String[])
* @see DefaultAmqpHeaderMapper#setReplyHeaderNames(String[])
*/
public S mappedReplyHeaders(String... headers) {
this.headerMapper.setReplyHeaderNames(headers);
@@ -109,4 +113,28 @@ public class AmqpBaseInboundGatewaySpec<S extends AmqpBaseInboundGatewaySpec<S>>
return _this();
}
/**
* Set a {@link RetryTemplate} to use for retrying a message delivery within the
* adapter.
* @param retryTemplate the template.
* @return the spec.
* @since 5.0.2
* @see AmqpInboundGateway#setRetryTemplate(RetryTemplate)
*/
public S retryTemplate(RetryTemplate retryTemplate) {
this.target.setRetryTemplate(retryTemplate);
return _this();
}
/**
* Set a {@link RecoveryCallback} when using retry within the adapter.
* @param recoveryCallback the callback.
* @since 5.0.2
* @see AmqpInboundGateway#setRecoveryCallback(RecoveryCallback)
*/
public S recoveryCallback(RecoveryCallback<?> recoveryCallback) {
this.target.setRecoveryCallback(recoveryCallback);
return _this();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2016-2018 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,8 +25,10 @@ import org.springframework.integration.amqp.support.AmqpHeaderMapper;
import org.springframework.integration.amqp.support.DefaultAmqpHeaderMapper;
import org.springframework.integration.dsl.MessageHandlerSpec;
import org.springframework.integration.expression.FunctionExpression;
import org.springframework.integration.support.ErrorMessageStrategy;
import org.springframework.messaging.Message;
import org.springframework.messaging.MessageChannel;
import org.springframework.messaging.MessageHeaders;
/**
* The base {@link MessageHandlerSpec} for {@link AbstractAmqpOutboundEndpoint}s.
@@ -35,100 +37,193 @@ import org.springframework.messaging.MessageChannel;
* @param <E> the target {@link AbstractAmqpOutboundEndpoint} implementation type.
*
* @author Artem Bilan
*
* @since 5.0
*/
public abstract class
AmqpBaseOutboundEndpointSpec<S extends AmqpBaseOutboundEndpointSpec<S, E>, E extends AbstractAmqpOutboundEndpoint>
AmqpBaseOutboundEndpointSpec<S extends AmqpBaseOutboundEndpointSpec<S, E>, E extends AbstractAmqpOutboundEndpoint>
extends MessageHandlerSpec<S, E> {
protected final DefaultAmqpHeaderMapper headerMapper = DefaultAmqpHeaderMapper.outboundMapper();
/**
* Set a custom {@link AmqpHeaderMapper} for mapping request and reply headers.
* @param headerMapper the {@link AmqpHeaderMapper} to use.
* @return the spec
*/
public S headerMapper(AmqpHeaderMapper headerMapper) {
this.target.setHeaderMapper(headerMapper);
return _this();
}
/**
* Set the default delivery mode.
* @param defaultDeliveryMode the delivery mode.
* @return the spec
*/
public S defaultDeliveryMode(MessageDeliveryMode defaultDeliveryMode) {
this.target.setDefaultDeliveryMode(defaultDeliveryMode);
return _this();
}
/**
* Configure an AMQP routing key for sending messages.
* @param routingKey the routing key to use
* @return the spec
*/
public S routingKey(String routingKey) {
this.target.setRoutingKey(routingKey);
return _this();
}
/**
* A SpEL expression to evaluate routing key at runtime.
* @param routingKeyExpression the expression to use.
* @return the spec
*/
public S routingKeyExpression(String routingKeyExpression) {
return routingKeyExpression(PARSER.parseExpression(routingKeyExpression));
}
/**
* A function to evaluate routing key at runtime.
* @param routingKeyFunction the {@link Function} to use.
* @return the spec
*/
public S routingKeyFunction(Function<Message<?>, String> routingKeyFunction) {
return routingKeyExpression(new FunctionExpression<Message<?>>(routingKeyFunction));
return routingKeyExpression(new FunctionExpression<>(routingKeyFunction));
}
/**
* A SpEL expression to evaluate routing key at runtime.
* @param routingKeyExpression the expression to use.
* @return the spec
*/
public S routingKeyExpression(Expression routingKeyExpression) {
this.target.setRoutingKeyExpression(routingKeyExpression);
return _this();
}
/**
* Set the channel to which returned messages are sent.
* @param returnChannel the channel.
* @return the spec
*/
public S returnChannel(MessageChannel returnChannel) {
this.target.setReturnChannel(returnChannel);
return _this();
}
/**
* Set the channel to which acks are send (publisher confirms).
* @param ackChannel the channel.
* @return the spec
*/
public S confirmAckChannel(MessageChannel ackChannel) {
this.target.setConfirmAckChannel(ackChannel);
return _this();
}
/**
* Configure an AMQP exchange name for sending messages.
* @param exchangeName the exchange name for sending messages.
* @return the spec
*/
public S exchangeName(String exchangeName) {
this.target.setExchangeName(exchangeName);
return _this();
}
/**
* Configure a SpEL expression to evaluate an exchange name at runtime.
* @param exchangeNameExpression the expression to use.
* @return the spec
*/
public S exchangeNameExpression(String exchangeNameExpression) {
return exchangeNameExpression(PARSER.parseExpression(exchangeNameExpression));
}
/**
* Configure a {@link Function} to evaluate an exchange name at runtime.
* @param exchangeNameFunction the function to use.
* @return the spec
*/
public S exchangeNameFunction(Function<Message<?>, String> exchangeNameFunction) {
return exchangeNameExpression(new FunctionExpression<Message<?>>(exchangeNameFunction));
return exchangeNameExpression(new FunctionExpression<>(exchangeNameFunction));
}
/**
* Configure a SpEL expression to evaluate an exchange name at runtime.
* @param exchangeNameExpression the expression to use.
* @return the spec
*/
public S exchangeNameExpression(Expression exchangeNameExpression) {
this.target.setExchangeNameExpression(exchangeNameExpression);
return _this();
}
/**
* Set the channel to which nacks are send (publisher confirms).
* @param nackChannel the channel.
* @return the spec
*/
public S confirmNackChannel(MessageChannel nackChannel) {
this.target.setConfirmNackChannel(nackChannel);
return _this();
}
/**
* Set a SpEL expression to evaluate confirm correlation at runtime.
* @param confirmCorrelationExpression the expression to use.
* @return the spec
*/
public S confirmCorrelationExpression(String confirmCorrelationExpression) {
return confirmCorrelationExpression(PARSER.parseExpression(confirmCorrelationExpression));
}
/**
* Set a {@link Function} to evaluate confirm correlation at runtime.
* @param confirmCorrelationFunction the function to use.
* @return the spec
*/
public S confirmCorrelationFunction(Function<Message<?>, Object> confirmCorrelationFunction) {
return confirmCorrelationExpression(new FunctionExpression<Message<?>>(confirmCorrelationFunction));
return confirmCorrelationExpression(new FunctionExpression<>(confirmCorrelationFunction));
}
/**
* Set a SpEL expression to evaluate confirm correlation at runtime.
* @param confirmCorrelationExpression the expression to use.
* @return the spec
*/
public S confirmCorrelationExpression(Expression confirmCorrelationExpression) {
this.target.setConfirmCorrelationExpression(confirmCorrelationExpression);
return _this();
}
/**
* Provide the header names that should be mapped from a request to a {@link MessageHeaders}.
* @param headers The request header names.
* @return the spec
*/
public S mappedRequestHeaders(String... headers) {
this.headerMapper.setRequestHeaderNames(headers);
return _this();
}
/**
* Provide the header names that should be mapped to a response
* from a {@link MessageHeaders}.
* @param headers The reply header names.
* @return the spec
*/
public S mappedReplyHeaders(String... headers) {
this.headerMapper.setReplyHeaderNames(headers);
return _this();
}
/**
* Determine whether the headers are
* mapped before the message is converted, or afterwards.
* @param headersLast true to map headers last.
* @return the spec.
* @see AbstractAmqpOutboundEndpoint#setHeadersMappedLast(boolean)
@@ -138,4 +233,81 @@ public abstract class
return _this();
}
/**
* Set to {@code false} to attempt to connect during endpoint start.
* @param lazyConnect the lazyConnect to set.
* @return the spec.
* @since 5.0.2
* @see AbstractAmqpOutboundEndpoint#setLazyConnect(boolean)
*/
public S lazyConnect(boolean lazyConnect) {
this.target.setLazyConnect(lazyConnect);
return _this();
}
/**
* Set the value to set in the {@code x-delay} header when using the
* RabbitMQ delayed message exchange plugin.
* @param delay the delay.
* @return the spec.
* @since 5.0.2
* @see AbstractAmqpOutboundEndpoint#setDelay(int)
*/
public S delay(int delay) {
this.target.setDelay(delay);
return _this();
}
/**
* Set the function to calculate the {@code x-delay} header when using the
* RabbitMQ delayed message exchange plugin.
* @param delayFunction the function to evaluate the value for the {@code x-delay} header.
* @return the spec.
* @since 5.0.2
* @see #delayExpression(Expression)
*/
public S delayFunction(Function<Message<?>, Integer> delayFunction) {
return delayExpression(new FunctionExpression<>(delayFunction));
}
/**
* Set the SpEL expression to calculate the {@code x-delay} header when using the
* RabbitMQ delayed message exchange plugin.
* @param delayExpression the expression.
* @return the spec.
* @since 5.0.2
* @see AbstractAmqpOutboundEndpoint#setDelayExpression(Expression)
*/
public S delayExpression(Expression delayExpression) {
this.target.setDelayExpression(delayExpression);
return _this();
}
/**
* Set the SpEL expression to calculate the {@code x-delay} header when using the
* RabbitMQ delayed message exchange plugin.
* @param delayExpression the expression.
* @return the spec.
* @since 5.0.2
* @see AbstractAmqpOutboundEndpoint#setDelayExpressionString(String)
*/
public S delayExpression(String delayExpression) {
this.target.setDelayExpressionString(delayExpression);
return _this();
}
/**
Set the error message strategy to use for returned (or negatively confirmed)
* messages.
* @param errorMessageStrategy the strategy.
* @return the spec.
* @since 5.0.2
* @see AbstractAmqpOutboundEndpoint#setErrorMessageStrategy(ErrorMessageStrategy)
*/
public S errorMessageStrategy(ErrorMessageStrategy errorMessageStrategy) {
this.target.setErrorMessageStrategy(errorMessageStrategy);
return _this();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016-2017 the original author or authors.
* Copyright 2016-2018 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.
@@ -52,7 +52,7 @@ import org.springframework.util.StringUtils;
*
*/
public abstract class AbstractAmqpOutboundEndpoint extends AbstractReplyProducingMessageHandler
implements Lifecycle {
implements Lifecycle {
private String exchangeName;
@@ -98,6 +98,11 @@ public abstract class AbstractAmqpOutboundEndpoint extends AbstractReplyProducin
private volatile boolean running;
/**
* Set a custom {@link AmqpHeaderMapper} for mapping request and reply headers.
* Defaults to {@link DefaultAmqpHeaderMapper#outboundMapper()}.
* @param headerMapper the {@link AmqpHeaderMapper} to use.
*/
public void setHeaderMapper(AmqpHeaderMapper headerMapper) {
Assert.notNull(headerMapper, "headerMapper must not be null");
this.headerMapper = headerMapper;
@@ -121,12 +126,17 @@ public abstract class AbstractAmqpOutboundEndpoint extends AbstractReplyProducin
this.headersMappedLast = headersMappedLast;
}
/**
* Configure an AMQP exchange name for sending messages.
* @param exchangeName the exchange name for sending messages.
*/
public void setExchangeName(String exchangeName) {
Assert.notNull(exchangeName, "exchangeName must not be null");
this.exchangeName = exchangeName;
}
/**
* Configure a SpEL expression to evaluate an exchange name at runtime.
* @param exchangeNameExpression the expression to use.
* @since 4.3
*/
@@ -143,6 +153,10 @@ public abstract class AbstractAmqpOutboundEndpoint extends AbstractReplyProducin
this.exchangeNameExpression = EXPRESSION_PARSER.parseExpression(exchangeNameExpression);
}
/**
* Configure an AMQP routing key for sending messages.
* @param routingKey the routing key to use
*/
public void setRoutingKey(String routingKey) {
Assert.notNull(routingKey, "routingKey must not be null");
this.routingKey = routingKey;
@@ -166,6 +180,7 @@ public abstract class AbstractAmqpOutboundEndpoint extends AbstractReplyProducin
}
/**
* Set a SpEL expression to evaluate confirm correlation at runtime.
* @param confirmCorrelationExpression the expression to use.
* @since 4.3
*/
@@ -174,6 +189,7 @@ public abstract class AbstractAmqpOutboundEndpoint extends AbstractReplyProducin
}
/**
* Set a SpEL expression to evaluate confirm correlation at runtime.
* @param confirmCorrelationExpression the String in SpEL syntax.
* @since 4.3
*/

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2016-2018 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.
@@ -17,6 +17,7 @@
package org.springframework.integration.dsl;
import org.springframework.integration.endpoint.MessageProducerSupport;
import org.springframework.integration.support.ErrorMessageStrategy;
import org.springframework.messaging.MessageChannel;
/**
@@ -75,7 +76,7 @@ public abstract class MessageProducerSpec<S extends MessageProducerSpec<S, P>, P
* @see MessageProducerSupport#setOutputChannel(MessageChannel)
*/
public S outputChannel(MessageChannel outputChannel) {
target.setOutputChannel(outputChannel);
this.target.setOutputChannel(outputChannel);
return _this();
}
@@ -87,7 +88,7 @@ public abstract class MessageProducerSpec<S extends MessageProducerSpec<S, P>, P
* @see MessageProducerSupport#setOutputChannelName(String)
*/
public S outputChannel(String outputChannel) {
target.setOutputChannelName(outputChannel);
this.target.setOutputChannelName(outputChannel);
return _this();
}
@@ -98,7 +99,7 @@ public abstract class MessageProducerSpec<S extends MessageProducerSpec<S, P>, P
* @see MessageProducerSupport#setErrorChannel(MessageChannel)
*/
public S errorChannel(MessageChannel errorChannel) {
target.setErrorChannel(errorChannel);
this.target.setErrorChannel(errorChannel);
return _this();
}
@@ -109,7 +110,44 @@ public abstract class MessageProducerSpec<S extends MessageProducerSpec<S, P>, P
* @see MessageProducerSupport#setErrorChannelName(String)
*/
public S errorChannel(String errorChannel) {
target.setErrorChannelName(errorChannel);
this.target.setErrorChannelName(errorChannel);
return _this();
}
/**
* Configure the default timeout value to use for send operations.
* May be overridden for individual messages.
* @param sendTimeout the send timeout in milliseconds
* @return the spec.
* @since 5.0.2
* @see MessageProducerSupport#setSendTimeout
*/
public S sendTimeout(long sendTimeout) {
this.target.setSendTimeout(sendTimeout);
return _this();
}
/**
* Whether component should be tracked or not by message history.
* @param shouldTrack the tracking flag
* @return the spec.
* @since 5.0.2
* @see MessageProducerSupport#setShouldTrack(boolean)
*/
public S shouldTrack(boolean shouldTrack) {
this.target.setShouldTrack(shouldTrack);
return _this();
}
/**
* Set an {@link ErrorMessageStrategy} to use to build an error message when a exception occurs.
* @param errorMessageStrategy the {@link ErrorMessageStrategy}.
* @return the spec.
* @since 5.0.2
* @see MessageProducerSupport#setErrorMessageStrategy(ErrorMessageStrategy)
*/
public S errorMessageStrategy(ErrorMessageStrategy errorMessageStrategy) {
this.target.setErrorMessageStrategy(errorMessageStrategy);
return _this();
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2016 the original author or authors.
* Copyright 2016-2018 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.
@@ -176,4 +176,16 @@ public abstract class MessagingGatewaySpec<S extends MessagingGatewaySpec<S, G>,
return _this();
}
/**
* Whether component should be tracked or not by message history.
* @param shouldTrack the tracking flag
* @return the spec.
* @since 5.0.2
* @see MessagingGatewaySupport#setShouldTrack(boolean)
*/
public S shouldTrack(boolean shouldTrack) {
this.target.setShouldTrack(shouldTrack);
return _this();
}
}

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 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.
@@ -125,6 +125,12 @@ public abstract class MessageProducerSupport extends AbstractEndpoint implements
return this.errorChannel;
}
/**
* Configure the default timeout value to use for send operations.
* May be overridden for individual messages.
* @param sendTimeout the send timeout in milliseconds
* @see MessagingTemplate#setSendTimeout
*/
public void setSendTimeout(long sendTimeout) {
this.messagingTemplate.setSendTimeout(sendTimeout);
}