Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@RabbitListener use SimpleAsyncTaskExecutor crete the same name thread,when has many SimpleMessageListenerContainer #905

Closed
xxw1754352621 opened this issue Feb 15, 2019 · 3 comments
Assignees
Milestone

Comments

@xxw1754352621
Copy link

xxw1754352621 commented Feb 15, 2019

Affects Version(s): 2.1.3.RELEASE


Question

when we use the @RabbitListener ,for create the container,there is a question 。The All Thread name would be same。Because they use the below code to create。

RabbitListenerContainerFactory#createListenerContainer(org.springframework.amqp.rabbit.listener.RabbitListenerEndpoint)
image

But actually,we want the different SimpleAsyncTaskExecutor's thread has its own name,like the below picture. They always name like 'SimpleAsyncTaskExecutor-1',but we want 'specialSimpleAsyncTaskExecutor-1''

image

Just you use the @bean to create the SimpleMessageListenerContainer ,the SimpleAsyncTaskExecutor's thread can be name the thread with different name。
we want to name is different ,because we want to analyze the dump file。

@garyrussell
Copy link
Contributor

You currently need to create a different container factory for each listener and inject a different TaskExecutor into each one. Spring names the threads using the executor's bean name by default.

I will treat this issue as a new feature request to add an executor property to @RabbitListener to enable different TaskExecutor beans to be injected into containers so they can share the same factory.

@garyrussell garyrussell added this to the 2.2.0.M1 milestone Feb 15, 2019
@garyrussell
Copy link
Contributor

I have found a much simpler way to fix this.

@garyrussell garyrussell self-assigned this Feb 15, 2019
garyrussell added a commit to garyrussell/spring-amqp that referenced this issue Feb 15, 2019
garyrussell added a commit to garyrussell/spring-amqp that referenced this issue Feb 15, 2019
garyrussell added a commit to garyrussell/spring-amqp that referenced this issue Feb 15, 2019
Fixes spring-projects#905

Default container thread names are based on the bean name. `@RabbitListener`
containers are not beans; use `getListenerId()` instead (which falls back
to bean name for other containers).

**cherry-pick to all supported branches**
@garyrussell
Copy link
Contributor

In the mean time; here is a simple work-around...

spring.rabbitmq.listener.simple.auto-startup=false
@SpringBootApplication
public class Rgh905Application {

	public static void main(String[] args) {
		SpringApplication.run(Rgh905Application.class, args);
	}

	@RabbitListener(id = "listen1", queues = "foo")
	public void listen(String in) {
		System.out.println(in + ":" + Thread.currentThread().getName());
	}

	@Bean
	public ApplicationRunner runner1(RabbitTemplate template) {
		return args -> template.convertAndSend("foo", "bar");
	}

	@Bean
	public ApplicationRunner runner2(RabbitListenerEndpointRegistry registry) {
		return args -> {
			registry.getListenerContainers().stream()
				.map(c -> (AbstractMessageListenerContainer) c)
				.forEach(c -> {
					c.setTaskExecutor(new SimpleAsyncTaskExecutor(c.getListenerId() + "-"));
				});
			registry.start();
		};
	}

}

result

bar:listen1-1

artembilan pushed a commit that referenced this issue Feb 17, 2019
artembilan pushed a commit that referenced this issue Feb 17, 2019
Fixes #905

Default container thread names are based on the bean name. `@RabbitListener`
containers are not beans; use `getListenerId()` instead (which falls back
to bean name for other containers).

**cherry-pick to all supported branches**
artembilan pushed a commit that referenced this issue Feb 17, 2019
Fixes #905

Default container thread names are based on the bean name. `@RabbitListener`
containers are not beans; use `getListenerId()` instead (which falls back
to bean name for other containers).

**cherry-pick to all supported branches**

(cherry picked from commit 5f4c60a)
artembilan pushed a commit that referenced this issue Feb 17, 2019
Fixes #905

Default container thread names are based on the bean name. `@RabbitListener`
containers are not beans; use `getListenerId()` instead (which falls back
to bean name for other containers).

**cherry-pick to all supported branches**

(cherry picked from commit 5f4c60a)

# Conflicts:
#	spring-rabbit/src/test/java/org/springframework/amqp/rabbit/annotation/EnableRabbitIntegrationTests.java
artembilan pushed a commit that referenced this issue Feb 18, 2019
Fixes #905

Default container thread names are based on the bean name. `@RabbitListener`
containers are not beans; use `getListenerId()` instead (which falls back
to bean name for other containers).

**cherry-pick to all supported branches**

(cherry picked from commit 5f4c60a)

# Conflicts:
#	spring-rabbit/src/test/java/org/springframework/amqp/rabbit/annotation/EnableRabbitIntegrationTests.java

# Conflicts:
#	spring-rabbit/src/main/java/org/springframework/amqp/rabbit/listener/AbstractMessageListenerContainer.java
artembilan added a commit that referenced this issue Feb 18, 2019
Fixes #905

Default container thread names are based on the bean name. `@RabbitListener`
containers are not beans; use `getListenerId()` instead (which falls back
to bean name for other containers).

**cherry-pick to all supported branches**

(cherry picked from commit 5f4c60a)
garyrussell added a commit that referenced this issue Feb 18, 2019
- resolve new possible null pointer dereference
- if test are run on a host that resolves localhost to an IPv6
  address, the behavior of bad credentials and invalid vHost
  tests changes
garyrussell added a commit that referenced this issue Feb 18, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants