Skip to content

Commit 3b11519

Browse files
committed
Fix deprecation warnings in AMQP module
1 parent 5e1a92d commit 3b11519

File tree

2 files changed

+92
-67
lines changed

2 files changed

+92
-67
lines changed

spring-integration-amqp/src/main/java/org/springframework/integration/amqp/config/AmqpChannelFactoryBean.java

+75-63
Original file line numberDiff line numberDiff line change
@@ -70,73 +70,73 @@
7070
public class AmqpChannelFactoryBean extends AbstractFactoryBean<AbstractAmqpChannel>
7171
implements SmartLifecycle, BeanNameAware {
7272

73-
private volatile AbstractAmqpChannel channel;
74-
75-
private volatile List<ChannelInterceptor> interceptors;
73+
private final AmqpTemplate amqpTemplate = new RabbitTemplate();
7674

7775
private final boolean messageDriven;
7876

79-
private final AmqpTemplate amqpTemplate = new RabbitTemplate();
77+
private AbstractAmqpChannel channel;
78+
79+
private List<ChannelInterceptor> interceptors;
8080

81-
private volatile AmqpAdmin amqpAdmin;
81+
private AmqpAdmin amqpAdmin;
8282

83-
private volatile FanoutExchange exchange;
83+
private FanoutExchange exchange;
8484

85-
private volatile String queueName;
85+
private String queueName;
8686

87-
private volatile boolean autoStartup = true;
87+
private boolean autoStartup = true;
8888

89-
private volatile Advice[] adviceChain;
89+
private Advice[] adviceChain;
9090

91-
private volatile Integer concurrentConsumers;
91+
private Integer concurrentConsumers;
9292

93-
private volatile Integer consumersPerQueue;
93+
private Integer consumersPerQueue;
9494

95-
private volatile ConnectionFactory connectionFactory;
95+
private ConnectionFactory connectionFactory;
9696

97-
private volatile MessagePropertiesConverter messagePropertiesConverter;
97+
private MessagePropertiesConverter messagePropertiesConverter;
9898

99-
private volatile ErrorHandler errorHandler;
99+
private ErrorHandler errorHandler;
100100

101-
private volatile Boolean exposeListenerChannel;
101+
private Boolean exposeListenerChannel;
102102

103-
private volatile Integer phase;
103+
private Integer phase;
104104

105-
private volatile Integer prefetchCount;
105+
private Integer prefetchCount;
106106

107-
private volatile boolean isPubSub;
107+
private boolean isPubSub;
108108

109-
private volatile Long receiveTimeout;
109+
private Long receiveTimeout;
110110

111-
private volatile Long recoveryInterval;
111+
private Long recoveryInterval;
112112

113-
private volatile Long shutdownTimeout;
113+
private Long shutdownTimeout;
114114

115-
private volatile String beanName;
115+
private String beanName;
116116

117-
private volatile AcknowledgeMode acknowledgeMode;
117+
private AcknowledgeMode acknowledgeMode;
118118

119-
private volatile boolean channelTransacted;
119+
private boolean channelTransacted;
120120

121-
private volatile Executor taskExecutor;
121+
private Executor taskExecutor;
122122

123-
private volatile PlatformTransactionManager transactionManager;
123+
private PlatformTransactionManager transactionManager;
124124

125-
private volatile TransactionAttribute transactionAttribute;
125+
private TransactionAttribute transactionAttribute;
126126

127-
private volatile Integer txSize;
127+
private Integer batchSize;
128128

129-
private volatile Integer maxSubscribers;
129+
private Integer maxSubscribers;
130130

131-
private volatile Boolean missingQueuesFatal;
131+
private Boolean missingQueuesFatal;
132132

133-
private volatile MessageDeliveryMode defaultDeliveryMode;
133+
private MessageDeliveryMode defaultDeliveryMode;
134134

135-
private volatile Boolean extractPayload;
135+
private Boolean extractPayload;
136136

137-
private volatile AmqpHeaderMapper outboundHeaderMapper = DefaultAmqpHeaderMapper.outboundMapper();
137+
private AmqpHeaderMapper outboundHeaderMapper = DefaultAmqpHeaderMapper.outboundMapper();
138138

139-
private volatile AmqpHeaderMapper inboundHeaderMapper = DefaultAmqpHeaderMapper.inboundMapper();
139+
private AmqpHeaderMapper inboundHeaderMapper = DefaultAmqpHeaderMapper.inboundMapper();
140140

141141
private boolean headersLast;
142142

@@ -314,8 +314,18 @@ public void setTransactionManager(PlatformTransactionManager transactionManager)
314314
this.transactionManager = transactionManager;
315315
}
316316

