spring config server not posting to rabbitmq - spring-boot

I've generated a spring boot config server from spring's initialzr.
I've installed rabbitmq with brew. initialzr generated with boot version 2.1.1.RELEASE and cloud version Greenwich.M3.
the simple rest services are connecting to rabbitmq queues. the config server is connection to a gitlab config repo.
But when I commit and push a change to it, the change is not reflected by the service application. The config server gets logs messages when the push is completed. Can anyone say what might be wrong? No messages ever seem to appear in rabbitmq console. I have been able to refresh the properties via actuator/bus-refresh through rabbitmq though.
config-server log messages on commit of change to config-repo's employee-service.yml file:
2018-12-07 11:53:12.185 INFO 84202 --- [nio-8888-exec-1] o.s.c.c.monitor.PropertyPathEndpoint : Refresh for: employee:service
2018-12-07 11:53:12.228 INFO 84202 --- [nio-8888-exec-1] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$b43cc593] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-12-07 11:53:12.253 INFO 84202 --- [nio-8888-exec-1] o.s.boot.SpringApplication : No active profile set, falling back to default profiles: default
2018-12-07 11:53:12.259 INFO 84202 --- [nio-8888-exec-1] o.s.boot.SpringApplication : Started application in 0.072 seconds (JVM running for 3075.606)
2018-12-07 11:53:12.345 INFO 84202 --- [nio-8888-exec-1] o.s.cloud.bus.event.RefreshListener : Received remote refresh request. Keys refreshed []
2018-12-07 11:53:12.345 INFO 84202 --- [nio-8888-exec-1] o.s.c.c.monitor.PropertyPathEndpoint : Refresh for: employee-service
2018-12-07 11:53:12.377 INFO 84202 --- [nio-8888-exec-1] trationDelegate$BeanPostProcessorChecker : Bean 'configurationPropertiesRebinderAutoConfiguration' of type [org.springframework.cloud.autoconfigure.ConfigurationPropertiesRebinderAutoConfiguration$$EnhancerBySpringCGLIB$$b43cc593] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2018-12-07 11:53:12.398 INFO 84202 --- [nio-8888-exec-1] o.s.boot.SpringApplication : No active profile set, falling back to default profiles: default
2018-12-07 11:53:12.402 INFO 84202 --- [nio-8888-exec-1] o.s.boot.SpringApplication : Started application in 0.056 seconds (JVM running for 3075.749)
2018-12-07 11:53:12.489 INFO 84202 --- [nio-8888-exec-1] o.s.cloud.bus.event.RefreshListener : Received remote refresh request. Keys refreshed []
config-server has this application.yml:
---
server:
port: ${PORT:8888}
spring:
cloud:
bus:
enabled: true
config:
server:
git:
uri: ${CONFIG_REPO_URI:git#gitlab.<somedomain>:<somegroup>/config-repo.git}
search-paths:
- feature/initial-repo
main:
banner-mode: "off"
and ConfigServerApplication.java:
#SpringBootApplication
#EnableConfigServer
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
and these gradle dependencies:
dependencies {
implementation('org.springframework.cloud:spring-cloud-config-server')
implementation('org.springframework.cloud:spring-cloud-starter-stream-rabbit')
implementation('org.springframework.cloud:spring-cloud-config-monitor')
testImplementation('org.springframework.boot:spring-boot-starter-test')
implementation('org.springframework.cloud:spring-cloud-stream-test-support')
}
service has this applciation.yml:
---
server:
port: 8092
management:
security:
enabled: "false"
endpoints:
web:
exposure:
include:
- '*'
spring:
main:
banner-mode: "off"
rabbitmq:
host: localhost
port: 5672
username: guest
password: guest
this bootstrap.yml:
---
spring:
application:
name: employee-service
cloud:
config:
uri:
- http://localhost:8888
label: feature(_)initial-repo
these gradle dependencies:
dependencies {
implementation('org.springframework.boot:spring-boot-starter-web')
implementation('org.springframework.cloud:spring-cloud-starter-config')
implementation('org.springframework.cloud:spring-cloud-starter-bus-amqp')
implementation('org.springframework.boot:spring-boot-starter-actuator')
testImplementation('org.springframework.boot:spring-boot-starter-test')
}
this main class:
#SpringBootApplication
public class EmployeeServiceApplication {
public static void main(String[] args) {
SpringApplication.run(EmployeeServiceApplication.class, args);
}
}
and this controller class:
#RefreshScope
#RestController
public class WelcomeController {
#Value("${app.service-name}")
private String serviceName;
#Value("${app.shared.attribute}")
private String sharedAttribute;
#GetMapping("/service")
public String getServiceName() {
return "service name [" + this.serviceName + "]";
}
#GetMapping("/shared")
public String getSharedAttribute() {
return " application.yml [" + this.sharedAttribute + "]";
}
}

Try to create and build your project with Maven instead of Gradle.
I experience the same problem. I have two identical apps with the same RabbitMQ dependencies, one is build with Maven and second with Gradle. The Maven-based app publishes things to RabbitMQ as expected. The very same app, built with Gradle doesn't establish connection to RabbitMQ and is not publishing events.
To further clarify things, I run both apps in Eclipse with Spring Tools.

Related

Spring boot H2 console returns 404

I have a simple Springboot application and it's up running. I am able to call REST endpoints through Postman. However, when I try to access the console using http://localhost:8080/h2 it keeps returning 404.
2020-08-29 08:06:37.577 INFO 6507 --- [ main] o.hibernate.jpa.internal.util.LogHelper : HHH000204: Processing PersistenceUnitInfo [
name: default
...]
2020-08-29 08:06:37.644 INFO 6507 --- [ main] org.hibernate.Version : HHH000412: Hibernate Core {5.2.17.Final}
2020-08-29 08:06:37.645 INFO 6507 --- [ main] org.hibernate.cfg.Environment : HHH000206: hibernate.properties not found
2020-08-29 08:06:37.677 INFO 6507 --- [ main] o.hibernate.annotations.common.Version : HCANN000001: Hibernate Commons Annotations {5.0.1.Final}
2020-08-29 08:06:37.787 INFO 6507 --- [ main] org.hibernate.dialect.Dialect : HHH000400: Using dialect: org.hibernate.dialect.H2Dialect
2020-08-29 08:06:38.247 INFO 6507 --- [ main] j.LocalContainerEntityManagerFactoryBean : Initialized JPA EntityManagerFactory for persistence unit 'default'
2020-08-29 08:06:38.737 INFO 6507 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2020-08-29 08:06:38.738 INFO 6507 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'dataSource' has been autodetected for JMX exposure
2020-08-29 08:06:38.741 INFO 6507 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Located MBean 'dataSource': registering with JMX server as MBean [com.zaxxer.hikari:name=dataSource,type=HikariDataSource]
2020-08-29 08:06:38.813 INFO 6507 --- [ctor-http-nio-1] r.ipc.netty.tcp.BlockingNettyContext : Started HttpServer on /0:0:0:0:0:0:0:0:8080
2020-08-29 08:06:38.813 INFO 6507 --- [ main] o.s.b.web.embedded.netty.NettyWebServer : Netty started on port(s): 8080
2020-08-29 08:06:38.816 INFO 6507 --- [ main] c.v.t.c.m.tenant.discovery.Application : Started Application in 3.4 seconds (JVM running for 3.661)
2020-08-29 08:06:48.527 WARN 6507 --- [ctor-http-nio-2] .a.w.r.e.DefaultErrorWebExceptionHandler : Failed to handle request [GET http://localhost:8080/h2]: Response status 404
2020-08-29 08:23:07.301 WARN 6507 --- [l-1 housekeeper] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Retrograde clock change detected (housekeeper delta=29s626ms), soft-evicting connections from pool.
2020-08-29 08:57:06.586 WARN 6507 --- [l-1 housekeeper] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Thread starvation or clock leap detected (housekeeper delta=33m59s284ms).
2020-08-29 09:35:49.699 WARN 6507 --- [l-1 housekeeper] com.zaxxer.hikari.pool.HikariPool : HikariPool-1 - Thread starvation or clock leap detected (housekeeper
My application.yml file looks like this.
spring:
datasource:
url: jdbc:h2:mem:test
platform: h2
username: sa
password:
driverClassName: org.h2.Driver
hikari:
maximum-pool-size: 50
h2:
console:
enabled: true
path: /h2
settings:
web-allow-others: true
jpa:
database-platform: org.hibernate.dialect.H2Dialect
hibernate:
ddl-auto: update
server:
port: 8080
As per your logs, I found that, you are using an embedded server, other than tomcat, i.e, spring-boot-starter-reactor-netty that comes along with spring webflux dependency.
H2ConsoleAutoConfiguration will not be executed for spring webflux & netty(reactor based), as H2 console will only be available to servlet based applications. So, you have to configure H2 server manually in this spring boot application, with spring webflux & netty.
Sample H2Server (working code):
package com.example.springbootnettyserver;
import org.h2.tools.Server;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.stereotype.Component;
import static org.h2.tools.Server.createWebServer;
#Component
public class H2ServerManual {
Logger log = LoggerFactory.getLogger(H2ServerManual.class);
private Server webServer;
#Value("${h2-server.port}")
Integer h2ConsolePort;
#EventListener(ContextRefreshedEvent.class)
public void start() throws java.sql.SQLException {
log.info("starting h2 console at port "+ h2ConsolePort);
this.webServer = createWebServer("-webPort", h2ConsolePort.toString(),
"-tcpAllowOthers").start();
System.out.println(webServer.getURL());
}
#EventListener(ContextClosedEvent.class)
public void stop() {
log.info("stopping h2 console at port "+h2ConsolePort);
this.webServer.stop();
}
}
Note: org.h2.tools.Server class will be resolved only when h2 dependency is added without scope of runtime. (remove scope element in dependency)
In application.properties, you will add port details for h2 server like
h2-server:
port: 8081
Here, now, the H2 console will be available at http://localhost:8081
Following properties can be removed
# h2:
# console:
# enabled: true
# path: /h2
# settings:
# web-allow-others: true
For Reference: https://github.com/donthadineshkumar/webflux-netty-server-h2-example.git

How to move Zuul gateway configurations to configuration server

I'm starting out with microservices architecture and spring cloud.
I'm trying to get configurations for my Spring Zuul Gateway from the spring configuration server.
I've added below properties in bootstrap.properties file of the gateway service:
spring.application.name=api-gateway
spring.cloud.config.uri=http://localhost:8888
spring.profiles.active=dev
Even though these properties work for all other services, for the gateway they do not work.
The annotations I'm using for the gateway are:
#EnableZuulProxy
#EnableDiscoveryClient
#SpringBootApplication
public class ApiGatewayApplication {
public static void main(String[] args) {
SpringApplication.run(ApiGatewayApplication.class, args);
}
}
The annotation for other services is only:
#SpringBootApplication
My configuration server has a connected git repository with a file: api-gateway-dev.properties
logs of gateway:
:: Spring Boot :: (v2.3.0.M4)
2020-04-17 21:42:39.983 INFO 10340 --- [ restartedMain]
c.nyo.apigateway.ApiGatewayApplication : The following profiles are
active: dev 2020-04-17 21:42:41.926 WARN 10340 --- [ restartedMain]
o.s.boot.actuate.endpoint.EndpointId : Endpoint ID
'service-registry' contains invalid characters, please migrate to a
valid format. 2020-04-17 21:42:41.969 WARN 10340 --- [
restartedMain] o.s.boot.actuate.endpoint.EndpointId : Endpoint ID
'hystrix.stream' contains invalid characters, please migrate to a
valid format. 2020-04-17 21:42:42.240 INFO 10340 --- [
restartedMain] o.s.cloud.context.scope.GenericScope : BeanFactory
id=a11a283e-7de6-3470-b177-65c08eab7398 2020-04-17 21:42:43.859 INFO
10340 --- [ restartedMain] o.s.b.w.embedded.tomcat.TomcatWebServer :
Tomcat initialized with port(s): 8765 (http) 2020-04-17 21:42:43.880
INFO 10340 --- [ restartedMain]
o.apache.catalina.core.StandardService : Starting service [Tomcat]
logs of a service that is getting configurations:
:: Spring Boot :: (v2.3.0.M4)
2020-04-17 21:54:01.414 INFO 5180 --- [ restartedMain]
c.c.c.ConfigServicePropertySourceLocator : Fetching config from server
at : http://localhost:8888 2020-04-17 21:54:04.184 INFO 5180 --- [
restartedMain] c.c.c.ConfigServicePropertySourceLocator : Located
environment: name=users-service, profiles=[dev], label=null,
version=244114f5a11aa7d4a0acb5750ddad144f7de1be5, state=null
2020-04-17 21:54:04.186 INFO 5180 --- [ restartedMain]
b.c.PropertySourceBootstrapConfiguration : Located property source:
[BootstrapPropertySource {name='bootstrapProperties-configClient'},
BootstrapPropertySource
{name='bootstrapProperties-https://my-user#bitbucket.org/my-user/configs.git/users-service-dev.properties'},
BootstrapPropertySource
{name='bootstrapProperties-https://my-user#bitbucket.org/my-user/configs.git/users-service.properties'}]
2020-04-17 21:54:04.197 INFO 5180 --- [ restartedMain]
c.n.U.UsersServiceApplication : The following profiles are
active: dev
Is it logical to make gateway configuration dynamic?
Why don't I get the configuration from the configuration server?
Found the problem. I was missing:
implementation 'org.springframework.cloud:spring-cloud-starter-config'
in my build.gradle file dependencies

Unable to add my micro service as Eureka Client

I have set a sample Micro Service using 3 spring boot applications. Post that I am trying to connect all of them to Eureka Server.
There are 3 spring Boot Applications Task-Display,Task-Repo and Task-Status-Repo.
Task Display communicates with the other two and retrieve data.
Now Problem is except Task-Display all others are linked to eureka server. Getting the following error when Task Display is deployed
2019-08-31 18:43:00.055 INFO 15528 --- [tbeatExecutor-0]
com.netflix.discovery.DiscoveryClient : DiscoveryClient_TASK-DISPLAY-
ME;/192.168.1.9:task-display-me;:8180 - Re-registering apps/TASK-DISPLAY-
ME;
2019-08-31 18:43:00.055 INFO 15528 --- [tbeatExecutor-0]
com.netflix.discovery.DiscoveryClient : DiscoveryClient_TASK-DISPLAY-
ME;/192.168.1.9:task-display-me;:8180: registering service...
2019-08-31 18:43:00.057 WARN 15528 --- [tbeatExecutor-0]
c.n.d.s.t.d.RetryableEurekaHttpClient : Request execution failure with
status code 400; retrying on another server if available
2019-08-31 18:43:00.059 WARN 15528 --- [tbeatExecutor-0]
c.n.d.s.t.d.RetryableEurekaHttpClient : Request execution failure with
status code 400; retrying on another server if available
2019-08-31 18:43:00.060 WARN 15528 --- [tbeatExecutor-0]
com.netflix.discovery.DiscoveryClient : DiscoveryClient_TASK-DISPLAY-
ME;/192.168.1.9:task-display-me;:8180 - registration failed Cannot execute
request on any known server
com.netflix.discovery.shared.transport.TransportException: Cannot execute
request on any known server
This is my Application.java of the server which is not getting linked to Eureka
#SpringBootApplication
#EnableEurekaClient
public class TaskDisplayApplication {
public static void main(String[] args) {
SpringApplication.run(TaskDisplayApplication.class, args);
}
#LoadBalanced
#Bean
public RestTemplate getRestTemplate() {
return new RestTemplate();
}
}

Spring Reactive MongoDB not saving document

I'm trying to save a basic document but despite connecting to mongodb successfully... It doesn't seem to want to save.
Spring logs
2018-10-03 00:17:25.998 INFO 10713 --- [ restartedMain] o.s.b.d.a.OptionalLiveReloadServer : LiveReload server is running on port 35729
2018-10-03 00:17:26.049 INFO 10713 --- [ restartedMain] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-10-03 00:17:26.106 INFO 10713 --- [ctor-http-nio-1] r.ipc.netty.tcp.BlockingNettyContext : Started HttpServer on /0:0:0:0:0:0:0:0:8080
2018-10-03 00:17:26.106 INFO 10713 --- [ restartedMain] o.s.b.web.embedded.netty.NettyWebServer : Netty started on port(s): 8080
2018-10-03 00:17:26.112 INFO 10713 --- [ restartedMain] c.l.s.ServiceLegalApplicationKt : Started ServiceLegalApplicationKt in 3.459 seconds (JVM running for 4.201)
2018-10-03 00:17:26.644 INFO 10713 --- [ntLoopGroup-2-2] org.mongodb.driver.connection : Opened connection [connectionId{localValue:3, serverValue:4}] to localhost:27017
application.properties
spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.database=legal
spring.data.mongodb.repositories.type=reactive
spring.mongodb.embedded.version=4.0.2
basic interface and class
interface EventRepository: ReactiveMongoRepository<Event, String>
#Document
class Event(id: String, name: String)
trying a simple save function
#Service
class SomeService(val eventRepository: EventRepository)
{
fun save() = eventRepository.save(Event(UUID.randomUUID().toString(), "hey"))
}
Mono<Event> response = repository.save(Event(UUID.randomUUID().toString(), "hey"));
Changes in save method
fun save() = eventRepository.save(Event(UUID.randomUUID().toString(), "hey")).subscribe();
You have to invoke subscribe() method on Mono reference to see the logs or details.
To make you stream terminal with subscribe() operation and to get the Mono result at the same time - split into two separate operations:
Mono<String> myEvent = eventRepository.save(Event(UUID.randomUUID().toString(), "hey"));
myEvent.subscribe();
return myEvent;
You can also call .block() on the returned Reactive mono
Mono<Event> reactiveEvent = repository.save(); reactiveEvent.block()
Also read this

CamelContextStartedEvent called twice

The CamelContextStartedEvent is called twice for the same camel context (camel-1). The issue might be the way I register the EventNotifier. You can reproduce the issue with Spring Initializr with Spring Boot 1.5.14, Spring Boot Camel Starter 2.21.1 and Spring Boot Web Starter.
See the logs:
2018-07-06 11:04:41.104 INFO 19092 --- [ main] o.a.camel.spring.SpringCamelContext : Apache Camel 2.21.1 (CamelContext: camel-1) is starting
2018-07-06 11:04:41.106 INFO 19092 --- [ main] o.a.c.m.ManagedManagementStrategy : JMX is enabled
2018-07-06 11:04:41.191 INFO 19092 --- [ main] o.a.camel.spring.SpringCamelContext : StreamCaching is not in use. If using streams then its recommended to enable stream caching. See more details at http://camel.apache.org/stream-caching.html
2018-07-06 11:04:41.193 INFO 19092 --- [ main] o.a.camel.spring.boot.RoutesCollector : Starting CamelMainRunController to ensure the main thread keeps running
2018-07-06 11:04:41.193 INFO 19092 --- [ main] o.a.camel.spring.SpringCamelContext : Total 0 routes, of which 0 are started
2018-07-06 11:04:41.194 INFO 19092 --- [ main] o.a.camel.spring.SpringCamelContext : Apache Camel 2.21.1 (CamelContext: camel-1) started in 0.090 seconds
2018-07-06 11:04:41.195 INFO 19092 --- [ main] c.e.bug.service.StartupEventNotifier : CamelContextStartedEvent for SpringCamelContext(camel-1) with spring id application:11223
2018-07-06 11:04:41.195 INFO 19092 --- [ main] c.e.bug.service.StartupEventNotifier : CamelContextStartedEvent for SpringCamelContext(camel-1) with spring id application:11223
2018-07-06 11:04:41.216 INFO 19092 --- [ main] s.b.c.e.t.TomcatEmbeddedServletContainer : Tomcat started on port(s): 11223 (http)
2018-07-06 11:04:41.221 INFO 19092 --- [ main] com.example.bug.BugApplication : Started BugApplication in 4.684 seconds (JVM running for 6.773)
The service that initializes the EventNotifier:
#Service
public class SchedulerService {
private final CamelContext camelContext;
private final StartupEventNotifier startupEventNotifier;
public SchedulerService(CamelContext camelContext, StartupEventNotifier startupEventNotifier) {
this.camelContext = camelContext;
this.startupEventNotifier = startupEventNotifier;
}
#PostConstruct
public void init() {
camelContext.getManagementStrategy().addEventNotifier(startupEventNotifier);
}
}
The EventNotifier:
#Component
public class StartupEventNotifier extends EventNotifierSupport {
private static final Logger logger = LoggerFactory.getLogger(StartupEventNotifier.class);
#Override
public void notify(EventObject event) throws Exception {
if (event instanceof CamelContextStartedEvent) {
logger.info("CamelContextStartedEvent for {}", event.getSource());
}
}
#Override
public boolean isEnabled(EventObject event) {
if (event instanceof CamelContextStartedEvent) {
return true;
}
return false;
}
}
application.yml:
camel:
springboot:
main-run-controller: true
server:
port: 11223
It is called twice, because it is registered twice. Once by you and once by Apache Camel. EventNotifier is registered automatically, if is found in Registry. Since your StartupEventNotifier is annotated as Component, it is part of Registry and Apache Camel registered it during CamelContext startup (You can see it in CamelAutoConfiguration line 424).
You have four options:
Remove your custom registration from SchedulerService.
Remove #Component annotation from StartupEventNotifier and register it with with camelContext.getManagementStrategy().addEventNotifier(new StartupEventNotifier())
Add duplicity check to your SchedulerService. Something like:
if (!context.getManagementStrategy().getEventNotifiers().contains(startupEventNotifier)){
context.getManagementStrategy().addEventNotifier(startupEventNotifier);
}
Register EventNotifier in #PostConstruct of RouteBuilder. It will be registered before automatic discovery is started and then it will be skipped in CamelAutoConfiguration (See line 422)

Resources