How to close Rabbitmq Connection before Spring context - spring

Spring - Close RabbitMQ Consumer connection without closing spring application
We have a requirement we want to close the rabbitmq connection, wait for few minutes before cleaning up other resources and then closing the spring application. We have a buffer of 6 minutes to clean up the other resources. However, during this time, the rabbitmq connection is auto recreated.
We are creating the connections as follows...
#Configuration
public class RabbitMQSubscribersHolder extends BaseRabbitMQConfig {
private static final Logger LOGGER = LoggerFactory.getLogger(RabbitMQSubscribersHolder.class);
private ConcurrentMap<String, SimpleMessageListenerContainer> containers = new ConcurrentHashMap();
public RabbitMQSubscribersHolder() {
}
public void addSubscriber(String mqAlias, MessageListener receiver) {
ConnectionFactory connectionFactory = this.connectionFactory(mqAlias);
RabbitAdmin admin = null;
try {
admin = new RabbitAdmin(connectionFactory);
AbstractExchange exchange = this.exchange(mqAlias);
admin.declareExchange(exchange);
Queue queue = null;
if (!StringUtils.isEmpty(this.getMqQueueNameForQueueAlias(mqAlias))) {
queue = this.queue(mqAlias);
admin.declareQueue(queue);
} else {
queue = admin.declareQueue();
}
admin.declareBinding(this.binding(mqAlias, queue, exchange));
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
container.setQueueNames(new String[]{queue.getName()});
container.setMessageListener(this.listenerAdapter(receiver));
container.setRabbitAdmin(admin);
container.start();
this.containers.put(mqAlias, container);
} catch (Exception var8) {
LOGGER.error(var8.getMessage(), var8);
}
}
MessageListenerAdapter listenerAdapter(MessageListener receiver) {
return new MessageListenerAdapter(receiver, "onMessage");
}
public SimpleMessageListenerContainer getContainer(String mqAlias) {
return (SimpleMessageListenerContainer)this.containers.get(mqAlias);
}
This is our destroy method
public void destroy() {
Iterator var1 = this.aliasToConnectionFactory.entrySet().iterator();
while(var1.hasNext()) {
Map.Entry<String, CachingConnectionFactory> entry = (Map.Entry)var1.next();
try {
((CachingConnectionFactory)entry.getValue()).destroy();
LOGGER.info("RabbitMQ caching connection factory closed for alias: {}", entry.getKey());
} catch (Exception var4) {
LOGGER.error("RabbitMQ caching connection destroy operation failed for alias: {} due to {}", entry.getKey(), StringUtils.getStackTrace(var4));
}
}
}
It seems the connection is re-created automatically as soon as it is destroyed (verified from Rabbit UI). Here are the logs:
2022-07-11 19:42:55.334 INFO 35761 --- [ Thread-11] c.g.f.f.r.GracefulShutdownRabbitMQ : RabbitMQ caching connection factory closed for alias: preMatchFreeze
2022-07-11 19:42:55.395 INFO 35761 --- [cTaskExecutor-1] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer: tags=[{amq.ctag-tSAgXuPdMnLd9q79ryBWGg=fury_pre_matchfreeze_queue}], channel=Cached Rabbit Channel: AMQChannel(amqp://gwportal#10.24.128.76:5672/,1), conn: Proxy#205b73d8 Shared Rabbit Connection: null, acknowledgeMode=AUTO local queue size=0
2022-07-11 19:42:55.405 INFO 35761 --- [ Thread-11] c.g.f.f.r.GracefulShutdownRabbitMQ : RabbitMQ caching connection factory closed for alias: parentMatchFreezeEds
2022-07-11 19:42:55.447 INFO 35761 --- [ Thread-11] c.g.f.f.r.GracefulShutdownRabbitMQ : RabbitMQ caching connection factory closed for alias: fantasy_matchFreeze
2022-07-11 19:42:55.489 INFO 35761 --- [ Thread-11] c.g.f.f.r.GracefulShutdownRabbitMQ : RabbitMQ caching connection factory closed for alias: parentMatchFreezeCore
2022-07-11 19:42:55.489 INFO 35761 --- [ Thread-11] c.g.f.fury.GracefulShutdownHandler : Waiting before starting graceful shutdown
2022-07-11 19:42:55.794 INFO 35761 --- [cTaskExecutor-1] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer: tags=[{amq.ctag-sK8_FY4PtHW52HXkQV3S_w=fury_match_freeze_queue}], channel=Cached Rabbit Channel: AMQChannel(amqp://gwportal#10.24.128.76:5672/,1), conn: Proxy#4bc9389 Shared Rabbit Connection: null, acknowledgeMode=AUTO local queue size=0
2022-07-11 19:42:56.046 INFO 35761 --- [cTaskExecutor-2] o.s.a.r.c.CachingConnectionFactory : Created new connection: SimpleConnection#3828e912 [delegate=amqp://gwportal#10.24.128.76:5672/, localPort= 58170]
2022-07-11 19:42:56.098 INFO 35761 --- [cTaskExecutor-1] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer: tags=[{amq.ctag-KyvnWaqZco9NRTessjupJQ=fantasy_parent_match_freeze_queue}], channel=Cached Rabbit Channel: AMQChannel(amqp://gwportal#10.24.128.76:5672/,1), conn: Proxy#17d45cfb Shared Rabbit Connection: null, acknowledgeMode=AUTO local queue size=0
2022-07-11 19:43:13.127 INFO 35761 --- [cTaskExecutor-2] o.s.a.r.c.CachingConnectionFactory : Created new connection: SimpleConnection#4c3cefad [delegate=amqp://gwportal#10.24.141.77:5672/, localPort= 58182]
2022-07-11 19:43:16.849 INFO 35761 --- [cTaskExecutor-2] o.s.a.r.c.CachingConnectionFactory : Created new connection: SimpleConnection#801eaf8 [delegate=amqp://gwportal#10.24.141.77:5672/, localPort= 58185]

You need to stop the message listener container(s) to prevent them from trying to reconnect.

Related

Setup of JMS message listener invoker failed for destination 'TESTQUEUE' - trying to recover. Cause: null

My application run well in my local machine and i am able to connect to IBM MQ and poll message. I am facing below issue in polling after i deploy my application on open shift.
Error:
2022-05-03 02:02:24.418 DEBUG 7 --- [ main] o.s.j.c.CachingConnectionFactory : Established shared JMS Connection: com.ibm.mq.jms.MQConnection#397a10df
2022-05-03 02:02:24.422 DEBUG 7 --- [ main] o.s.j.l.DefaultMessageListenerContainer : Established shared JMS Connection
2022-05-03 02:02:24.423 DEBUG 7 --- [ main] o.s.j.l.DefaultMessageListenerContainer : Resumed paused task: org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker#55c46ec1
2022-05-03 02:02:24.623 INFO 7 --- [ main] c.c.com.poc.ibmmq.DemoApplication : Started DemoApplication in 84.7 seconds (JVM running for 103.063)
2022-05-03 02:02:30.922 WARN 7 --- [enerContainer-1] o.s.j.l.DefaultMessageListenerContainer : Setup of JMS message listener invoker failed for destination 'TESTQUEUE' - trying to recover. Cause: null
java.lang.NullPointerException: null
at com.ibm.mq.jms.MQSession.getTransacted(MQSession.java:876) ~[com.ibm.mq.allclient-9.1.5.0.jar!/:9.1.5.0 - p915-L200316]
at com.ibm.mq.jms.MQSession.<init>(MQSession.java:262) ~[com.ibm.mq.allclient-9.1.5.0.jar!/:9.1.5.0 - p915-L200316]
at com.ibm.mq.jms.MQConnection.createSession(MQConnection.java:336) ~[com.ibm.mq.allclient-9.1.5.0.jar!/:9.1.5.0 - p915-L200316]
at org.springframework.jms.connection.SingleConnectionFactory.createSession(SingleConnectionFactory.java:482) ~[spring-jms-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
at org.springframework.jms.connection.CachingConnectionFactory.getSession(CachingConnectionFactory.java:233) ~[spring-jms-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
at org.springframework.jms.connection.SingleConnectionFactory$SharedConnectionInvocationHandler.invoke(SingleConnectionFactory.java:649) ~[spring-jms-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
at com.sun.proxy.$Proxy148.createSession(Unknown Source) ~[na:na]
at org.springframework.jms.support.JmsAccessor.createSession(JmsAccessor.java:208) ~[spring-jms-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
at org.springframework.jms.listener.DefaultMessageListenerContainer.access$1500(DefaultMessageListenerContainer.java:126) ~[spring-jms-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.initResourcesIfNecessary(DefaultMessageListenerContainer.java:1213) ~[spring-jms-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.invokeListener(DefaultMessageListenerContainer.java:1188) ~[spring-jms-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.executeOngoingLoop(DefaultMessageListenerContainer.java:1179) ~[spring-jms-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
at org.springframework.jms.listener.DefaultMessageListenerContainer$AsyncMessageListenerInvoker.run(DefaultMessageListenerContainer.java:1076) ~[spring-jms-5.2.8.RELEASE.jar!/:5.2.8.RELEASE]
at java.base/java.lang.Thread.run(Unknown Source) ~[na:na]
Code:
My configuration:
#Bean
public JmsListenerContainerFactory<?> myFactory(ConnectionFactory connectionFactory, DefaultJmsListenerContainerFactoryConfigurer configurer) {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
setSSLProperties();
configurer.configure(factory,connectionFactory);
return factory;
}
Receiver:
#JmsListener(destination = "${response.queue}", containerFactory = "myFactory")
public void receiveMessage(JmsMessage test) throws JMSException {
logger.info("Response Sent {}", test.toString());
}

RemoteProxyFailureException: No reply received - perhaps a timeout in the template?" error when calling method from other module

I have two modules client and server. The client has controllers, which call methods in services on the server. When I try to call service methods I get a listener exception.
I have Spring configuration for RPC call, migrated from the old project.
Server-side:
I have a proxy factory:
#Component
public class AmqpProxyFactory {
private final ConnectionFactory connectionFactory;
private final String exchange;
private final Integer timeout;
private List<SimpleMessageListenerContainer> listenersRegistry;
private final MessageConverter clientConverter;
private final MessageConverter serverConverter;
#Autowired
public AmqpProxyFactory(ConnectionFactory connectionFactory,
#Value("${rabbit.marsFacade.exchange}") String exchange,
#Value("${rabbit.marsFacade.timeout}") Integer timeout,
#Qualifier("clientSecurityContextMessageConverter")MessageConverter clientConverter,
#Qualifier("serverSecurityContextMessageConverter")MessageConverter serverConverter) {
this.connectionFactory = connectionFactory;
this.exchange = exchange;
this.timeout = timeout;
this.clientConverter = clientConverter;
this.serverConverter = serverConverter;
listenersRegistry = new ArrayList<>();
}
private RabbitTemplate createTemplate(String route) {
RabbitTemplate rabbitTemplate = new RabbitTemplate(connectionFactory);
rabbitTemplate.setRoutingKey(route);
rabbitTemplate.setExchange(exchange);
rabbitTemplate.setReplyTimeout(timeout);
rabbitTemplate.setMessageConverter(clientConverter);
// rabbitTemplate.setUseDirectReplyToContainer(false);
return rabbitTemplate;
}
public <T> T createClient(String route, Class<T> serviceInterface) throws Exception {
AmqpProxyFactoryBean proxy = new AmqpProxyFactoryBean();
proxy.setAmqpTemplate(createTemplate(route));
proxy.setServiceInterface(serviceInterface);
proxy.afterPropertiesSet();
return serviceInterface.cast(proxy.getObject());
}
private AmqpInvokerServiceExporter createExporter(Class<?> serviceInterface, Object service, String route) {
AmqpInvokerServiceExporter result = new AmqpInvokerServiceExporter();
result.setServiceInterface(serviceInterface);
result.setService(service);
result.setAmqpTemplate(createTemplate(route));
result.setMessageConverter(serverConverter);
return result;
}
public SimpleMessageListenerContainer createListenerContainer(Class<?> serviceInterface, Object service, String route, String queueName, Integer concurrency) {
SimpleMessageListenerContainer listenerContainer = new SimpleMessageListenerContainer();
listenerContainer.setQueues(new Queue(
queueName,
true,
false,
false,
ImmutableMap.<String, Object>builder()
.put("x-message-ttl", timeout)
.build()
));
listenerContainer.setMaxConcurrentConsumers(concurrency);
listenerContainer.setMessageListener(createExporter(serviceInterface, service, route));
listenerContainer.setConnectionFactory(connectionFactory);
listenersRegistry.add(listenerContainer);
return listenerContainer;
}
public List<SimpleMessageListenerContainer> getListenersRegistry() {
return listenersRegistry;
}
Here I create client
#Configuration
public class AmqpClientsConfig {
#Lazy
#Bean(name = "testRebbitService")
public TestRabbitService testRebbitService(AmqpProxyFactory amqpProxyFactory) throws Exception {
return amqpProxyFactory.createClient(TestRabbitServiceRabbitConfig.ROUTE_KEY, TestRabbitService.class);
}
Configuration for every using service:
#Configuration
public class TestRabbitServiceRabbitConfig {
public static final String QUEUE_NAME = "com.xxx.yyy.service.queue.testRabbitService";
public static final String ROUTE_KEY = "com.xxx.yyy.service.testRabbitService";
#Autowired
RabbitCommonConfig commonConfig;
#Bean
public Queue testRabbitServiceRabbitQueue() {
return commonConfig.buildServiceQueue(QUEUE_NAME);
}
#Bean
public Binding userServiceBinding() {
return BindingBuilder.bind(testRabbitServiceRabbitQueue()).to(commonConfig.directExchange()).with(ROUTE_KEY);
}
Rabbit common configuration class:
package com.xxx.yyy.rabbit.common;
import com.google.common.collect.ImmutableMap;
import org.springframework.amqp.core.AmqpAdmin;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.amqp.rabbit.connection.CachingConnectionFactory;
import org.springframework.amqp.rabbit.connection.ConnectionFactory;
import org.springframework.amqp.rabbit.core.RabbitAdmin;
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.jmx.export.MBeanExporter;
#Configuration
#ComponentScan(basePackages = {
"com.xxx.yyy.rabbit",
"com.xxx.yyy.components",
"com.xxx.yyy.rabbit.common"
})
public class RabbitCommonConfig {
#Autowired
private ApplicationContext context;
#Value("${rabbit.host}")
private String rabbitHost;
#Value("${rabbit.password}")
private String rabbitPassword;
#Value("${rabbit.user}")
private String rabbitUserName;
#Value("${rabbit.port}")
private Integer rabbitPort = 5672;
#Value("${rabbit.marsFacade.exchange}")
private String exchangeName;
#Value("${rabbit.marsFacade.timeout}")
private Integer queueTimeout = 60000;
public Queue buildServiceQueue(String queueName) {
return new Queue(queueName, true, false, false, ImmutableMap.<String, Object>builder().put("x-message-ttl", queueTimeout).build());
}
#Bean
public ConnectionFactory rabbitConnectionFactory() {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory(rabbitHost);
connectionFactory.setUsername(rabbitUserName);
connectionFactory.setPassword(rabbitPassword);
connectionFactory.setPort(rabbitPort);
try {
MBeanExporter mbeanExporter = context.getBean(MBeanExporter.class);
mbeanExporter.addExcludedBean("rabbitConnectionFactory");
} catch (NoSuchBeanDefinitionException ex) {
// No exporter. Exclusion is unnecessary
}
return connectionFactory;
}
#Bean
public AmqpAdmin amqpAdmin(ConnectionFactory rabbitConnectionFactory) {
return new RabbitAdmin(rabbitConnectionFactory);
}
#Bean
public DirectExchange directExchange() {
return new DirectExchange(exchangeName);
}
}
Service class:
#Service
public class TestRabbitServiceImpl implements TestRabbitService{
#Override
public void testRemoteMethod(String arg){
System.out.println(arg);
}
}
Configuration for listener:
#Configuration
#ComponentScan(basePackages = {"com.xxx.yyy.rabbit.common"})
#RequiredArgsConstructorpublic
class RabbitListenerConfiguration {
private final TestRabbitService testRebbitService;
#Value("${rabbit.marsFacade.concurrency}")
private Integer concurrency = 100;
#Bean
public SimpleMessageListenerContainer testRabbitServiceListenerContainer(AmqpProxyFactory amqpProxyFactory) {
return amqpProxyFactory.createListenerContainer(TestRabbitService.class, testRebbitService, TestRabbitServiceRabbitConfig.ROUTE_KEY, TestRabbitServiceRabbitConfig.QUEUE_NAME, concurrency);
}
}
Client side(module):
Rabbit common configuration class:
Configuration
#RequiredArgsConstructor
public class RabbitCommonConfig {
#Autowired
private ApplicationContext context;
#Value("${rabbit.host}")
private String rabbitHost;
#Value("${rabbit.password}")
private String rabbitPassword;
#Value("${rabbit.user}")
private String rabbitUserName;
#Value("${rabbit.port}")
private Integer rabbitPort = 5672;
#Value("${rabbit.marsFacade.exchange}")
private String exchangeName;
#Value("${rabbit.marsFacade.timeout}")
private Integer queueTimeout = 60000;
#Bean
public ConnectionFactory rabbitConnectionFactory() {
CachingConnectionFactory connectionFactory = new CachingConnectionFactory(rabbitHost);
connectionFactory.setUsername(rabbitUserName);
connectionFactory.setPassword(rabbitPassword);
connectionFactory.setPort(rabbitPort);
try {
MBeanExporter mbeanExporter = context.getBean(MBeanExporter.class);
mbeanExporter.addExcludedBean("rabbitConnectionFactory");
} catch (NoSuchBeanDefinitionException ex) {
// No exporter. Exclusion is unnecessary
}
return connectionFactory;
}
#Bean
public AmqpAdmin amqpAdmin(ConnectionFactory rabbitConnectionFactory) {
return new RabbitAdmin(rabbitConnectionFactory);
}
#Bean
public DirectExchange directExchange() {
return new DirectExchange(exchangeName);
}
#Bean(name = "clientSecurityContextMessageConverter")
public SecurityContextMessageConverter clientConverter() {
return new SecurityContextMessageConverter(true, false);
}
#Bean(name = "serverSecurityContextMessageConverter")
public SecurityContextMessageConverter serverConverter() {
return new SecurityContextMessageConverter(false, true);
}
}
The application property file has the same settings on the client and server sides:
rabbit:
marsFacade:
timeout: 60000
concurrency: 100
queueLength: 10000
exchange: com.xxx.yyy.remoting.marsFacade.exchange
host: localhost
port: 5672
user: guest
password: guest
When I try to call the remote method from the other module:
public class BaseController {
private final TestRabbitService testRabbitService;
#GetMapping
public String ping() {
testRabbitService.testRemoteMethod("hello");
return "Hello!";
}
Debug log trace on the server side when I start application:
DEBUG [core,,] 2802316 --- [ main] o.s.amqp.rabbit.core.RabbitAdmin : Binding destination [com.xxx.yyy.service.queue.testRabbitService (QUEUE)] to exchange [com.xxx.yyy.remoting.marsFacade.exchange] with routing key [com.xxx.yyy.service.testRabbitService]
...
DEBUG [core,,] 2802316 --- [enerContainer-1] o.s.a.r.listener.BlockingQueueConsumer : Started on queue 'com.xxx.yyy.service.queue.testRabbitService' with tag amq.ctag-nzefWR53naCaUNDBQZ1AWg: Consumer#71c6bf20: tags=[[amq.ctag-nzefWR53naCaUNDBQZ1AWg]], channel=Cached Rabbit Channel: AMQChannel(amqp://guest#127.0.0.1:5672/,34), conn: Proxy#161722eb Shared Rabbit Connection: SimpleConnection#70ba6842 [delegate=amqp://guest#127.0.0.1:5672/, localPort= 37370], acknowledgeMode=AUTO local queue size=0
Debug log trace no the client side:
DEBUG [agent,,] 2804522 --- [on(4)-127.0.0.1] o.s.amqp.rabbit.core.RabbitAdmin : Binding destination [com.xxx.yyy.service.queue.testRabbitService (QUEUE)] to exchange [com.xxx.yyy.remoting.marsFacade.exchange] with routing key [com.xxx.yyy.service.testRabbitService]
When I try to call the method on the BaseBontroller, after the delay time i get "Listener threw exception" on the client side. And "No reply received from 'testRemoteMethod' with arguments '[hello]' - perhaps a timeout in the template?" on the server side.
Error stack on client:
2022-04-07 20:20:21.008 DEBUG [agent,ed823cf4ed1fc76e,ed823cf4ed1fc76e] 2804522 --- [nio-8080-exec-1] s.w.s.m.m.a.RequestMappingHandlerMapping : Mapped to com.xxx.yyy.rest.front.controller.BaseController#ping()
2022-04-07T17:20:21 [http-nio-8080-exec-1] DEBUG o.s.w.s.m.m.a.RequestMappingHandlerMapping - Mapped to com.xxx.yyy.rest.front.controller.BaseController#ping()
2022-04-07 20:20:33.296 DEBUG [agent,ed823cf4ed1fc76e,ed823cf4ed1fc76e] 2804522 --- [nio-8080-exec-1] o.s.amqp.rabbit.core.RabbitTemplate : Executing callback RabbitTemplate$$Lambda$1623/0x00000008409c2040 on RabbitMQ Channel: Cached Rabbit Channel: AMQChannel(amqp://guest#127.0.0.1:5672/,1), conn: Proxy#551ef755 Shared Rabbit Connection: SimpleConnection#6e552d5e [delegate=amqp://guest#127.0.0.1:5672/, localPort= 37372]
2022-04-07T17:20:33 [http-nio-8080-exec-1] DEBUG o.s.amqp.rabbit.core.RabbitTemplate - Executing callback RabbitTemplate$$Lambda$1623/0x00000008409c2040 on RabbitMQ Channel: Cached Rabbit Channel: AMQChannel(amqp://guest#127.0.0.1:5672/,1), conn: Proxy#551ef755 Shared Rabbit Connection: SimpleConnection#6e552d5e [delegate=amqp://guest#127.0.0.1:5672/, localPort= 37372]
2022-04-07 20:20:33.334 DEBUG [agent,ed823cf4ed1fc76e,ed823cf4ed1fc76e] 2804522 --- [nio-8080-exec-1] o.s.s.c.ThreadPoolTaskScheduler : Initializing ExecutorService
2022-04-07T17:20:33 [http-nio-8080-exec-1] DEBUG o.s.s.c.ThreadPoolTaskScheduler - Initializing ExecutorService
2022-04-07 20:20:33.334 DEBUG [agent,ed823cf4ed1fc76e,ed823cf4ed1fc76e] 2804522 --- [nio-8080-exec-1] .l.DirectReplyToMessageListenerContainer : Starting Rabbit listener container.
2022-04-07T17:20:33 [http-nio-8080-exec-1] DEBUG o.s.a.r.l.DirectReplyToMessageListenerContainer - Starting Rabbit listener container.
2022-04-07 20:20:33.346 INFO [agent,ed823cf4ed1fc76e,ed823cf4ed1fc76e] 2804522 --- [nio-8080-exec-1] .l.DirectReplyToMessageListenerContainer : Container initialized for queues: [amq.rabbitmq.reply-to]
2022-04-07T17:20:33 [http-nio-8080-exec-1] INFO o.s.a.r.l.DirectReplyToMessageListenerContainer - Container initialized for queues: [amq.rabbitmq.reply-to]
2022-04-07 20:20:33.429 INFO [agent,ed823cf4ed1fc76e,ed823cf4ed1fc76e] 2804522 --- [nio-8080-exec-1] .l.DirectReplyToMessageListenerContainer : SimpleConsumer [queue=amq.rabbitmq.reply-to, index=0, consumerTag=amq.ctag-eANKK31VIkaHjWZRT0NAVw identity=4372b241] started
2022-04-07T17:20:33 [http-nio-8080-exec-1] INFO o.s.a.r.l.DirectReplyToMessageListenerContainer - SimpleConsumer [queue=amq.rabbitmq.reply-to, index=0, consumerTag=amq.ctag-eANKK31VIkaHjWZRT0NAVw identity=4372b241] started
2022-04-07 20:20:33.431 DEBUG [agent,,] 2804522 --- [pool-1-thread-3] .l.DirectReplyToMessageListenerContainer : New SimpleConsumer [queue=amq.rabbitmq.reply-to, index=0, consumerTag=amq.ctag-eANKK31VIkaHjWZRT0NAVw identity=4372b241] consumeOk
2022-04-07T17:20:33 [pool-1-thread-3] DEBUG o.s.a.r.l.DirectReplyToMessageListenerContainer - New SimpleConsumer [queue=amq.rabbitmq.reply-to, index=0, consumerTag=amq.ctag-eANKK31VIkaHjWZRT0NAVw identity=4372b241] consumeOk
2022-04-07 20:20:33.442 DEBUG [agent,ed823cf4ed1fc76e,ed823cf4ed1fc76e] 2804522 --- [nio-8080-exec-1] o.s.amqp.rabbit.core.RabbitTemplate : Sending message with tag 1
2022-04-07T17:20:33 [http-nio-8080-exec-1] DEBUG o.s.amqp.rabbit.core.RabbitTemplate - Sending message with tag 1
2022-04-07 20:20:33.445 DEBUG [agent,ed823cf4ed1fc76e,ed823cf4ed1fc76e] 2804522 --- [nio-8080-exec-1] o.s.amqp.rabbit.core.RabbitTemplate : Publishing message [(Body:'[B#5d58fa73(byte[864])' MessageProperties [headers={}, correlationId=1, replyTo=amq.rabbitmq.reply-to, contentType=application/json, contentEncoding=UTF-8, contentLength=864, deliveryMode=PERSISTENT, priority=0, deliveryTag=0])] on exchange [com.xxx.yyy.remoting.marsFacade.exchange], routingKey = [com.xxx.yyy.service.testRabbitService]
2022-04-07T17:20:33 [http-nio-8080-exec-1] DEBUG o.s.amqp.rabbit.core.RabbitTemplate - Publishing message [(Body:'[B#5d58fa73(byte[864])' MessageProperties [headers={}, correlationId=1, replyTo=amq.rabbitmq.reply-to, contentType=application/json, contentEncoding=UTF-8, contentLength=864, deliveryMode=PERSISTENT, priority=0, deliveryTag=0])] on exchange [com.xxx.yyy.remoting.marsFacade.exchange], routingKey = [com.xxx.yyy.service.testRabbitService]
2022-04-07 20:21:33.452 DEBUG [agent,ed823cf4ed1fc76e,ed823cf4ed1fc76e] 2804522 --- [nio-8080-exec-1] o.s.amqp.rabbit.core.RabbitTemplate : Reply: null
2022-04-07T17:21:33 [http-nio-8080-exec-1] DEBUG o.s.amqp.rabbit.core.RabbitTemplate - Reply: null
2022-04-07 20:21:33.457 DEBUG [agent,ed823cf4ed1fc76e,ed823cf4ed1fc76e] 2804522 --- [nio-8080-exec-1] .m.m.a.ExceptionHandlerExceptionResolver : Using #ExceptionHandler com.xxx.yyy.rest.front.controller.RestExceptionHandler#handleServiceException(Exception, HttpServletResponse)
2022-04-07T17:21:33 [http-nio-8080-exec-1] DEBUG o.s.w.s.m.m.a.ExceptionHandlerExceptionResolver - Using #ExceptionHandler com.xxx.yyy.rest.front.controller.RestExceptionHandler#handleServiceException(Exception, HttpServletResponse)
2022-04-07 20:21:33.463 DEBUG [agent,ed823cf4ed1fc76e,ed823cf4ed1fc76e] 2804522 --- [nio-8080-exec-1] w.c.HttpSessionSecurityContextRepository : Did not store anonymous SecurityContext
2022-04-07T17:21:33 [http-nio-8080-exec-1] DEBUG o.s.s.w.c.HttpSessionSecurityContextRepository - Did not store anonymous SecurityContext
2022-04-07 20:21:33.464 DEBUG [agent,ed823cf4ed1fc76e,ed823cf4ed1fc76e] 2804522 --- [nio-8080-exec-1] .m.m.a.ExceptionHandlerExceptionResolver : Resolved [org.springframework.remoting.RemoteProxyFailureException: No reply received from 'testRemoteMethod' with arguments '[hello]' - perhaps a timeout in the template?]
2022-04-07T17:21:33 [http-nio-8080-exec-1] DEBUG o.s.w.s.m.m.a.ExceptionHandlerExceptionResolver - Resolved [org.springframework.remoting.RemoteProxyFailureException: No reply received from 'testRemoteMethod' with arguments '[hello]' - perhaps a timeout in the template?]
...
org.springframework.amqp.rabbit.support.ListenerExecutionFailedException: Listener threw exception
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.wrapToListenerExecutionFailedExceptionIfNeeded(AbstractMessageListenerContainer.java:1779)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:1669)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.actualInvokeListener(AbstractMessageListenerContainer.java:1584)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:1572)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:1563)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:1507)
at org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer$SimpleConsumer.callExecuteListener(DirectMessageListenerContainer.java:1107)
at org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer$SimpleConsumer.handleDelivery(DirectMessageListenerContainer.java:1067)
at com.rabbitmq.client.impl.ConsumerDispatcher$5.run(ConsumerDispatcher.java:149)
at com.rabbitmq.client.impl.ConsumerWorkService$WorkPoolRunnable.run(ConsumerWorkService.java:104)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: org.springframework.amqp.AmqpRejectAndDontRequeueException: Reply received after timeout
at org.springframework.amqp.rabbit.core.RabbitTemplate.onMessage(RabbitTemplate.java:2659)
at org.springframework.amqp.rabbit.listener.DirectReplyToMessageListenerContainer.lambda$setMessageListener$0(DirectReplyToMessageListenerContainer.java:90)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:1665)
... 11 common frames omitted
2022-04-07T17:21:33 [pool-1-thread-4] WARN o.s.a.r.l.ConditionalRejectingErrorHandler - Execution of Rabbit message listener failed.
org.springframework.amqp.rabbit.support.ListenerExecutionFailedException: Listener threw exception
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.wrapToListenerExecutionFailedExceptionIfNeeded(AbstractMessageListenerContainer.java:1779)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:1669)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.actualInvokeListener(AbstractMessageListenerContainer.java:1584)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:1572)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:1563)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:1507)
at org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer$SimpleConsumer.callExecuteListener(DirectMessageListenerContainer.java:1107)
at org.springframework.amqp.rabbit.listener.DirectMessageListenerContainer$SimpleConsumer.handleDelivery(DirectMessageListenerContainer.java:1067)
at com.rabbitmq.client.impl.ConsumerDispatcher$5.run(ConsumerDispatcher.java:149)
at com.rabbitmq.client.impl.ConsumerWorkService$WorkPoolRunnable.run(ConsumerWorkService.java:104)
at java.base/java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128)
at java.base/java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628)
at java.base/java.lang.Thread.run(Thread.java:829)
Caused by: org.springframework.amqp.AmqpRejectAndDontRequeueException: Reply received after timeout
at org.springframework.amqp.rabbit.core.RabbitTemplate.onMessage(RabbitTemplate.java:2659)
at org.springframework.amqp.rabbit.listener.DirectReplyToMessageListenerContainer.lambda$setMessageListener$0(DirectReplyToMessageListenerContainer.java:90)
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:1665)
... 11 common frames omitted
2022-04-07 20:21:33.631 ERROR [agent,,] 2804522 --- [pool-1-thread-4] .l.DirectReplyToMessageListenerContainer : Failed to invoke listener
Error stack on server:
022-04-07 20:21:33.617 DEBUG [core,,] 2802316 --- [enerContainer-1] o.s.amqp.rabbit.core.RabbitTemplate : Executing callback RabbitTemplate$$Lambda$1939/0x0000000840d30040 on RabbitMQ Channel: Cached Rabbit Channel: AMQChannel(amqp://guest#127.0.0.1:5672/,36), conn: Proxy#161722eb Shared Rabbit Connection: SimpleConnection#70ba6842 [delegate=amqp://guest#127.0.0.1:5672/, localPort= 37370]
2022-04-07 20:21:33.618 DEBUG [core,,] 2802316 --- [enerContainer-1] o.s.amqp.rabbit.core.RabbitTemplate : Publishing message [(Body:'[B#6d9b27be(byte[6632])' MessageProperties [headers={}, correlationId=1, contentType=application/json, contentEncoding=UTF-8, contentLength=6632, deliveryMode=PERSISTENT, priority=0, deliveryTag=0])] on exchange [], routingKey = [amq.rabbitmq.reply-to.g1h2AA5yZXBseUAxNjEwNTI1MwAALWAAAAAEYkq0OA==.RB6LgnVMwPiBd8Hvvye0dg==]
2022-04-07 20:21:33.621 DEBUG [core,,] 2802316 --- [enerContainer-1] o.s.a.r.listener.BlockingQueueConsumer : Received message: (Body:'[B#144dbfd6(byte[833])' MessageProperties [headers={}, correlationId=1, replyTo=amq.rabbitmq.reply-to.g1h2AA5yZXBseUAxNjEwNTI1MwAAK8gAAAAEYkq0OA==.OJmY9VwG2ROnH9tN5z0Mvw==, contentType=application/json, contentEncoding=UTF-8, contentLength=0, receivedDeliveryMode=PERSISTENT, priority=0, redelivered=false, receivedExchange=com.xxx.yyy.remoting.marsFacade.exchange, receivedRoutingKey=com.xxx.yyy.service.testRabbitService, deliveryTag=2, consumerTag=amq.ctag-nzefWR53naCaUNDBQZ1AWg, consumerQueue=com.xxx.yyy.service.queue.testRabbitService])
2022-04-07 20:21:33.625 DEBUG [core,,] 2802316 --- [enerContainer-1] o.s.amqp.rabbit.core.RabbitTemplate : Sending message with tag 2
2022-04-07 20:21:33.625 DEBUG [core,,] 2802316 --- [enerContainer-1] o.s.amqp.rabbit.core.RabbitTemplate : Publishing message [(Body:'[B#77a86b39(byte[833])' MessageProperties [headers={}, correlationId=2, replyTo=amq.rabbitmq.reply-to, contentType=application/json, contentEncoding=UTF-8, contentLength=833, deliveryMode=PERSISTENT, priority=0, deliveryTag=0])] on exchange [com.xxx.yyy.remoting.marsFacade.exchange], routingKey = [com.xxx.yyy.service.testRabbitService]
2022-04-07 20:21:33.627 DEBUG [core,,] 2802316 --- [pool-1-thread-8] o.s.a.r.listener.BlockingQueueConsumer : Storing delivery for consumerTag: 'amq.ctag-nzefWR53naCaUNDBQZ1AWg' with deliveryTag: '3' in Consumer#71c6bf20: tags=[[amq.ctag-nzefWR53naCaUNDBQZ1AWg]], channel=Cached Rabbit Channel: AMQChannel(amqp://guest#127.0.0.1:5672/,34), conn: Proxy#161722eb Shared Rabbit Connection: SimpleConnection#70ba6842 [delegate=amqp://guest#127.0.0.1:5672/, localPort= 37370], acknowledgeMode=AUTO local queue size=0
2022-04-07 20:22:33.626 DEBUG [core,,] 2802316 --- [enerContainer-1] o.s.amqp.rabbit.core.RabbitTemplate : Reply: null
2022-04-07 20:22:33.627 DEBUG [core,,] 2802316 --- [enerContainer-1] o.s.a.r.s.AmqpInvokerServiceExporter : Target method failed for RemoteInvocation: method name 'testRemoteMethod'; parameter types [java.lang.String]
org.springframework.remoting.RemoteProxyFailureException: No reply received from 'testRemoteMethod' with arguments '[hello]' - perhaps a timeout in the template?
at org.springframework.amqp.remoting.client.AmqpClientInterceptor.invoke(AmqpClientInterceptor.java:69) ~[spring-amqp-2.4.1.jar:2.4.1]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.14.jar:5.3.14]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:215) ~[spring-aop-5.3.14.jar:5.3.14]
at com.sun.proxy.$Proxy260.testRemoteMethod(Unknown Source) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:na]
at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
at java.base/java.lang.reflect.Method.invoke(Method.java:566) ~[na:na]
at org.springframework.remoting.support.RemoteInvocation.invoke(RemoteInvocation.java:215) ~[spring-context-5.3.14.jar:5.3.14]
at org.springframework.remoting.support.DefaultRemoteInvocationExecutor.invoke(DefaultRemoteInvocationExecutor.java:39) ~[spring-context-5.3.14.jar:5.3.14]
at org.springframework.remoting.support.RemoteInvocationBasedExporter.invoke(RemoteInvocationBasedExporter.java:78) ~[spring-context-5.3.14.jar:5.3.14]
at org.springframework.remoting.support.RemoteInvocationBasedExporter.invokeAndCreateResult(RemoteInvocationBasedExporter.java:114) ~[spring-context-5.3.14.jar:5.3.14]
at org.springframework.amqp.remoting.service.AmqpInvokerServiceExporter.onMessage(AmqpInvokerServiceExporter.java:81) ~[spring-amqp-2.4.1.jar:2.4.1]
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doInvokeListener(AbstractMessageListenerContainer.java:1721) ~[spring-rabbit-2.4.1.jar:2.4.1]
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.actualInvokeListener(AbstractMessageListenerContainer.java:1595) ~[spring-rabbit-2.4.1.jar:2.4.1]
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeListener(AbstractMessageListenerContainer.java:1572) ~[spring-rabbit-2.4.1.jar:2.4.1]
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.doExecuteListener(AbstractMessageListenerContainer.java:1563) ~[spring-rabbit-2.4.1.jar:2.4.1]
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:1507) ~[spring-rabbit-2.4.1.jar:2.4.1]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doReceiveAndExecute(SimpleMessageListenerContainer.java:967) ~[spring-rabbit-2.4.1.jar:2.4.1]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.receiveAndExecute(SimpleMessageListenerContainer.java:914) ~[spring-rabbit-2.4.1.jar:2.4.1]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$1600(SimpleMessageListenerContainer.java:83) ~[spring-rabbit-2.4.1.jar:2.4.1]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.mainLoop(SimpleMessageListenerContainer.java:1291) ~[spring-rabbit-2.4.1.jar:2.4.1]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1197) ~[spring-rabbit-2.4.1.jar:2.4.1]

Connect to remote jms queue with Spring Boot

I'm trying to connect a remote JBOSS, JBOSS EAP 7, JMS queue with spring boot.
Below my code, I have only a configuration class and consumer class.
I see through logs that I'm connecting to localhost, but... WHY???
#Configuration
#EnableJms
public class ActiveMqConnectionFactoryConfig {
String queueName= "JMSTestQueueName";
private static final String INITIAL_CONTEXT_FACTORY = "org.jboss.naming.remote.client.InitialContextFactory";
private static final String CONNECTION_FACTORY = "jms/RemoteConnectionFactory";
public ConnectionFactory connectionFactory() {
try {
System.out.println("Retrieving JMS queue with JNDI name: " + CONNECTION_FACTORY);
JndiObjectFactoryBean jndiObjectFactoryBean = new JndiObjectFactoryBean();
jndiObjectFactoryBean.setJndiName(CONNECTION_FACTORY);
jndiObjectFactoryBean.setJndiEnvironment(getEnvProperties());
jndiObjectFactoryBean.afterPropertiesSet();
return (QueueConnectionFactory) jndiObjectFactoryBean.getObject();
} catch (NamingException e) {
System.out.println("Error while retrieving JMS queue with JNDI name: [" + CONNECTION_FACTORY + "]");
} catch (Exception ex) {
System.out.println("Error error");
ex.getStackTrace();
}
return null;
}
#Bean
Properties getEnvProperties() throws NamingException {
Properties env = new Properties();
env.put(Context.INITIAL_CONTEXT_FACTORY, INITIAL_CONTEXT_FACTORY);
env.put(Context.PROVIDER_URL, "http-remoting://<REMOTE_ADDRESS>:8080?broker.persistent=false&broker.useJmx=false");
env.put(Context.SECURITY_PRINCIPAL, <USER>);
env.put(Context.SECURITY_CREDENTIALS, <PASSWORD>);
namingContext = new InitialContext(env);
return env;
}
#Bean
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory(ConnectionFactory connectionFactory) throws NamingException {
DefaultJmsListenerContainerFactory factory = new DefaultJmsListenerContainerFactory();
factory.setConnectionFactory(connectionFactory);
factory.setConcurrency("3-10");
JndiDestinationResolver jndiDestinationResolver = new JndiDestinationResolver();
jndiDestinationResolver.setJndiEnvironment(getEnvProperties());
factory.setDestinationResolver(jndiDestinationResolver);
return factory;
}
}
Listener Class:
#Configuration
public class jmsListener {
#JmsListener(destination = "queue/JMSTestQueueName", containerFactory = "jmsListenerContainerFactory")
public void receive(Message message) {
System.out.println("Received Message: " + message);
}
}
The log:
2020-05-27 00:21:58.571 INFO 10368 --- [ main] o.apache.activemq.broker.BrokerService : Apache ActiveMQ 5.15.7 (localhost, ID:ITPC020248-60530-1590531718443-0:1) is starting
2020-05-27 00:21:58.576 INFO 10368 --- [ main] o.apache.activemq.broker.BrokerService : Apache ActiveMQ 5.15.7 (localhost, ID:ITPC020248-60530-1590531718443-0:1) started
2020-05-27 00:21:58.577 INFO 10368 --- [ main] o.apache.activemq.broker.BrokerService : For help or more information please see: http://activemq.apache.org
2020-05-27 00:21:58.617 INFO 10368 --- [ main] o.a.activemq.broker.TransportConnector : Connector vm://localhost started
2020-05-27 00:21:58.659 INFO 10368 --- [ main] jboss.ConsumerClass : Started ConsumerClass in 1.922 seconds (JVM running for 3.504)
Without ?broker.persistent=false&broker.useJmx=false on the JNDI URL I obtain this:
2020-05-27 19:38:34.680 INFO 19752 --- [dpoint" task-13] org.jboss.ejb.client.remoting : EJBCLIENT000016: Channel Channel ID 8f759d73 (outbound) of Remoting connection 336369ee to /172.16.68.80:8080 can no longer process messages
2020-05-27 19:38:37.479 INFO 19752 --- [ main] jboss.ConsumerClass : Started ConsumerClass in 7.194 seconds (JVM running for 9.26)
2020-05-27 19:38:42.772 ERROR 19752 --- [enerContainer-2] o.s.j.l.DefaultMessageListenerContainer : Could not refresh JMS Connection for destination 'queue/JMSTestQueueName' - retrying using FixedBackOff{interval=5000, currentAttempts=0, maxAttempts=unlimited}. Cause: AMQ119031: Unable to validate user
2020-05-27 19:38:48.068 ERROR 19752 --- [enerContainer-2] o.s.j.l.DefaultMessageListenerContainer : Could not refresh JMS Connection for destination 'queue/JMSTestQueueName' - retrying using FixedBackOff{interval=5000, currentAttempts=1, maxAttempts=unlimited}. Cause: AMQ119031: Unable to validate user
2020-05-27 19:38:53.401 ERROR 19752 --- [enerContainer-2] o.s.j.l.DefaultMessageListenerContainer : Could not refresh JMS Connection for destination 'queue/JMSTestQueueName' - retrying using FixedBackOff{interval=5000, currentAttempts=2, maxAttempts=unlimited}. Cause: AMQ119031: Unable to validate user
2020-05-27 19:38:58.699 ERROR 19752 --- [enerContainer-2] o.s.j.l.DefaultMessageListenerContainer : Could not refresh JMS Connection for destination 'queue/JMSTestQueueName' - retrying using FixedBackOff{interval=5000, currentAttempts=3, maxAttempts=unlimited}. Cause: AMQ119031: Unable to validate user
2020-05-27 19:39:04.006 ERROR 19752 --- [enerContainer-2] o.s.j.l.DefaultMessageListenerContainer : Could not refresh JMS Connection for destination 'queue/JMSTestQueueName' - retrying using FixedBackOff{interval=5000, currentAttempts=4, maxAttempts=unlimited}. Cause: AMQ119031: Unable to validate user
2020-05-27 19:39:09.320 ERROR 19752 --- [enerContainer-2] o.s.j.l.DefaultMessageListenerContainer : Could not refresh JMS Connection for destination 'queue/JMSTestQueueName' - retrying using FixedBackOff{interval=5000, currentAttempts=5, maxAttempts=unlimited}. Cause: AMQ119031: Unable to validate user
Your connectionFactory() needs to be a #Bean in order to inject it as an argument into your container factory factory method.
public DefaultJmsListenerContainerFactory jmsListenerContainerFactory(ConnectionFactory connectionFactory) throws NamingException {
Since it's not a #Bean you are getting boot's default connection factory (presumably you have ActiveMQ on the class path).

Spring boot rabbitMq setExceptionHandler

How can I convert the following code using the Spring framework?
ConnectionFactory factory = new ConnectionFactory();
factory.setExceptionHandler(new BrokerExceptionHandler(logger, instance));
public final class BrokerExceptionHandler extends StrictExceptionHandler {
#Override
public void handleReturnListenerException(Channel channel, Throwable exception) {
logger.log(Level.SEVERE, "ReturnListenerException detected: ReturnListener.handleReturn", exception);
this.publishAlert(exception, "ReturnListener.handleReturn");
logger.log(Level.SEVERE, "Close application", exception);
System.exit(-1);
}
....
}
Basically I need to specify a custom exception handler if a rabbitMQ exception occurs and then stop the application
How can I publish a rabbitMq message every time that there is an exception?
EDIT
I modified my configuration class in this way:
#Bean
SimpleMessageListenerContainer containerPredict(ConnectionFactory connectionFactory,
MessageListenerAdapter listenerPredictAdapter) {
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
container.setDefaultRequeueRejected(false);
container.setErrorHandler(new BrokerExceptionHandler());
container.setQueueNames(getQueueName());
container.setMessageListener(listenerAdapter);
return container;
}
and this is my BrokerExceptionHandler class
public class BrokerExceptionHandler implements ErrorHandler {
private final Logger logger = Logger.getLogger(getClass().getSimpleName());
#Autowired
private Helper helper;
#Override
public void handleError(Throwable t) {
logger.log(Level.SEVERE, "Exception Detected. Publishing error alert");
String message = "Exception detected. Message: " + t.getMessage());
// Notify the error to the System sending a new RabbitMq message
System.out.println("---> Before convertAndSend");
rabbitTemplate.convertAndSend(exchange, routing, message);
System.out.println("---> After convertAndSend");
}
}
I can see the log Exception Detected. Publishing error alert and ---> Before convertAdnSend in the console, but the new alert is not published and the log ---> After convertAndSend doesn't appear in the console.
Here it is the log:
2018-10-17 09:32:02.849 ERROR 1506 --- [tainer****-1] BrokerExceptionHandler : Exception Detected. Publishing error alert
---> Before convertAndSend
2018-10-17 09:32:02.853 INFO 1506 --- [tainer****-1] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer#4f5b08d: tags=[{amq.ctag-yUcUmg5BCo20ucG1wJZoWA=myechange}], channel=Cached Rabbit Channel: AMQChannel(amqp://admin#XXX.XXX.XXX.XXX:5672/testbed_simulators,1), conn: Proxy#3964d79 Shared Rabbit Connection: SimpleConnection#61f39bb [delegate=amqp://admin#XXX.XXX.XXX.XXX:5672/testbed_simulators, localPort= 51528], acknowledgeMode=AUTO local queue size=0
2018-10-17 09:32:02.905 INFO 1506 --- [tainer****-2] o.s.amqp.rabbit.core.RabbitAdmin : Auto-declaring a non-durable, auto-delete, or exclusive Queue (myexchange) durable:false, auto-delete:true, exclusive:true. It will be redeclared if the broker stops and is restarted while the connection factory is alive, but all messages will be lost.
2018-10-17 09:32:02.905 INFO 1506 --- [tainer****-2] o.s.amqp.rabbit.core.RabbitAdmin : Auto-declaring a non-durable, auto-delete, or exclusive Queue (myexchange) durable:false, auto-delete:true, exclusive:true. It will be redeclared if the broker stops and is restarted while the connection factory is alive, but all messages will be lost.
EDIT
Debugging I see that before to send the new message, the following code is called:
File: SimpleMessageListenerContainer.class line 1212
if (!isActive(this.consumer) || aborted) {
.....
}
else {
---> logger.info("Restarting " + this.consumer);
restart(this.consumer);
}
EDIT 2
Example code: http://github.com/fabry00/spring-boot-rabbitmq
It depends on how you are doing your configuration; if you are using Spring Boot's auto-configured connection factory...
#Bean
public InitializingBean connectionFactoryConfigurer(CachingConnectionFactory ccf) {
return () -> ccf.getRabbitConnectionFactory().setExceptionHandler(...);
}
If you are wiring up your own beans (e.g. via a RabbitConnectionFactoryBean) then set it directly.
EDIT
You are throwing a NullPointerException in your error handler...
2018-10-17 11:51:58.733 DEBUG 38975 --- [containerKpis-1] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it
java.lang.NullPointerException: null
at com.test.BrokerExceptionHandler.handleError(BrokerExceptionHandler.java:27) ~[main/:na]
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.invokeErrorHandler(AbstractMessageListenerContainer.java:1243) ~[spring-rabbit-2.0.6.RELEASE.jar:2.0.6.RELEASE]
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.handleListenerException(AbstractMessageListenerContainer.java:1488) ~[spring-rabbit-2.0.6.RELEASE.jar:2.0.6.RELEASE]
at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.executeListener(AbstractMessageListenerContainer.java:1318) ~[spring-rabbit-2.0.6.RELEASE.jar:2.0.6.RELEASE]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.doReceiveAndExecute(SimpleMessageListenerContainer.java:817) ~[spring-rabbit-2.0.6.RELEASE.jar:2.0.6.RELEASE]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.receiveAndExecute(SimpleMessageListenerContainer.java:801) ~[spring-rabbit-2.0.6.RELEASE.jar:2.0.6.RELEASE]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer.access$700(SimpleMessageListenerContainer.java:77) ~[spring-rabbit-2.0.6.RELEASE.jar:2.0.6.RELEASE]
at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:1042) ~[spring-rabbit-2.0.6.RELEASE.jar:2.0.6.RELEASE]
at java.lang.Thread.run(Thread.java:748) [na:1.8.0_131]
2018-10-17 11:51:58.734 INFO 38975 --- [containerKpis-1] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer#1aabf50d: tags=[{amq.ctag-VxxHKiMsWI_w8DIooAsySA=myapp.mydomain.KPIS}], channel=Cached Rabbit Channel: AMQChannel(amqp://guest#127.0.0.1:5672/,1), conn: Proxy#b88a7d6 Shared Rabbit Connection: SimpleConnection#25dc64a [delegate=amqp://guest#127.0.0.1:5672/, localPort= 55662], acknowledgeMode=AUTO local queue size=0
To turn on DEBUG logging, add
logging.level.org.springframework.amqp=debug
to your application.properties.
this.helper is null because the error handler is not a Spring Bean - #Autowired only works if Spring manages the object; you are using new BrokerExceptionHandler().
EDIT2
I added these 2 beans
#Bean
public BrokerExceptionHandler errorHandler() {
return new BrokerExceptionHandler();
}
#Bean
public MessageConverter json() { // Boot auto-configures in template
return new Jackson2JsonMessageConverter();
}
and now...
---> Before publishing Alert event
--- ALERT
2018-10-17 12:14:45.304 INFO 43359 --- [containerKpis-1] Helper : publishAlert
2018-10-17 12:14:45.321 DEBUG 43359 --- [containerKpis-1] o.s.a.r.c.CachingConnectionFactory : Creating cached Rabbit Channel from AMQChannel(amqp://guest#127.0.0.1:5672/,3)
2018-10-17 12:14:45.321 DEBUG 43359 --- [containerKpis-1] o.s.amqp.rabbit.core.RabbitTemplate : Executing callback RabbitTemplate$$Lambda$638/975724213 on RabbitMQ Channel: Cached Rabbit Channel: AMQChannel(amqp://guest#127.0.0.1:5672/,3), conn: Proxy#77f3f419 Shared Rabbit Connection: SimpleConnection#10c86af1 [delegate=amqp://guest#127.0.0.1:5672/, localPort= 56220]
2018-10-17 12:14:45.321 DEBUG 43359 --- [containerKpis-1] o.s.amqp.rabbit.core.RabbitTemplate : Publishing message (Body:'{"timestamp":1539792885303,"code":"ERROR","severity":"ERROR","message":"Exception detected. Message: Listener method 'kpisEvent' threw exception"}' MessageProperties [headers={sender=myapp, protocolVersion=1.0.0, senderType=MY_COMPONENT_1, __TypeId__=com.test.domain.Alert, timestamp=1539792885304}, contentType=application/json, contentEncoding=UTF-8, contentLength=146, deliveryMode=PERSISTENT, priority=0, deliveryTag=0])on exchange [myevent.ALERT], routingKey = [/]
--- ALERT 2
---> After publishing Alert event
2018-10-17 12:14:45.323 DEBUG 43359 --- [pool-1-thread-6] o.s.a.r.listener.BlockingQueueConsumer : Storing delivery for consumerTag: 'amq.ctag-eYbzZ09pCw3cjdtSprlZMQ' with deliveryTag: '1' in Consumer#4b790d86: tags=[{amq.ctag-eYbzZ09pCw3cjdtSprlZMQ=myapp.myevent.ALERT}], channel=Cached Rabbit Channel: AMQChannel(amqp://guest#127.0.0.1:5672/,2), conn: Proxy#77f3f419 Shared Rabbit Connection: SimpleConnection#10c86af1 [delegate=amqp://guest#127.0.0.1:5672/, localPort= 56220], acknowledgeMode=AUTO local queue size=0
2018-10-17 12:14:45.324 DEBUG 43359 --- [ontainerReset-1] o.s.a.r.listener.BlockingQueueConsumer : Received message: (Body:'{"timestamp":1539792885303,"code":"ERROR","severity":"ERROR","message":"Exception detected. Message: Listener method 'kpisEvent' threw exception"}' MessageProperties [headers={sender=myapp, protocolVersion=1.0.0, senderType=MY_COMPONENT_1, __TypeId__=com.test.domain.Alert, timestamp=1539792885304}, contentType=application/json, contentEncoding=UTF-8, contentLength=0, receivedDeliveryMode=PERSISTENT, priority=0, redelivered=false, receivedExchange=myevent.ALERT, receivedRoutingKey=/, deliveryTag=1, consumerTag=amq.ctag-eYbzZ09pCw3cjdtSprlZMQ, consumerQueue=myapp.myevent.ALERT])
2018-10-17 12:14:45.324 INFO 43359 --- [ontainerReset-1] Application : ---> kpisAlert RECEIVED
2018-10-17 12:14:45.325 ERROR 43359 --- [ontainerReset-1] Application : ---> Message: Exception detected. Message: Listener method 'kpisEvent' threw exception
2018-10-17 12:14:45.326 DEBUG 43359 --- [containerKpis-1] o.s.a.r.listener.BlockingQueueConsumer : Rejecting messages (requeue=false)
EDIT3
Or, if you prefer Gson...
#Bean
public MessageConverter json() {
Gson gson = new GsonBuilder().create();
return new MessageConverter() {
#Override
public Message toMessage(Object object, MessageProperties messageProperties) throws MessageConversionException {
return new Message(gson.toJson(object).getBytes(), messageProperties);
}
#Override
public Object fromMessage(Message message) throws MessageConversionException {
throw new UnsupportedOperationException();
}
};
}
EDIT4
I changed the current version of your app as follows:
#Bean
public MessageConverter jsonConverter() {
Gson gson = new GsonBuilder().create();
EventKpisCollected collected = new EventKpisCollected();
return new MessageConverter() {
#Override
public Message toMessage(Object object, MessageProperties messageProperties) throws MessageConversionException {
System.out.println("toMessage");
return new Message(gson.toJson(object).getBytes(), messageProperties);
}
#Override
public Object fromMessage(Message message) throws MessageConversionException {
System.out.println("fromMessage");
return collected.decode(new String(message.getBody()));
}
};
}
...
#Bean
SimpleMessageListenerContainer containerKpis(ConnectionFactory connectionFactory,
MessageListenerAdapter listenerKpisAdapter) {
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
container.setDefaultRequeueRejected(false);
container.setErrorHandler(errorHandler());
container.setQueueNames(getQueueKpis());
container.setMessageListener(listenerKpisAdapter);
return container;
}
#Bean
SimpleMessageListenerContainer containerReset(ConnectionFactory connectionFactory,
MessageListenerAdapter listenerAlertAdapter) {
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
container.setDefaultRequeueRejected(false);
container.setErrorHandler(errorHandler());
container.setQueueNames(getQueueAlert());
container.setMessageListener(listenerAlertAdapter);
return container;
}
#Bean
MessageListenerAdapter listenerKpisAdapter(Application receiver) {
MessageListenerAdapter messageListenerAdapter = new MessageListenerAdapter(receiver, "kpisEvent");
messageListenerAdapter.setMessageConverter(jsonConverter());
return messageListenerAdapter;
}
#Bean
MessageListenerAdapter listenerAlertAdapter(Application receiver) {
MessageListenerAdapter messageListenerAdapter = new MessageListenerAdapter(receiver, "alertEvent");
// messageListenerAdapter.setMessageConverter(jsonConverter()); converter only handles events.
return messageListenerAdapter;
}
and
fromMessage
2018-10-19 13:46:53.734 INFO 10725 --- [containerKpis-1] Application : ---> kpisEvent RECEIVED
2018-10-19 13:46:53.734 INFO 10725 --- [containerKpis-1] Application : ---> kpisEvent DECODED, windowId: 1522751098000-1522752198000
With the event decoding done by the framework (just for the event currently - you will need a second converter for the alers).

Correctly configuring SimpleRabbitListenerContainerFactory

I have a bean to configure SimpleRabbitListenerContainerFactory but when I use factory.setTaskExecutor(taskScheduler); I get this log which delays the app start-up for more than 300+ seconds. But if I commented this TaskExecutor everything work fine.
Log on Debug level:
2017-04-24 15:48:45.449 DEBUG 28550 --- [ JWorkers-4] o.s.a.r.t.RabbitTransactionManager : Initiating transaction commit
2017-04-24 15:48:45.449 DEBUG 28550 --- [ JWorkers-7] o.s.a.r.t.RabbitTransactionManager : Initiating transaction commit
2017-04-24 15:48:45.449 DEBUG 28550 --- [ JWorkers-1] o.s.a.r.t.RabbitTransactionManager : Initiating transaction commit
2017-04-24 15:48:45.449 DEBUG 28550 --- [ JWorkers-2] o.s.a.r.t.RabbitTransactionManager : Initiating transaction commit
2017-04-24 15:48:45.449 DEBUG 28550 --- [ JWorkers-6] o.s.a.r.t.RabbitTransactionManager : Initiating transaction commit
2017-04-24 15:48:45.449 DEBUG 28550 --- [ JWorkers-3] o.s.a.r.t.RabbitTransactionManager : Initiating transaction commit
2017-04-24 15:48:45.449 DEBUG 28550 --- [ JWorkers-8] o.s.a.r.t.RabbitTransactionManager : Initiating transaction commit
2017-04-24 15:48:45.449 DEBUG 28550 --- [ JWorkers-5] o.s.a.r.t.RabbitTransactionManager : Initiating transaction commit
2017-04-24 15:48:45.450 DEBUG 28550 --- [ JWorkers-4] o.s.a.r.connection.RabbitResourceHolder : Skipping close of consumer channel: Cached Rabbit Channel: AMQChannel(amqp://localuser#localhost:5672/vh,4), conn: Proxy#14aa069c Shared Rabbit Connection: SimpleConnection#4f8c20a2 [delegate=amqp://localuser#localhost:5672/vh, localPort= 40106]
2017-04-24 15:48:45.450 DEBUG 28550 --- [ JWorkers-7] o.s.a.r.connection.RabbitResourceHolder : Skipping close of consumer channel: Cached Rabbit Channel: AMQChannel(amqp://localuser#localhost:5672/vh,7), conn: Proxy#14aa069c Shared Rabbit Connection: SimpleConnection#4f8c20a2 [delegate=amqp://localuser#localhost:5672/vh, localPort= 40106]
2017-04-24 15:48:45.450 DEBUG 28550 --- [ JWorkers-4] o.s.a.r.t.RabbitTransactionManager : Creating new transaction with name [null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
2017-04-24 15:48:45.450 DEBUG 28550 --- [ JWorkers-2] o.s.a.r.connection.RabbitResourceHolder : Skipping close of consumer channel: Cached Rabbit Channel: AMQChannel(amqp://localuser#localhost:5672/vh,2), conn: Proxy#14aa069c Shared Rabbit Connection: SimpleConnection#4f8c20a2 [delegate=amqp://localuser#localhost:5672/vh, localPort= 40106]
2017-04-24 15:48:45.450 DEBUG 28550 --- [ JWorkers-8] o.s.a.r.connection.RabbitResourceHolder : Skipping close of consumer channel: Cached Rabbit Channel: AMQChannel(amqp://localuser#localhost:5672/vh,9), conn: Proxy#14aa069c Shared Rabbit Connection: SimpleConnection#4f8c20a2 [delegate=amqp://localuser#localhost:5672/vh, localPort= 40106]
2017-04-24 15:48:45.450 DEBUG 28550 --- [ JWorkers-7] o.s.a.r.t.RabbitTransactionManager : Creating new transaction with name [null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
2017-04-24 15:48:45.450 DEBUG 28550 --- [ JWorkers-4] o.s.a.r.t.RabbitTransactionManager : Created AMQP transaction on channel [Cached Rabbit Channel: AMQChannel(amqp://localuser#localhost:5672/vh,4), conn: Proxy#14aa069c Shared Rabbit Connection: SimpleConnection#4f8c20a2 [delegate=amqp://localuser#localhost:5672/vh, localPort= 40106]]
2017-04-24 15:48:45.450 DEBUG 28550 --- [ JWorkers-1] o.s.a.r.connection.RabbitResourceHolder : Skipping close of consumer channel: Cached Rabbit Channel: AMQChannel(amqp://localuser#localhost:5672/vh,8), conn: Proxy#14aa069c Shared Rabbit Connection: SimpleConnection#4f8c20a2 [delegate=amqp://localuser#localhost:5672/vh, localPort= 40106]
2017-04-24 15:48:45.450 DEBUG 28550 --- [ JWorkers-2] o.s.a.r.t.RabbitTransactionManager : Creating new transaction with name [null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
2017-04-24 15:48:45.450 DEBUG 28550 --- [ JWorkers-6] o.s.a.r.connection.RabbitResourceHolder : Skipping close of consumer channel: Cached Rabbit Channel: AMQChannel(amqp://localuser#localhost:5672/vh,6), conn: Proxy#14aa069c Shared Rabbit Connection: SimpleConnection#4f8c20a2 [delegate=amqp://localuser#localhost:5672/vh, localPort= 40106]
2017-04-24 15:48:45.450 DEBUG 28550 --- [ JWorkers-3] o.s.a.r.connection.RabbitResourceHolder : Skipping close of consumer channel: Cached Rabbit Channel: AMQChannel(amqp://localuser#localhost:5672/vh,3), conn: Proxy#14aa069c Shared Rabbit Connection: SimpleConnection#4f8c20a2 [delegate=amqp://localuser#localhost:5672/vh, localPort= 40106]
2017-04-24 15:48:45.450 DEBUG 28550 --- [ JWorkers-5] o.s.a.r.connection.RabbitResourceHolder : Skipping close of consumer channel: Cached Rabbit Channel: AMQChannel(amqp://localuser#localhost:5672/vh,5), conn: Proxy#14aa069c Shared Rabbit Connection: SimpleConnection#4f8c20a2 [delegate=amqp://localuser#localhost:5672/vh, localPort= 40106]
2017-04-24 15:48:45.451 DEBUG 28550 --- [ JWorkers-8] o.s.a.r.t.RabbitTransactionManager : Creating new transaction with name [null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
2017-04-24 15:48:45.451 DEBUG 28550 --- [ JWorkers-7] o.s.a.r.t.RabbitTransactionManager : Created AMQP transaction on channel [Cached Rabbit Channel: AMQChannel(amqp://localuser#localhost:5672/vh,7), conn: Proxy#14aa069c Shared Rabbit Connection: SimpleConnection#4f8c20a2 [delegate=amqp://localuser#localhost:5672/vh, localPort= 40106]]
2017-04-24 15:48:45.451 DEBUG 28550 --- [ JWorkers-4] o.s.a.r.listener.BlockingQueueConsumer : Retrieving delivery for Consumer: tags=[{amq.ctag-WNpoLguXQUuqvsfU0XWgbg=accepted-queue}], channel=Cached Rabbit Channel: AMQChannel(amqp://localuser#localhost:5672/vh,4), conn: Proxy#14aa069c Shared Rabbit Connection: SimpleConnection#4f8c20a2 [delegate=amqp://localuser#localhost:5672/vh, localPort= 40106], acknowledgeMode=AUTO local queue size=0
2017-04-24 15:48:45.451 DEBUG 28550 --- [ JWorkers-1] o.s.a.r.t.RabbitTransactionManager : Creating new transaction with name [null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
2017-04-24 15:48:45.451 DEBUG 28550 --- [ JWorkers-2] o.s.a.r.t.RabbitTransactionManager : Created AMQP transaction on channel [Cached Rabbit Channel: AMQChannel(amqp://localuser#localhost:5672/vh,2), conn: Proxy#14aa069c Shared Rabbit Connection: SimpleConnection#4f8c20a2 [delegate=amqp://localuser#localhost:5672/vh, localPort= 40106]]
2017-04-24 15:48:45.451 DEBUG 28550 --- [ JWorkers-6] o.s.a.r.t.RabbitTransactionManager : Creating new transaction with name [null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
2017-04-24 15:48:45.451 DEBUG 28550 --- [ JWorkers-3] o.s.a.r.t.RabbitTransactionManager : Creating new transaction with name [null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
2017-04-24 15:48:45.451 DEBUG 28550 --- [ JWorkers-5] o.s.a.r.t.RabbitTransactionManager : Creating new transaction with name [null]: PROPAGATION_REQUIRED,ISOLATION_DEFAULT
2017-04-24 15:48:45.451 DEBUG 28550 --- [ JWorkers-8] o.s.a.r.t.RabbitTransactionManager : Created AMQP transaction on channel [Cached Rabbit Channel: AMQChannel(amqp://localuser#localhost:5672/vh,9), conn: Proxy#14aa069c Shared Rabbit Connection: SimpleConnection#4f8c20a2 [delegate=amqp://localuser#localhost:5672/vh, localPort= 40106]]
2017-04-24 15:48:45.451 DEBUG 28550 --- [ JWorkers-7] o.s.a.r.listener.BlockingQueueConsumer : Retrieving delivery for Consumer: tags=[{amq.ctag-4-uSG6VKO__RhZW7e1Eqhg=queue-wait}], channel=Cached Rabbit Channel: AMQChannel(amqp://localuser#localhost:5672/vh,7), conn: Proxy#14aa069c Shared Rabbit Connection: SimpleConnection#4f8c20a2 [delegate=amqp://localuser#localhost:5672/vh, localPort= 40106], acknowledgeMode=AUTO local queue size=0
2017-04-24 15:48:45.451 DEBUG 28550 --- [ JWorkers-1] o.s.a.r.t.RabbitTransactionManager : Created AMQP transaction on channel [Cached Rabbit Channel: AMQChannel(amqp://localuser#localhost:5672/vh,8), conn: Proxy#14aa069c Shared Rabbit Connection: SimpleConnection#4f8c20a2 [delegate=amqp://localuser#localhost:5672/vh, localPort= 40106]]
2017-04-24 15:48:45.451 DEBUG 28550 --- [ JWorkers-2] o.s.a.r.listener.BlockingQueueConsumer : Retrieving delivery for Consumer: tags=[{amq.ctag-gNKSZWts2YmsHyIflgFBRw=exceptions-queue}], channel=Cached Rabbit Channel: AMQChannel(amqp://localuser#localhost:5672/vh,2), conn: Proxy#14aa069c Shared Rabbit Connection: SimpleConnection#4f8c20a2 [delegate=amqp://localuser#localhost:5672/vh, localPort= 40106], acknowledgeMode=AUTO local queue size=0
2017-04-24 15:48:45.451 DEBUG 28550 --- [ JWorkers-6] o.s.a.r.t.RabbitTransactionManager : Created AMQP transaction on channel [Cached Rabbit Channel: AMQChannel(amqp://localuser#localhost:5672/vh,6), conn: Proxy#14aa069c Shared Rabbit Connection: SimpleConnection#4f8c20a2 [delegate=amqp://localuser#localhost:5672/vh, localPort= 40106]]
2017-04-24 15:48:45.451 DEBUG 28550 --- [ JWorkers-3] o.s.a.r.t.RabbitTransactionManager : Created AMQP transaction on channel [Cached Rabbit Channel: AMQChannel(amqp://localuser#localhost:5672/vh,3), conn: Proxy#14aa069c Shared Rabbit Connection: SimpleConnection#4f8c20a2 [delegate=amqp://localuser#localhost:5672/vh, localPort= 40106]]
2017-04-24 15:48:45.451 DEBUG 28550 --- [ JWorkers-7] o.s.a.r.listener.BlockingQueueConsumer : Retrieving delivery for Consumer: tags=[{amq.ctag-4-uSG6VKO__RhZW7e1Eqhg=queue-wait}], channel=Cached Rabbit Channel: AMQChannel(amqp://localuser#localhost:5672/vh,7), conn: Proxy#14aa069c Shared Rabbit Connection: SimpleConnection#4f8c20a2 [delegate=amqp://localuser#localhost:5672/vh, localPort= 40106], acknowledgeMode=AUTO local queue size=0
2017-04-24 15:48:45.451 DEBUG 28550 --- [ JWorkers-1] o.s.a.r.t.RabbitTransactionManager : Created AMQP transaction on channel [Cached Rabbit Channel: AMQChannel(amqp://localuser#localhost:5672/vh,8), conn: Proxy#14aa069c Shared Rabbit Connection: SimpleConnection#4f8c20a2 [delegate=amqp://localuser#localhost:5672/vh, localPort= 40106]]
2017-04-24 15:48:45.451 DEBUG 28550 --- [ JWorkers-2] o.s.a.r.listener.BlockingQueueConsumer : Retrieving delivery for Consumer: tags=[{amq.ctag-gNKSZWts2YmsHyIflgFBRw=exceptions-queue}], channel=Cached Rabbit Channel: AMQChannel(amqp://localuser#localhost:5672/vh,2), conn: Proxy#14aa069c Shared Rabbit Connection: SimpleConnection#4f8c20a2 [delegate=amqp://localuser#localhost:5672/vh, localPort= 40106], acknowledgeMode=AUTO local queue size=0
2017-04-24 15:48:45.451 DEBUG 28550 --- [ JWorkers-6] o.s.a.r.t.RabbitTransactionManager : Created AMQP transaction on channel [Cached Rabbit Channel: AMQChannel(amqp://localuser#localhost:5672/vh,6), conn: Proxy#14aa069c Shared Rabbit Connection: SimpleConnection#4f8c20a2 [delegate=amqp://localuser#localhost:5672/vh, localPort= 40106]]
2017-04-24 15:48:45.451 DEBUG 28550 --- [ JWorkers-3] o.s.a.r.t.RabbitTransactionManager : Created AMQP transaction on channel [Cached Rabbit Channel: AMQChannel(amqp://localuser#localhost:5672/vh,3), conn: Proxy#14aa069c Shared Rabbit Connection: SimpleConnection#4f8c20a2 [delegate=amqp://localuser#localhost:5672/vh, localPort= 40106]]
2017-04-24 15:48:45.451 DEBUG 28550 --- [ JWorkers-5] o.s.a.r.t.RabbitTransactionManager : Created AMQP transaction on channel [Cached Rabbit Channel: AMQChannel(amqp://localuser#localhost:5672/vh,5), conn: Proxy#14aa069c Shared Rabbit Connection: SimpleConnection#4f8c20a2 [delegate=amqp://localuser#localhost:5672/vh, localPort= 40106]]
2017-04-24 15:48:45.451 DEBUG 28550 --- [ JWorkers-8] o.s.a.r.listener.BlockingQueueConsumer : Retrieving delivery for Consumer: tags=[{amq.ctag-uAZX6E7qZilTn7YVzc9Gfw=cr-queue}], channel=Cached Rabbit Channel: AMQChannel(amqp://localuser#localhost:5672/vh,9), conn: Proxy#14aa069c Shared Rabbit Connection: SimpleConnection#4f8c20a2 [delegate=amqp://localuser#localhost:5672/vh, localPort= 40106], acknowledgeMode=AUTO local queue size=0
2017-04-24 15:48:45.451 DEBUG 28550 --- [ JWorkers-1] o.s.a.r.listener.BlockingQueueConsumer : Retrieving delivery for Consumer: tags=[{amq.ctag--wz2ymgmywlECrSmcXvAhg=cr-queue}], channel=Cached Rabbit Channel: AMQChannel(amqp://localuser#localhost:5672/vh,8), conn: Proxy#14aa069c Shared Rabbit Connection: SimpleConnection#4f8c20a2 [delegate=amqp://localuser#localhost:5672/vh, localPort= 40106], acknowledgeMode=AUTO local queue size=0
2017-04-24 15:48:45.451 DEBUG 28550 --- [ JWorkers-6] o.s.a.r.listener.BlockingQueueConsumer : Retrieving delivery for Consumer: tags=[{amq.ctag-mWHmcoeXhWAd_z89yBQ22A=queue-wait}], channel=Cached Rabbit Channel: AMQChannel(amqp://localuser#localhost:5672/vh,6), conn: Proxy#14aa069c Shared Rabbit Connection: SimpleConnection#4f8c20a2 [delegate=amqp://localuser#localhost:5672/vh, localPort= 40106], acknowledgeMode=AUTO local queue size=0
2017-04-24 15:48:45.451 DEBUG 28550 --- [ JWorkers-3] o.s.a.r.listener.BlockingQueueConsumer : Retrieving delivery for Consumer: tags=[{amq.ctag-U2_lfDwU_B3WS_2epRAspw=exceptions-queue}], channel=Cached Rabbit Channel: AMQChannel(amqp://localuser#localhost:5672/vh,3), conn: Proxy#14aa069c Shared Rabbit Connection: SimpleConnection#4f8c20a2 [delegate=amqp://localuser#localhost:5672/vh, localPort= 40106], acknowledgeMode=AUTO local queue size=0
2017-04-24 15:48:45.451 DEBUG 28550 --- [ JWorkers-5] o.s.a.r.listener.BlockingQueueConsumer : Retrieving delivery for Consumer: tags=[{amq.ctag-0wfRlvj-gh96FFeDqNhCzQ=accepted-queue}], channel=Cached Rabbit Channel: AMQChannel(amqp://localuser#localhost:5672/vh,5), conn: Proxy#14aa069c Shared Rabbit Connection: SimpleConnection#4f8c20a2 [delegate=amqp://localuser#localhost:5672/vh, localPort= 40106], acknowledgeMode=AUTO local queue size=0
2017-04-24 15:48:46.451 DEBUG 28550 --- [ JWorkers-4] o.s.a.r.t.RabbitTransactionManager : Initiating transaction commit
2017-04-24 15:48:46.451 DEBUG 28550 --- [ JWorkers-7] o.s.a.r.t.RabbitTransactionManager : Initiating transaction commit
2017-04-24 15:48:46.451 DEBUG 28550 --- [ JWorkers-2] o.s.a.r.t.RabbitTransactionManager : Initiating transaction commit
My Configurations:
#Autowired
private CachingConnectionFactory cachingConnectionFactory;
/**
* To configure #RabbitListener
*
* #return
*/
#Bean
public SimpleRabbitListenerContainerFactory rabbitListenerContainerFactory(ConcurrentTaskScheduler taskScheduler) {
SimpleRabbitListenerContainerFactory factory = new SimpleRabbitListenerContainerFactory();
factory.setTaskExecutor(taskScheduler); // When commenting this everything is fine
factory.setConnectionFactory(cachingConnectionFactory);
factory.setMessageConverter(jsonMessageConverter());
factory.setConcurrentConsumers(2);
factory.setMaxConcurrentConsumers(6);
factory.setTransactionManager(rabbitTransactionManager());
// use a non-transactional template for the DLQ
RabbitTemplate dlqTemplate = new RabbitTemplate(this.cachingConnectionFactory);
// When retries reach the maximum number that massage is dead-lettered to exceptions-exchange
Interceptor retryInterceptor = RetryInterceptorBuilder.stateless()
.maxAttempts(5)
.recoverer(new RepublishMessageRecoverer(dlqTemplate, DLQueue.EXCEPTION_EXCHANGE))
.build();
factory.setAdviceChain(retryInterceptor);
return factory;
}
public RabbitTransactionManager rabbitTransactionManager() {
return new RabbitTransactionManager(cachingConnectionFactory);
}
This Spring Boot 1.4.1.RELEASE running on Tomcat 8.0
delays the app start-up for more than 300+
Since you only show 2 milliseconds of logs, and none of it relates to container start up, it's hard to say.
Using an external task executor shouldn't make any difference, as long as it can supply enough threads to satisfy the container's concurrency (in addition to whatever else is using the executor).
Edit your question to show the exact configuration (including the container and executor) that exhibits this behavior.

Resources