0
votes

Using SimpleMessageListenerContainer.start() to start listener threads in client machine to listen for messages from RabbitMQ. All listener threads have name as SimpleAsyncTaskExecutor-1 . Is there a way user can provide/set name of listener-thread (to help troubleshooting issue by seeing threadname and relating part of code that this thread belongs to)

Following is summary of my current implementation ---

I am using xml file with following tags to define connection factory, queue, binding etc. For example, XML tags used are Rabbit:queues , Rabbit:queue-arguments , Rabbit:direct-exchange , Rabbit:topic-exchange, Rabbit:bindings, rabbit:binding , Rabbit:Admin (with ConnectionFactory)

Following is code snippet to start listener---

SimpleMessageListenerContainer container= new SimpleMessageListenerContainer();
container.setConnectionFactory(messagingTopology.getConnectionFactory());
container.setQueueNames(new String[] { messagingTopology.getQueue().getName() });
MessageListenerAdapter adapter = new MessageListenerAdapter(listener); 
container.setMessageListener(adapter); 
container.start();
1
One workaround is to set threadname (only once by checking some state variable) in MessagePostProcessor.postProcessMessage that gets called just before onMessage. Downside is that name will be set only when first message will be received... Note: We are using xml with following tags to define connection factory, queue, binding etc. Rabbit:Queues , Rabbit:queue-arguments , • Rabbit:DIRECTExchange , Rabbit:TOPICExchange, Rabbit:binding , Rabbit:Admin [[[ ConnectionFactory]]]gosachin1
Following is sample code that I am currently using to start listener. SimpleMessageListenerContainer container= new SimpleMessageListenerContainer(); container.setConnectionFactory(messagingTopology.getConnectionFactory()); container.setQueueNames(new String[] { messagingTopology.getQueue().getName() }); container.setMessageListener(adapter); container.setAfterReceivePostProcessors(loggingMessagingPostProcessor); container.start(); container.start(); Considering above code how thread name can be set in listener while starting listener?gosachin1
Don't put code in comments; it doesn't render well; it's better to edit the question.Gary Russell

1 Answers

0
votes

Set the taskExecutor (task-executor in XML) property on the listener container. The thread name is based on the executor's bean name so use a different one for each container.