|
1 | 1 | /* |
2 | | - * Copyright 2015-2023 the original author or authors. |
| 2 | + * Copyright 2015-2024 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
|
24 | 24 | import org.springframework.amqp.rabbit.connection.AbstractConnectionFactory; |
25 | 25 | import org.springframework.amqp.rabbit.connection.ConnectionFactory; |
26 | 26 | import org.springframework.amqp.rabbit.connection.ConnectionNameStrategy; |
| 27 | +import org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer; |
27 | 28 | import org.springframework.amqp.rabbit.listener.MessageListenerContainer; |
28 | 29 | import org.springframework.amqp.support.postprocessor.DelegatingDecompressingPostProcessor; |
29 | 30 | import org.springframework.amqp.support.postprocessor.GZipPostProcessor; |
30 | 31 | import org.springframework.beans.factory.annotation.Autowired; |
31 | 32 | import org.springframework.boot.autoconfigure.amqp.RabbitProperties; |
| 33 | +import org.springframework.boot.autoconfigure.condition.ConditionalOnThreading; |
32 | 34 | import org.springframework.boot.autoconfigure.context.PropertyPlaceholderAutoConfiguration; |
| 35 | +import org.springframework.boot.autoconfigure.thread.Threading; |
33 | 36 | import org.springframework.boot.context.properties.EnableConfigurationProperties; |
34 | 37 | import org.springframework.cloud.stream.binder.rabbit.RabbitMessageChannelBinder; |
35 | 38 | import org.springframework.cloud.stream.binder.rabbit.properties.RabbitBinderConfigurationProperties; |
|
42 | 45 | import org.springframework.context.annotation.Bean; |
43 | 46 | import org.springframework.context.annotation.Configuration; |
44 | 47 | import org.springframework.context.annotation.Import; |
| 48 | +import org.springframework.core.task.VirtualThreadTaskExecutor; |
45 | 49 | import org.springframework.integration.amqp.inbound.AmqpInboundChannelAdapter; |
46 | 50 | import org.springframework.integration.amqp.inbound.AmqpMessageSource; |
47 | 51 | import org.springframework.lang.Nullable; |
@@ -150,4 +154,15 @@ MessagePostProcessor gZipPostProcessor() { |
150 | 154 | RabbitExchangeQueueProvisioner provisioningProvider(List<DeclarableCustomizer> customizers) { |
151 | 155 | return new RabbitExchangeQueueProvisioner(this.rabbitConnectionFactory, customizers); |
152 | 156 | } |
| 157 | + |
| 158 | + @Bean |
| 159 | + @ConditionalOnThreading(Threading.VIRTUAL) |
| 160 | + ListenerContainerCustomizer<MessageListenerContainer> listenerContainerVirtualThreadExecutorCustomizer() { |
| 161 | + return (container, destinationName, group) -> { |
| 162 | + if (container instanceof AbstractMessageListenerContainer listenerContainer) { |
| 163 | + listenerContainer.setTaskExecutor(new VirtualThreadTaskExecutor(destinationName + "-")); |
| 164 | + } |
| 165 | + }; |
| 166 | + } |
| 167 | + |
153 | 168 | } |
0 commit comments