org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'eurekaAutoServiceRegistration': Singleton bean crea - microservices

I'm developing a Spring Boot + Microservices example. I've taken reference from link: https://github.com/PacktPublishing/Mastering-Spring-Cloud/tree/master/Chapter06/sample-spring-cloud-comm-feign.
In this example, I'm able to start the discovery-service and gateway-service successfully, but when I tried to start any other service I am getting below error.
One thing which I notice that instructions are not very clear on how to execute the code even not mentioned clearly in the book.
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
19:05:25.564 ERROR
***************************
APPLICATION FAILED TO START
***************************
Description:
The Tomcat connector configured to listen on port 8080 failed to start. The port may already be in use or the connector may be misconfigured.
Action:
Verify the connector's configuration, identify and stop any process that's listening on port 8080, or configure this application to listen on another port.
19:05:25.564 INFO Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#1992eaf4: startup date [Mon Dec 24 19:05:14 IST 2018]; parent: org.springframework.context.annotation.AnnotationConfigApplicationContext#48aca48b
19:05:25.564 INFO Unregistering application customer-service with eureka with status DOWN
19:05:25.564 WARN Saw local status change event StatusChangeEvent [timestamp=1545658525564, current=DOWN, previous=UP]
19:05:25.564 INFO DiscoveryClient_CUSTOMER-SERVICE/localhost:customer-service: registering service...
19:05:25.564 INFO Stopping beans in phase 0
19:05:25.579 INFO DiscoveryClient_CUSTOMER-SERVICE/localhost:customer-service - registration status: 204
19:05:26.017 INFO Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#4a064404: startup date [Mon Dec 24 19:05:26 IST 2018]; parent: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#1992eaf4
19:05:26.061 INFO JSR-330 'javax.inject.Inject' annotation found and supported for autowiring
19:05:26.221 INFO Flipping property: localhost.ribbon.ActiveConnectionsLimit to use NEXT property: niws.loadbalancer.availabilityFilteringRule.activeConnectionsLimit = 2147483647
19:05:26.221 INFO Shutdown hook installed for: NFLoadBalancer-PingTimer-localhost
19:05:26.254 INFO Client: localhost instantiated a LoadBalancer: DynamicServerListLoadBalancer:{NFLoadBalancer:name=localhost,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:null
19:05:26.288 INFO Using serverListUpdater PollingServerListUpdater
19:05:26.288 INFO DynamicServerListLoadBalancer for client localhost initialized: DynamicServerListLoadBalancer:{NFLoadBalancer:name=localhost,current list of Servers=[],Load balancer stats=Zone stats: {},Server stats: []}ServerList:org.springframework.cloud.netflix.ribbon.eureka.DomainExtractingServerList#1ba156fc
19:05:26.585 INFO Unregistering JMX-exposed beans on shutdown
19:05:26.585 INFO Unregistering JMX-exposed beans
19:05:26.585 INFO Shutting down DiscoveryClient ...
19:05:26.585 INFO Unregistering ...
19:05:26.606 INFO DiscoveryClient_CUSTOMER-SERVICE/localhost:customer-service - deregister status: 200
19:05:26.607 INFO Completed shut down of DiscoveryClient
19:05:26.607 INFO Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#4a064404: startup date [Mon Dec 24 19:05:26 IST 2018]; parent: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#1992eaf4
19:05:26.607 WARN Exception thrown from ApplicationListener handling ContextClosedEvent
org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'eurekaAutoServiceRegistration': Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.getSingleton(DefaultSingletonBeanRegistry.java:216)
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:302)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:197)
at org.springframework.context.support.AbstractApplicationContext.getBean(AbstractApplicationContext.java:1078)
at org.springframework.context.event.ApplicationListenerMethodAdapter.getTargetBean(ApplicationListenerMethodAdapter.java:283)
at org.springframework.context.event.ApplicationListenerMethodAdapter.doInvoke(ApplicationListenerMethodAdapter.java:253)
at org.springframework.context.event.ApplicationListenerMethodAdapter.processEvent(ApplicationListenerMethodAdapter.java:177)
at org.springframework.context.event.ApplicationListenerMethodAdapter.onApplicationEvent(ApplicationListenerMethodAdapter.java:140)
at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:167)
at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:393)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:399)
at org.springframework.context.support.AbstractApplicationContext.publishEvent(AbstractApplicationContext.java:347)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:991)
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:958)
at org.springframework.cloud.context.named.NamedContextFactory.destroy(NamedContextFactory.java:76)
at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:272)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:578)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:554)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:961)
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:523)
at org.springframework.beans.factory.support.FactoryBeanRegistrySupport.destroySingletons(FactoryBeanRegistrySupport.java:230)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:968)
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1030)
at org.springframework.context.support.AbstractApplicationContext.doClose(AbstractApplicationContext.java:1006)
at org.springframework.context.support.AbstractApplicationContext.close(AbstractApplicationContext.java:958)
at org.springframework.boot.SpringApplication.handleRunFailure(SpringApplication.java:750)
at org.springframework.boot.SpringApplication.run(SpringApplication.java:314)
at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:134)
at pl.piomin.services.customer.CustomerApplication.main(CustomerApplication.java:22)
19:05:26.607 INFO Shutdown hook removed for: NFLoadBalancer-PingTimer-localhost
19:05:26.607 INFO Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#1491344a: startup date [Mon Dec 24 19:05:17 IST 2018]; parent: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#1992eaf4
19:05:26.607 WARN Exception thrown from ApplicationListener handling ContextClosedEvent
org.springframework.beans.factory.BeanCreationNotAllowedException: Error creating bean with name 'eurekaAutoServiceRegistration': Singleton bean creation not allowed while singletons of this factory are in destruction (Do not request a bean from a BeanFactory in a destroy method implementation!)