317+
/**
318+
* Specify a batch size for consumer.
319+
* @param txSize the batch size to use
320+
* @deprecated since 5.2 in favor of {@link #setBatchSize(Integer)}
321+
*/
322+
@Deprecated
317323
public void setTxSize(int txSize) {
318-
this.txSize = txSize;
324+
setBatchSize(txSize);
325+
}
326+
327+
public void setBatchSize(Integer batchSize) {
328+
this.batchSize = batchSize;
319329
}
320330

321331
public void setMaxSubscribers(int maxSubscribers) {
@@ -360,18 +370,20 @@ protected AbstractAmqpChannel createInstance() {
360370
}
361371
if (this.isPubSub) {
362372
PublishSubscribeAmqpChannel pubsub = new PublishSubscribeAmqpChannel(
363-
this.beanName, container, this.amqpTemplate, this.outboundHeaderMapper, this.inboundHeaderMapper);
373+
this.beanName, container, this.amqpTemplate, this.outboundHeaderMapper,
374+
this.inboundHeaderMapper);
364375
JavaUtils.INSTANCE
365-
.acceptIfNotNull(this.exchange, pubsub::setExchange)
366-
.acceptIfNotNull(this.maxSubscribers, pubsub::setMaxSubscribers);
376+
.acceptIfNotNull(this.exchange, pubsub::setExchange)
377+
.acceptIfNotNull(this.maxSubscribers, pubsub::setMaxSubscribers);
367378
this.channel = pubsub;
368379
}
369380
else {
370381
PointToPointSubscribableAmqpChannel p2p = new PointToPointSubscribableAmqpChannel(
371-
this.beanName, container, this.amqpTemplate, this.outboundHeaderMapper, this.inboundHeaderMapper);
382+
this.beanName, container, this.amqpTemplate, this.outboundHeaderMapper,
383+
this.inboundHeaderMapper);
372384
JavaUtils.INSTANCE
373-
.acceptIfHasText(this.queueName, p2p::setQueueName)
374-
.acceptIfNotNull(this.maxSubscribers, p2p::setMaxSubscribers);
385+
.acceptIfHasText(this.queueName, p2p::setQueueName)
386+
.acceptIfNotNull(this.maxSubscribers, p2p::setMaxSubscribers);
375387
this.channel = p2p;
376388
}
377389
}
@@ -380,17 +392,17 @@ protected AbstractAmqpChannel createInstance() {
380392
PollableAmqpChannel pollable = new PollableAmqpChannel(this.beanName, this.amqpTemplate,
381393
this.outboundHeaderMapper, this.inboundHeaderMapper);
382394
JavaUtils.INSTANCE
383-
.acceptIfNotNull(this.amqpAdmin, pollable::setAmqpAdmin)
384-
.acceptIfHasText(this.queueName, pollable::setQueueName);
395+
.acceptIfNotNull(this.amqpAdmin, pollable::setAmqpAdmin)
396+
.acceptIfHasText(this.queueName, pollable::setQueueName);
385397
this.channel = pollable;
386398
}
387399
JavaUtils.INSTANCE
388-
.acceptIfNotEmpty(this.interceptors, this.channel::setInterceptors);
400+
.acceptIfNotEmpty(this.interceptors, this.channel::setInterceptors);
389401
this.channel.setBeanName(this.beanName);
390402
JavaUtils.INSTANCE
391-
.acceptIfNotNull(getBeanFactory(), this.channel::setBeanFactory)
392-
.acceptIfNotNull(this.defaultDeliveryMode, this.channel::setDefaultDeliveryMode)
393-
.acceptIfNotNull(this.extractPayload, this.channel::setExtractPayload);
403+
.acceptIfNotNull(getBeanFactory(), this.channel::setBeanFactory)
404+
.acceptIfNotNull(this.defaultDeliveryMode, this.channel::setDefaultDeliveryMode)
405+
.acceptIfNotNull(this.extractPayload, this.channel::setExtractPayload);
394406
this.channel.setHeadersMappedLast(this.headersLast);
395407
this.channel.afterPropertiesSet();
396408
return this.channel;
@@ -401,9 +413,9 @@ private AbstractMessageListenerContainer createContainer() {
401413
if (this.consumersPerQueue == null) {
402414
SimpleMessageListenerContainer smlc = new SimpleMessageListenerContainer();
403415
JavaUtils.INSTANCE
404-
.acceptIfNotNull(this.concurrentConsumers, smlc::setConcurrentConsumers)
405-
.acceptIfNotNull(this.receiveTimeout, smlc::setReceiveTimeout)
406-
.acceptIfNotNull(this.txSize, smlc::setTxSize);
416+
.acceptIfNotNull(this.concurrentConsumers, smlc::setConcurrentConsumers)
417+
.acceptIfNotNull(this.receiveTimeout, smlc::setReceiveTimeout)
418+
.acceptIfNotNull(this.batchSize, smlc::setBatchSize);
407419
container = smlc;
408420
}
409421
else {
@@ -412,24 +424,24 @@ private AbstractMessageListenerContainer createContainer() {
412424
container = dmlc;
413425
}
414426
JavaUtils.INSTANCE
415-
.acceptIfNotNull(this.acknowledgeMode, container::setAcknowledgeMode)
416-
.acceptIfNotEmpty(this.adviceChain, container::setAdviceChain);
427+
.acceptIfNotNull(this.acknowledgeMode, container::setAcknowledgeMode)
428+
.acceptIfNotEmpty(this.adviceChain, container::setAdviceChain);
417429
container.setAutoStartup(this.autoStartup);
418430
container.setChannelTransacted(this.channelTransacted);
419431
container.setConnectionFactory(this.connectionFactory);
420432

421433
JavaUtils.INSTANCE
422-
.acceptIfNotNull(this.errorHandler, container::setErrorHandler)
423-
.acceptIfNotNull(this.exposeListenerChannel, container::setExposeListenerChannel)
424-
.acceptIfNotNull(this.messagePropertiesConverter, container::setMessagePropertiesConverter)
425-
.acceptIfNotNull(this.phase, container::setPhase)
426-
.acceptIfNotNull(this.prefetchCount, container::setPrefetchCount)
427-
.acceptIfNotNull(this.recoveryInterval, container::setRecoveryInterval)
428-
.acceptIfNotNull(this.shutdownTimeout, container::setShutdownTimeout)
429-
.acceptIfNotNull(this.taskExecutor, container::setTaskExecutor)
430-
.acceptIfNotNull(this.transactionAttribute, container::setTransactionAttribute)
431-
.acceptIfNotNull(this.transactionManager, container::setTransactionManager)
432-
.acceptIfNotNull(this.missingQueuesFatal, container::setMissingQueuesFatal);
434+
.acceptIfNotNull(this.errorHandler, container::setErrorHandler)
435+
.acceptIfNotNull(this.exposeListenerChannel, container::setExposeListenerChannel)
436+
.acceptIfNotNull(this.messagePropertiesConverter, container::setMessagePropertiesConverter)
437+
.acceptIfNotNull(this.phase, container::setPhase)
438+
.acceptIfNotNull(this.prefetchCount, container::setPrefetchCount)
439+
.acceptIfNotNull(this.recoveryInterval, container::setRecoveryInterval)
440+
.acceptIfNotNull(this.shutdownTimeout, container::setShutdownTimeout)
441+
.acceptIfNotNull(this.taskExecutor, container::setTaskExecutor)
442+
.acceptIfNotNull(this.transactionAttribute, container::setTransactionAttribute)
443+
.acceptIfNotNull(this.transactionManager, container::setTransactionManager)
444+
.acceptIfNotNull(this.missingQueuesFatal, container::setMissingQueuesFatal);
433445
return container;
434446
}
435447

spring-integration-amqp/src/main/java/org/springframework/integration/amqp/dsl/AmqpMessageChannelSpec.java

+17-4
Original file line numberDiff line numberDiff line change
@@ -39,11 +39,12 @@
3939
*
4040
* @author Artem Bilan
4141
* @author Gary Russell
42+
*
4243
* @since 5.0
4344
*/
4445
public class AmqpMessageChannelSpec<S extends AmqpMessageChannelSpec<S>> extends AmqpPollableMessageChannelSpec<S> {
4546

46-
private final List<Advice> adviceChain = new LinkedList<Advice>();
47+
private final List<Advice> adviceChain = new LinkedList<>();
4748

4849
AmqpMessageChannelSpec(ConnectionFactory connectionFactory) {
4950
super(new AmqpChannelFactoryBean(true), connectionFactory);
@@ -205,16 +206,28 @@ public S transactionManager(PlatformTransactionManager transactionManager) {
205206
* Configure the txSize.
206207
* @param txSize the txSize.
207208
* @return the spec.
208-
* @see org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#setTxSize(int)
209+
* @deprecated since 5.2 in favor of {@link #batchSize(int)}
209210
*/
211+
@Deprecated
210212
public S txSize(int txSize) {
211-
this.amqpChannelFactoryBean.setTxSize(txSize);
213+
return batchSize(txSize);
214+
}
215+
216+
/**
217+
* Configure the batch size.
218+
* @param batchSize the batchSize.
219+
* @return the spec.
220+
* @since 5.2
221+
* @see org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer#setBatchSize(int)
222+
*/
223+
public S batchSize(int batchSize) {
224+
this.amqpChannelFactoryBean.setBatchSize(batchSize);
212225
return _this();
213226
}
214227

215228
@Override
216229
protected AbstractAmqpChannel doGet() {
217-
this.amqpChannelFactoryBean.setAdviceChain(this.adviceChain.toArray(new Advice[this.adviceChain.size()]));
230+
this.amqpChannelFactoryBean.setAdviceChain(this.adviceChain.toArray(new Advice[0]));
218231
return super.doGet();
219232
}
220233

0 commit comments

Comments
 (0)