Change the port in application.yml where ever you have below properties. In your system the tomcat is probably running in default 8080 port.
server:
port: ${PORT:8080}
Hope the above change may help you.

https://github.com/spring-cloud/spring-cloud-netflix/commit/12583fd0c25638f95c14973d921ca28cdcd17df5
update your spring cloud version to Greenwich.SR6, the question will dispear

Related

Spring Application not getting terminate for timeout exception

I have created a spring boot application to publish the message to the Kafka queue. For that, I am using spring cloud stream and Kafka binder as dependencies. Problem is my application is continuously trying to connect to Kafka broker if it is down for 2 minutes because of the default configuration.
I have reduced that time using the below property and set it to 1000 ms and getting the timeout exception
spring.kafka.properties.request.timeout.ms:1000.
But still, my spring application is running after the exception. I want it to fail if Kafka broker is not available to connect to. I have tried one more property for that spring.kafka.admin.fail-fast=true but still, the application is running.
I have also tried to search for some properties of spring cloud stream and Kafka binder that I can set to fail my application if Kafka broker is not available but couldn't find anything related to that.
Please, help me with this.
Please see below for the log of exception.
Caused by: java.util.concurrent.ExecutionException: org.apache.kafka.common.errors.TimeoutException: Timed out waiting for a node assignment.
at org.apache.kafka.common.internals.KafkaFutureImpl.wrapAndThrow(KafkaFutureImpl.java:45)
at org.apache.kafka.common.internals.KafkaFutureImpl.access$000(KafkaFutureImpl.java:32)
at org.apache.kafka.common.internals.KafkaFutureImpl$SingleWaiter.await(KafkaFutureImpl.java:104)
at org.apache.kafka.common.internals.KafkaFutureImpl.get(KafkaFutureImpl.java:274)
at org.springframework.cloud.stream.binder.kafka.provisioning.KafkaTopicProvisioner.createTopicAndPartitions(KafkaTopicProvisioner.java:351)
at org.springframework.cloud.stream.binder.kafka.provisioning.KafkaTopicProvisioner.createTopicIfNecessary(KafkaTopicProvisioner.java:325)
at org.springframework.cloud.stream.binder.kafka.provisioning.KafkaTopicProvisioner.createTopic(KafkaTopicProvisioner.java:302)
... 33 common frames omitted
Caused by: org.apache.kafka.common.errors.TimeoutException: Timed out waiting for a node assignment.
2019-05-22 06:06:25 [main] DEBUG o.s.c.s.DefaultLifecycleProcessor - Successfully started bean 'outputBindingLifecycle'
2019-05-22 06:06:25 [main] DEBUG o.s.c.s.DefaultLifecycleProcessor - Starting beans in phase 2147482647
2019-05-22 06:06:25 [main] DEBUG o.s.c.s.binding.BindableProxyFactory - Binding inputs for :interface kafka.stream.RXXXStreams
2019-05-22 06:06:25 [main] DEBUG o.s.c.s.DefaultLifecycleProcessor - Successfully started bean 'inputBindingLifecycle'
2019-05-22 06:06:25 [main] DEBUG o.s.c.s.DefaultLifecycleProcessor - Starting beans in phase 2147483547
2019-05-22 06:06:25 [main] DEBUG o.s.c.s.DefaultLifecycleProcessor - Successfully started bean 'org.springframework.kafka.config.internalKafkaListenerEndpointRegistry'
2019-05-22 06:06:25 [main] DEBUG o.s.b.a.l.ConditionEvaluationReportLoggingListener -
Do you have spring-boot-web libraries as dependency? If that's the case, your application will not exit. A full log will be also very helpful.

The camel context initiates shutdown immediately after application start, with no apparent error

My spring-boot app starts a Camel route that consumes from a Kafka-enabled Azure event hub. Immediately after the message that the Application has started, this message is logged: "INFO o.a.camel.spring.SpringCamelContext - Apache Camel 2.24.0 (CamelContext: camel-1) is shutting down".
Then any in-flight exchanges (if they exist) are successfully processed by the Camel route, and eventually the route is shutdown (gracefully), which also terminates the app.
No error messages are shown, nothing seems to be wrong, except that the shutdown is initiated automatically right after the application starts....
Any idea why this happens ?
I have played around with the timeouts for Kafka, but there's no change in behavior.
I have set the logging level to TRACE, but still I don't see why shutdown is initiated.
Among others, I use these libraries: spring-boot-starter, spring-boot-starter-web, azure-servicebus-spring-boot-starter, camel-kafka, camel-spring-boot-starter, camel-undertow-starter
This is how the route starts:
from("kafka:dummytopic?brokers=dummy.servicebus.windows.net:9093&topic={{event.hubs.hub.magento}}&groupId={{event.hubs.consumer-group}}"
+ "&consumersCount=1"
+ "&autoOffsetReset=latest"
+ "&saslMechanism=PLAIN"
+ "&securityProtocol=SASL_SSL"
+ "&sslProtocol=TLSv1.2"
+ "&sslEnabledProtocols=TLSv1.2"
+ "&sslEndpointAlgorithm=HTTPS"
+ "&saslJaasConfig=" + saslJaasConfig
+ "&autoCommitEnable=true")
.....
Normally the route should keep running and polling the kafka Event Hub for events (and process them when they are available).
Instead, it initiates shutdown immediately (still successfully processing any in-flight exchanges) - it simply shuts down gracefully. No error messages.
Any help is appreciated!
PS: this is an extract from the trace log:
15:01:40.867 [main] INFO c.i.s.n.NotificationMicroserviceApplication - Started NotificationMicroserviceApplication in 10.516 seconds (JVM running for 14.643)
15:01:40.868 [main] TRACE o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'camelContext'
15:01:40.868 [main] TRACE o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'springApplicationAdminRegistrar'
15:01:40.868 [main] DEBUG o.a.camel.spring.SpringCamelContext - onApplicationEvent: org.springframework.boot.context.event.ApplicationStartedEvent[source=org.springframework.boot.SpringApplication#22aefae0]
15:01:40.870 [main] TRACE o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'camelContext'
15:01:40.870 [main] TRACE o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'springApplicationAdminRegistrar'
15:01:40.870 [main] DEBUG o.a.camel.spring.SpringCamelContext - onApplicationEvent: org.springframework.boot.context.event.ApplicationReadyEvent[source=org.springframework.boot.SpringApplication#22aefae0]
15:01:40.872 [Thread-37] DEBUG o.s.c.a.AnnotationConfigApplicationContext - Closing org.springframework.context.annotation.AnnotationConfigApplicationContext#2cd2a21f, started on Thu Jun 06 15:01:31 EEST 2019
15:01:40.873 [Thread-37] TRACE o.s.c.e.PropertySourcesPropertyResolver - Searching for key 'spring.liveBeansView.mbeanDomain' in PropertySource 'configurationProperties'
15:01:40.873 [Thread-37] TRACE o.s.c.e.PropertySourcesPropertyResolver - Searching for key 'spring.liveBeansView.mbeanDomain' in PropertySource 'systemProperties'
15:01:40.873 [Thread-37] DEBUG o.s.c.e.PropertySourcesPropertyResolver - Found key 'spring.liveBeansView.mbeanDomain' in PropertySource 'systemProperties' with value of type String
15:01:40.874 [Thread-37] TRACE o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'camelContext'
15:01:40.874 [Thread-37] TRACE o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'springApplicationAdminRegistrar'
15:01:40.875 [Thread-37] DEBUG o.a.camel.spring.SpringCamelContext - onApplicationEvent: org.springframework.context.event.ContextClosedEvent[source=org.springframework.context.annotation.AnnotationConfigApplicationContext#2cd2a21f, started on Thu Jun 06 15:01:31 EEST 2019]
15:01:40.877 [Thread-37] TRACE o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'camelContext'
15:01:40.877 [Thread-37] TRACE o.s.b.f.s.DefaultListableBeanFactory - Returning cached instance of singleton bean 'lifecycleProcessor'
15:01:40.879 [Thread-37] DEBUG o.s.c.s.DefaultLifecycleProcessor - Stopping beans in phase 2147483647
15:01:40.879 [Thread-37] TRACE o.s.c.s.DefaultLifecycleProcessor - Stopping bean 'camelContext' of type [org.apache.camel.spring.SpringCamelContext]
15:01:40.879 [Thread-37] INFO o.a.camel.spring.SpringCamelContext - Apache Camel 2.24.0 (CamelContext: camel-1) is shutting down
15:01:40.879 [Thread-37] TRACE org.apache.camel.util.ServiceHelper - Stopping service org.apache.camel.impl.DefaultRouteController#108b121f
15:01:40.879 [Thread-37] TRACE org.apache.camel.util.ServiceHelper - Shutting down service org.apache.camel.impl.DefaultRouteController#108b121f
15:01:40.879 [Thread-37] TRACE o.a.camel.support.ServiceSupport - Service already stopped
15:01:40.880 [Thread-37] INFO o.a.c.impl.DefaultShutdownStrategy - Starting to graceful shutdown 1 routes (timeout 300 seconds)
15:01:40.880 [Thread-37] TRACE o.a.c.m.DefaultManagementLifecycleStrategy - Checking whether to register org.apache.camel.util.concurrent.RejectableThreadPoolExecutor#11ee4d34[Running, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0][ShutdownTask] from route: null
15:01:40.880 [Thread-37] DEBUG o.a.c.i.DefaultExecutorServiceManager - Created new ThreadPool for source: org.apache.camel.impl.DefaultShutdownStrategy#58b97c15 with name: ShutdownTask. -> org.apache.camel.util.concurrent.RejectableThreadPoolExecutor#11ee4d34[Running, pool size = 0, active threads = 0, queued tasks = 0, completed tasks = 0][ShutdownTask]
15:01:41.073 [Thread-37] TRACE o.a.c.u.c.CamelThreadFactory - Created thread[Camel (camel-1) thread #2 - ShutdownTask] -> Thread[Camel (camel-1) thread #2 - ShutdownTask,5,main]
15:01:41.075 [Camel (camel-1) thread #2 - ShutdownTask] DEBUG o.a.c.impl.DefaultShutdownStrategy - There are 1 routes to shutdown
15:01:41.075 [Camel (camel-1) thread #2 - ShutdownTask] TRACE o.a.c.impl.DefaultShutdownStrategy - Shutting down route: routeEventHub with options [Default,CompleteCurrentTaskOnly]
You can see that at 15:01:40.872 it starts closing things down...
I had the same problem, for me case the solution it was add the next depency into pom file.
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency>
There is no thread that keeps the application alive. That's why it immediately shutsdown.
You may want to add spring-boot-starter-web to have a web container that is running or you could have a loop in our main class that prevents the shutdown.
I would go for the web container. So you could also add the actuator framework with some diagnostic information.
This is related to spring version upgrade.
The problem described is related to conflicts between different Maven dependencies. I've had the same problem while trying to use the latest version of Spring Boot with Apache Camel.
After analyzing the dependency tree, it turned out that the version of spring-webmvc was 5.2.9, while all other spring dependencies were of version 5.2.8.
I have solved the problem by using a newer version of camel-spring-boot-dependencies (3.6.0)
Eventually, this solution worked:
#Slf4j
#SpringBootApplication
public class NotificationMicroserviceApplication implements CommandLineRunner {
public static void main(String[] args) {
SpringApplication.run(NotificationMicroserviceApplication.class, args);
}
#Override
public void run(String... args) throws Exception {
log.info("You can press Ctrl+C anytime to shutdown application");
Thread.currentThread().join();
}
}

rabbitConnectionFactory autodetected for JMX exposure

I have a Spring Boot application that supports Kafka. Recently I am trying to make it also support RabbitMQ. I set up the code using the #Profile annotation so that all the new code for RabbitMQ should be active only if I select spring.profiles.active to be rabbit-mq. Likewise, the Kafka-specific code are marked out by profile value of kafka
I was surprise to see that even with the above setup, when I set the profile to be kafka, some RabbitMQ is still included and activated, through a mechanism JMX exposure. Specifically, a rabbitConnectionFactory bean was constructed, and then it tried to do health check with a RabbitMQ broker at localhost:5672, and failed.
In the log file, I saw these messages:
... o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
... o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'rabbitConnectionFactory' has been autodetected for JMX exposure
... o.s.j.e.a.AnnotationMBeanExporter : Located managed bean 'rabbitConnectionFactory': registering with JMX server as MBean [org.springframework.amqp.rabbit.connection:name=rabbitConnectionFactory,type=CachingConnectionFactory]
... o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 2147483547
... o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 2147483647
... o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
... c.s.datacomparatorproducer.Application : Started Application in 5.175 seconds (JVM running for 5.663)
... o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring FrameworkServlet 'dispatcherServlet'
... o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization started
... o.s.web.servlet.DispatcherServlet : FrameworkServlet 'dispatcherServlet': initialization completed in 15 ms
... o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [localhost:5672]
... o.s.b.a.amqp.RabbitHealthIndicator : Rabbit health check failed
org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:62) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:476) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:614) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.createConnection(ConnectionFactoryUtils.java:240) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1797) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1771) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
I have two questions:
How can I avoid RabbitMQ code from being included? Why my set up using #Profile did not work as expected?
How do I configure the rabbitConnectionFactory? Currently it is trying to talk to localhost:5672. I know how to, in general, set up Spring template to use application-xxx.properties for spring.rabbitmq.{host,port}, but in this case, since the code is auto-included, I don't know how to configure rabbitConnectionFactory
Usual configuration
spring.rabbitmq.host=someRabbitBroker
spring.rabbitmq.port=5672
Update
Attempt 1: Excluding RabbitAutoConfiguration
Thank you Gary Russell for the suggestion. I tried his method and changed my #SpringBootApplication as follows. The idea here is to exclude RabbitAutoConfiguration when spring.rabbitmq.host is NOT defined (when the profile of rabbit-mq is not active):
#SpringBootApplication
public class Application {
#ConditionalOnProperty(value="spring.rabbitmq.host")
#Bean
RabbitAutoConfiguration rabbitAutoConfiguration(){
return new RabbitAutoConfiguration();
}
public static void main(String[] args) {
SpringApplication.run(Application.class, args);
}
}
I am not sure if this code is the correct way to do it, but it did not work. When my app started, I still saw these in the message:
... o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
... o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'rabbitConnectionFactory' has been autodetected for JMX exposure
... o.s.j.e.a.AnnotationMBeanExporter : Located managed bean 'rabbitConnectionFactory': registering with JMX server as MBean [org.springframework.amqp.rabbit.connection:name=rabbitConnectionFactory,type=CachingConnectionFactory]
... o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 2147483547
I am okay with having the bean constructed, as long as I can stop it from doing health check (or at least configure it to use my designated host and port). Is there a way to do this?
You either need to exclude the spring-rabbit jar from the classpath or disable rabbitmq auto-configuration by excluding RabbitAutoConfiguration from the #SpringBootApplication.
Update: disabling health check
See the boot properties documentation. Specifically set management.health.rabbit.enabled to false

Spring Boot Application issue with rabbitmq in docker

I am trying to build a event driven microservice with spring cloud stream using rabbitmq. In my case, rabbitmq is running in docker.
Docker commands used to run below container
docker run -d --hostname my-rabbit --name some-rabbit --publish 15672:15672 rabbitmq:3
Then going to bash mode of container I fired below command:
rabbitmq-plugins enable rabbitmq_management
in order to start management-plugin
CONTAINER ID IMAGE COMMAND CREATED STATUS PORTS NAMES
b2bc315c44aa rabbitmq:3 "docker-entrypoint..." 7 minutes ago Up 7 minutes 4369/tcp, 5671-5672/tcp, 25672/tcp, 0.0.0.0:15672->15672/tcp some-rabbit
So I can access docker from browser on localhost:15672
But when I start the Spring Boot application it is not making queue and exchange. Please check the stack trace.
Stack-trace
o.s.i.codec.kryo.CompositeKryoRegistrar : configured Kryo registration [40, java.io.File] with serializer org.springframework.integration.codec.kryo.FileSerializer
o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'rabbitConnectionFactory' has been autodetected for JMX exposure
o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'integrationMbeanExporter' has been autodetected for JMX exposure
o.s.j.e.a.AnnotationMBeanExporter : Located managed bean 'integrationMbeanExporter': registering with JMX server as MBean [org.springframework.integration.monitor:name=integrationMbeanExporter,type=IntegrationMBeanExporter]
o.s.j.e.a.AnnotationMBeanExporter : Located managed bean 'rabbitConnectionFactory': registering with JMX server as MBean [org.springframework.amqp.rabbit.connection:name=rabbitConnectionFactory,type=CachingConnectionFactory]
o.s.i.monitor.IntegrationMBeanExporter : Registering beans for JMX exposure on startup
o.s.i.monitor.IntegrationMBeanExporter : Registering MessageChannel nullChannel
o.s.i.monitor.IntegrationMBeanExporter : Located managed bean 'org.springframework.integration:type=MessageChannel,name=nullChannel': registering with JMX server as MBean [org.springframework.integration:type=MessageChannel,name=nullChannel]
o.s.i.monitor.IntegrationMBeanExporter : Registering MessageChannel output
o.s.i.monitor.IntegrationMBeanExporter : Located managed bean 'org.springframework.integration:type=MessageChannel,name=output': registering with JMX server as MBean [org.springframework.integration:type=MessageChannel,name=output]
o.s.i.monitor.IntegrationMBeanExporter : Registering MessageChannel errorChannel
o.s.i.monitor.IntegrationMBeanExporter : Located managed bean 'org.springframework.integration:type=MessageChannel,name=errorChannel': registering with JMX server as MBean [org.springframework.integration:type=MessageChannel,name=errorChannel]
o.s.i.monitor.IntegrationMBeanExporter : Registering MessageHandler errorLogger
o.s.i.monitor.IntegrationMBeanExporter : Located managed bean 'org.springframework.integration:type=MessageHandler,name=errorLogger,bean=internal': registering with JMX server as MBean [org.springframework.integration:type=MessageHandler,name=errorLogger,bean=internal]
o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase -2147482648
r.t.b.demo.source.GatewayApplication : No active profile set, falling back to default profiles: default
s.c.a.AnnotationConfigApplicationContext : Refreshing org.springframework.context.annotation.AnnotationConfigApplicationContext#56cfe111: startup date [Mon May 29 15:07:40 JST 2017]; parent: org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#4fe767f3
o.s.c.support.GenericApplicationContext : Refreshing org.springframework.context.support.GenericApplicationContext#67de7a99: startup date [Mon May 29 15:07:40 JST 2017]; root of context hierarchy
r.t.b.demo.source.GatewayApplication : Started GatewayApplication in 0.189 seconds (JVM running for 10.957)
o.s.amqp.rabbit.core.RabbitAdmin : Failed to declare exchange: Exchange [name=output, type=topic, durable=true, autoDelete=false, internal=false, arguments={}], continuing... org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused
o.s.integration.channel.DirectChannel : Channel 'gateway:8181.output' has 1 subscriber(s).
o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 0
o.s.i.endpoint.EventDrivenConsumer : Adding {logging-channel-adapter:_org.springframework.integration.errorLogger} as a subscriber to the 'errorChannel' channel
o.s.i.channel.PublishSubscribeChannel : Channel 'gateway:8181.errorChannel' has 1 subscriber(s).
o.s.i.endpoint.EventDrivenConsumer : started _org.springframework.integration.errorLogger
o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 2147482647
o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 2147483647
s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 8181 (http)
Thanks in advance.
You need to use the Docker image for RabbitMQ that has the management plugin (see https://hub.docker.com/_/rabbitmq/), in your case rabbitmq:3-management.
I have been wrestling with using rabbit mq running in docker and I think you will need to make some entries in your spring boot application.properties file to overcome the connection problem.
It looks like your exchange is not being created due to connection refused. You need to overcome that. In the rabbit web admin console you will need to create a user with permissions. Then add some configuration in application.properties :
spring.rabbitmq.port=5672
spring.rabbitmq.username=the_user_name
spring.rabbitmq.password=user_password
Good luck.

Sonarqube Webapp did not start

I am installing SN5.5 using PostgreSQL9.5 under Windows. Unfortunately, I am hitting error "Webapp did not start".
Below is the full stack trace. I think I got the error first at line "Exception sending context initialized event to listener instance of class org.sonar.server.platform.PlatformServletContextListener"
2016.05.19 18:10:59 INFO web[o.a.c.h.Http11NioProtocol] Initializing ProtocolHandler ["http-nio-0.0.0.0-9000"]
2016.05.19 18:10:59 INFO web[o.a.t.u.n.NioSelectorPool] Using a shared selector for servlet write/read
2016.05.19 18:11:00 INFO web[o.s.s.p.ServerImpl] SonarQube Server / 5.5 / 5773a4aab0ef6c0de79d3038e82f8a051049d6d0
2016.05.19 18:11:00 INFO web[o.sonar.db.Database] Create JDBC data source for jdbc:postgresql://localhost/sonar
2016.05.19 18:11:01 ERROR web[o.a.c.c.C.[.[.[/]] Exception sending context initialized event to listener instance of class org.sonar.server.platform.PlatformServletContextListener
org.sonar.api.utils.MessageException: Current version is too old. Please upgrade to Long Term Support version firstly.
2016.05.19 18:11:01 ERROR web[o.a.c.c.StandardContext] One or more listeners failed to start. Full details will be found in the appropriate container log file
2016.05.19 18:11:01 ERROR web[o.a.c.c.StandardContext] Context [] startup failed due to previous errors
2016.05.19 18:11:01 WARN web[o.a.c.l.WebappClassLoaderBase] The web application [ROOT] appears to have started a thread named [Timer-0] but has failed to stop it. This is very likely to create a memory leak. Stack trace of thread:
java.lang.Object.wait(Native Method)
java.util.TimerThread.mainLoop(Timer.java:552)
java.util.TimerThread.run(Timer.java:505)
2016.05.19 18:11:01 INFO web[o.a.c.h.Http11NioProtocol] Starting ProtocolHandler ["http-nio-0.0.0.0-9000"]
2016.05.19 18:11:01 INFO web[o.s.s.a.TomcatAccessLog] Web server is started
2016.05.19 18:11:01 INFO web[o.s.s.a.EmbeddedTomcat] HTTP connector enabled on port 9000
2016.05.19 18:11:01 WARN web[o.s.p.ProcessEntryPoint] Fail to start web
java.lang.IllegalStateException: Webapp did not start
at org.sonar.server.app.EmbeddedTomcat.isUp(EmbeddedTomcat.java:84) ~[sonar-server-5.5.jar:na]
at org.sonar.server.app.WebServer.isUp(WebServer.java:48) [sonar-server-5.5.jar:na]
at org.sonar.process.ProcessEntryPoint.launch(ProcessEntryPoint.java:105) ~[sonar-process-5.5.jar:na]
at org.sonar.server.app.WebServer.main(WebServer.java:69) [sonar-server-5.5.jar:na]
2016.05.19 18:11:01 INFO web[o.a.c.h.Http11NioProtocol] Pausing ProtocolHandler ["http-nio-0.0.0.0-9000"]
2016.05.19 18:11:02 INFO web[o.a.c.h.Http11NioProtocol] Stopping ProtocolHandler ["http-nio-0.0.0.0-9000"]
2016.05.19 18:11:02 INFO web[o.a.c.h.Http11NioProtocol] Destroying ProtocolHandler ["http-nio-0.0.0.0-9000"]
2016.05.19 18:11:02 INFO web[o.s.s.a.TomcatAccessLog] Web server is stopped
2016.05.19 18:11:03 INFO app[o.s.p.m.Monitor] Process[es] is stopping
2016.05.19 18:11:03 INFO es[o.s.p.StopWatcher] Stopping process
2016.05.19 18:11:03 INFO es[o.elasticsearch.node] [sonar-1463652653150] stopping ...
2016.05.19 18:11:03 INFO es[o.elasticsearch.node] [sonar-1463652653150] stopped
2016.05.19 18:11:03 INFO es[o.elasticsearch.node] [sonar-1463652653150] closing ...
2016.05.19 18:11:03 INFO es[o.elasticsearch.node] [sonar-1463652653150] closed
2016.05.19 18:11:04 INFO app[o.s.p.m.Monitor] Process[es] is stopped
<-- Wrapper Stopped
org.sonar.api.utils.MessageException: Current version is too old. Please upgrade to Long Term Support version firstly.
This log means than you're trying to upgrade to a too recent version. You should first upgrade to the nearest LTS version (probably 4.5.X), then you'll be able to upgrade to 5.5.
See http://docs.sonarqube.org/display/SONAR/Upgrading for more information about the upgrade strategy.
You can try adding below properties in wrapper.conf file. It did the trick for me.
# Java Additional Parameter
wrapper.java.additional.1=-Djava.awt.headless=true
wrapper.java.additional.2=-XX:MaxPermSize=160m
wrapper.java.additional.3=-XX:+HeapDumpOnOutOfMemoryError
wrapper.java.additional.4=-Dfile.encoding=UTF-8
wrapper.java.additional.5=-Djruby.management.enabled=false
# Maximum amount of memory of Java VM
wrapper.java.additional.6=-Xmx2048M

Resources