Spring Webscoket error javax.websocket.DeploymentException: Handshake error in nginx - spring

I using spring-boot-starter-websocket and run localhost is success. But i run in server with Nginx, Spring Gateway is not connected.
#Configuration
#EnableWebSocketMessageBroker
public class WebSocketConfig implements WebSocketMessageBrokerConfigurer {
#Override
public void configureMessageBroker(MessageBrokerRegistry registry) {
registry.setApplicationDestinationPrefixes("/app");
registry.enableSimpleBroker("/topic");
}
#Override
public void registerStompEndpoints(StompEndpointRegistry registry) {
registry.addEndpoint("/chat/").setAllowedOrigins("*")
.setHandshakeHandler(new DefaultHandshakeHandler(new TomcatRequestUpgradeStrategy()));
}
}
config:
Nginx port 80
gateway-service port 8000
message-service port 8540
client-> Nginx -> gateway-service -> message-service
Run localhost: ws://127.0.0.1:8540/chat/ is ok
Run server: ws://mydomain.xyz/message-service/chat/ error javax.websocket.DeploymentException: Handshake
Zull:
server:
port: 8000
spring:
application:
name: gateway-service
zuul:
ignoredServices: '*'
host:
connect-timeout-millis: 20000
socket-timeout-millis: 20000
routes:
profile-service:
path: /profile-service/**
serviceId: profile-service
stripPrefix: true
message-service:
path: /message-service/**
serviceId: message-service
stripPrefix: true
Error:
run:
javax.websocket.DeploymentException: Handshake error.
false
at org.glassfish.tyrus.client.ClientManager$1.run(ClientManager.java:446)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at org.glassfish.tyrus.client.ClientManager$SameThreadExecutorService.execute(ClientManager.java:620)
at java.util.concurrent.AbstractExecutorService.submit(AbstractExecutorService.java:112)
at org.glassfish.tyrus.client.ClientManager.connectToServer(ClientManager.java:351)
at org.glassfish.tyrus.client.ClientManager.connectToServer(ClientManager.java:241)
at sk.Main.setConnectWebsocket(Main.java:28)
at sk.Main.main(Main.java:18)
Caused by: org.glassfish.tyrus.core.HandshakeException: Response code was not 101: 400
at org.glassfish.tyrus.core.Handshake.validateServerResponse(Handshake.java:315)
at org.glassfish.tyrus.client.TyrusClientEngine.processResponse(TyrusClientEngine.java:133)
at org.glassfish.tyrus.container.grizzly.client.GrizzlyClientFilter.handleHandshake(GrizzlyClientFilter.java:306)
at org.glassfish.tyrus.container.grizzly.client.GrizzlyClientFilter.handleRead(GrizzlyClientFilter.java:280)
at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:288)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:206)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:136)
at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:114)
at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77)
at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:547)
at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:113)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:115)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:55)
at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:135)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565)
at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545)
at java.lang.Thread.run(Thread.java:748)
BUILD SUCCESSFUL (total time: 0 seconds)

Related

Eureka Server Hangs After few min of Service registration

I am creating a spring cloud setup. I have Eureka Server, Auth Server, Gateway and two Micro-services. I am using Zuul for Gateway. Below is configuration of Eureka Server:
Main Class
#SpringBootApplication
#EnableEurekaServer
#EnableAdminServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
Application properties:
server.port: 8761
spring.application.name: discovery-server
logging.level.org.springframework.cloud.netflix.eureka: TRACE
eureka.instance.hostname: localhost
eureka.client.registerWithEureka: false
eureka.client.fetchRegistry: false
eureka.client.serviceUrl.defaultZone:
http://${eureka.instance.hostname}:${server.port}/eureka/
spring.boot.admin.context-path= /admin
Gateway:
Main Class:
#SpringBootApplication
#EnableZuulProxy
#EnableOAuth2Sso
public class GatewayApplication {
public static void main(String[] args) {
SpringApplication.run(GatewayApplication.class, args);
}
}
properties:
server.port= 8765
spring.application.name= gateway-server
spring.jpa.database-platform= org.hibernate.dialect.MySQL5Dialect
spring.jpa.database= MYSQL
spring.jpa.open-in-view= false
spring.jpa.hibernate.ddl-auto= create
spring.jpa.properties.hibernate.implicit_naming_strategy=
org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl
spring.jpa.properties.hibernate.id.new_generator_mappings= false # id
generation defaults to table otherwise
spring.jpa.properties.hibernate.enable_lazy_load_no_trans= true
spring.jpa.properties.hibernate.generate_statistics= false
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.jdbc-url= jdbc:mysql://localhost:3306/cloudDB?
useUnicode=true&createDatabaseIfNotExist=true&useSSL=false
spring.datasource.username= root
spring.datasource.password= root
spring.datasource.dbcp2.max-idle= 10000
logging.level.org.springframework.cloud.netflix.zuul= TRACE
zuul.routes.uaa.path= /uaa/**
zuul.routes.uaa.sensitiveHeaders=""
zuul.routes.uaa.serviceId= auth-server
zuul.routes.account.path= /account/**
zuul.routes.account.sensitiveHeaders= ""
zuul.routes.account.serviceId= account-service
zuul.routes.customer.path= /customer/**
zuul.routes.customer.sensitiveHeaders=
zuul.routes.customer.serviceId= customer
zuul.routes.fsp.path= /fsp/**
zuul.routes.fsp.sensitiveHeaders=
zuul.routes.fsp.serviceId= fsp-marketplace
eureka.client.registerWithEureka= false
eureka.client.serviceUrl.defaultZone= http://localhost:8761/eureka/
security.oauth2.sso.loginPath= /uaa/login
security.oauth2.client.accessTokenUri= http://localhost:8765/uua/oauth/token
security.oauth2.client.userAuthorizationUri= http://localhost:8765/uua/oauth/authorize
security.oauth2.client.clientId= acem
security.oauth2.client.clientSecret= secret
security.oauth2.client.clientAuthenticationScheme= form
security.oauth2.resource.userInfoUri= http://localhost:8765/user
security.oauth2.resource.preferTokenInfo= false
security.sessions= ALWAYS
Micro Service:
#SpringBootApplication
#EnableAutoConfiguration
#EnableDiscoveryClient
public class FspApplication {
public static void main(String[] args) {
SpringApplication.run(FspApplication.class, args);
}
}
properties:
server.port= ${PORT:4444}
spring.application.name= fsp-marketplace
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
spring.jpa.database= MYSQL
spring.jpa.hibernate.ddl-auto= update
spring.jpa.properties.hibernate.implicit_naming_strategy=
org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.jdbc-url= jdbc:mysql://localhost:3306/cloudDB?
useUnicode=true&createDatabaseIfNotExist=true&useSSL=false
spring.datasource.username= root
spring.datasource.password= root
spring.datasource.dbcp2.max-idle= 10000
logging.level.org.springframework.security= TRACE
security.user.name= root
security.user.password= password
security.oauth2.resource.userInfoUri= http://localhost:8999/user
eureka.client.serviceUrl.defaultZone= http://localhost:8761/eureka/
If any can help me on this, Thanks in advance. :)
All application are working fine individually. But when I start in cluster after service discovery
Eureka Server
hang in few mins.
I get this exception in discovery client:
DiscoveryClient_AUTH-SERVER/192.168.3.180:auth-server:8999 - de-
registration failedCannot execute request on any known server
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:112) ~[eureka-client-1.9.0.jar:1.9.0]
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.cancel(EurekaHttpClientDecorator.java:71) ~[eureka-client-1.9.0.jar:1.9.0]
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$2.execute(EurekaHttpClientDecorator.java:74) ~[eureka-client-1.9.0.jar:1.9.0]
at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77) ~[eureka-client-1.9.0.jar:1.9.0]
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.cancel(EurekaHttpClientDecorator.java:71) ~[eureka-client-1.9.0.jar:1.9.0]
at com.netflix.discovery.DiscoveryClient.unregister(DiscoveryClient.java:923) [eureka-client-1.9.0.jar:1.9.0]
at com.netflix.discovery.DiscoveryClient.shutdown(DiscoveryClient.java:901) [eureka-client-1.9.0.jar:1.9.0]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_101]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_101]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_101]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_101]
at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:223) [spring-core-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.cloud.context.scope.GenericScope$LockedScopedProxyFactoryBean.invoke(GenericScope.java:483) [spring-cloud-context-2.0.0.RC2.jar:2.0.0.RC2]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:185) [spring-aop-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.aop.framework.JdkDynamicAopProxy.invoke(JdkDynamicAopProxy.java:212) [spring-aop-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at com.sun.proxy.$Proxy129.shutdown(Unknown Source) [na:na]
at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration.close(EurekaRegistration.java:207) [spring-cloud-netflix-eureka-client-2.0.0.RC2.jar:2.0.0.RC2]
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_101]
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_101]
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_101]
at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_101]
at org.springframework.beans.factory.support.DisposableBeanAdapter.invokeCustomDestroyMethod(DisposableBeanAdapter.java:337) [spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.beans.factory.support.DisposableBeanAdapter.destroy(DisposableBeanAdapter.java:271) [spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroyBean(DefaultSingletonBeanRegistry.java:577) [spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingleton(DefaultSingletonBeanRegistry.java:549) [spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingleton(DefaultListableBeanFactory.java:957) [spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.beans.factory.support.DefaultSingletonBeanRegistry.destroySingletons(DefaultSingletonBeanRegistry.java:510) [spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.beans.factory.support.DefaultListableBeanFactory.destroySingletons(DefaultListableBeanFactory.java:964) [spring-beans-5.0.6.RELEASE.jar:5.0.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.destroyBeans(AbstractApplicationContext.java:1041) [spring-context-5.0.6.RELEASE.jar:5.0.6.RELEASE]
Auth Server:
#SpringBootApplication
#EnableAuthorizationServer
#EnableDiscoveryClient
#EnableResourceServer
public class AuthServerApplication {
public static void main(String[] args) {
SpringApplication.run(AuthServerApplication.class, args);
}
#Bean
#Primary
#ConfigurationProperties(prefix = "spring.datasource")
public DataSource datasource() {
return DataSourceBuilder.create().build();
}
}
Application properties:
server.port= 8999
spring.application.name= auth-server
spring.jpa.database-platform=org.hibernate.dialect.MySQLDialect
spring.jpa.database= MYSQL
spring.jpa.hibernate.ddl-auto= update
spring.jpa.properties.hibernate.implicit_naming_strategy= org.hibernate.boot.model.naming.ImplicitNamingStrategyJpaCompliantImpl
spring.datasource.driver-class-name=com.mysql.jdbc.Driver
spring.datasource.jdbc-url= jdbc:mysql://localhost:3306/cloudDB1?useUnicode=true&createDatabaseIfNotExist=true&useSSL=false
spring.datasource.username= root
spring.datasource.password= root
spring.datasource.dbcp2.max-idle= 10000
logging.level.org.springframework.security= TRACE
security.basic.enabled= false
security.user.name= root
security.user.password= password
security.oauth2.client.client-id= acem
security.oauth2.client.client-secret= secret
eureka.client.serviceUrl.defaultZone= http://localhost:8761/eureka/

Spring Cloud : Zuul throwing "Load balancer does not have available server for client"

I am trying to get a simple microservice to register to the Eureka Server and then have Zuul proxy to the microservice. I got the microservice to register to the Eureka Server. However, whenever I bring the Zuul service up I see that it is not registering to the Eureka Server. Whenever I try to route to the microservice I get the below exception:
Load balancer does not have available server for client: microservice
I am not able to figure out where the issue is. Any help would be greatly appreciated
Below are my Spring Boot classes for each of these components.
Microservice Components
MicroserviceApplication.java
#SpringBootApplication(scanBasePackages = { "some.package.controller", "some.package.service" })
#EnableEurekaClient
#EnableJpaRepositories("some.package.repository")
#EntityScan("some.package.entity")
public class MicroserviceApplication {
public static void main(String[] args) {
SpringApplication.run(MicroserviceApplication.class, args);
}
}
bootstrap.yml
server:
port: 8090
info:
component: Core Services
spring:
application:
name: microservice
application.yml
eureka:
instance:
leaseRenewalIntervalInSeconds: 1
leaseExpirationDurationInSeconds: 2
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
healthcheck:
enabled: true
lease:
duration: 5
#some other logging and jpa properties below
Eureka Server Components
EurekaServerApplication.java
#SpringBootApplication
#EnableEurekaServer
public class EurekaServerApplication {
public static void main(String[] args) {
SpringApplication.run(EurekaServerApplication.class, args);
}
}
bootstrap.yml
spring:
application:
name: discovery-server
application.yml
server:
port: 8761
info:
component: Discovery Server
eureka:
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/
instance:
hostname: localhost
server:
waitTimeInMsWhenSyncEmpty: 0
API Gateway Components
ZuulGatewayApplication.java
#SpringBootApplication
#EnableZuulProxy
public class ZuulGatewayApplication {
public static void main(String[] args) {
SpringApplication.run(ZuulGatewayApplication.class, args);
}
#Bean
public ZuulGatewayPreFilter gatewayPreFilter() {
return new ZuulGatewayPreFilter();
}
}
bootstrap.yml
spring:
application:
name: api-gateway
application.yml
server:
port: 8888
info:
component: API Gateway
eureka:
instance:
leaseRenewalIntervalInSeconds: 1
leaseExpirationDurationInSeconds: 2
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
zuul:
routes:
microservice:
path: /microservice/**
serviceId: microservice
Adding #EnableEurekaClient solved this issue. The Zuul application is now discoverable in the Eureka server and is able to route requests.
I had the correct annotation on my Zuul application #EnableZuulClient but still got that error.
The problem was that I started all the applications (Eureka, Zuul and the third application) at the same time instead of doing this one by one. So they all needed time to register. After some time, the error was gone and I could reach my service through Zuul client.
Wrong spring.application.name might be the reason for this error other than
adding #EnableEurekaClient to the Zuul application class.

Turbine AMQP not receiving the hystrix.stream from services

I am trying to implement Turbine AMQP to actually consolidate all the hystrix.stream from multiple services into one and show it in hystrix dashboard.
Hystrix.stream from my service looks fine:-
Sample of what I am seeing in the stream from my client service:- localhost:4444/hystrix.stream
ping:
data: {"type":"HystrixCommand","name":"getUserAssociations","group":"UserAssociationsDAO","currentTime":1462220674908,"isCircuitBreakerOpen":false,"errorPercentage":0,"errorCount":0,"requestCount":0,"rollingCountBadRequests":0,"rollingCountCollapsedRequests":0,"rollingCountEmit":0,"rollingCountExceptionsThrown":0,"rollingCountFailure":0,"rollingCountFallbackEmit":0,"rollingCountFallbackFailure":0,"rollingCountFallbackMissing":0,"rollingCountFallbackRejection":0,"rollingCountFallbackSuccess":0,"rollingCountResponsesFromCache":0,"rollingCountSemaphoreRejected":0,"rollingCountShortCircuited":0,"rollingCountSuccess":0,"rollingCountThreadPoolRejected":0,"rollingCountTimeout":0,"currentConcurrentExecutionCount":0,"rollingMaxConcurrentExecutionCount":0,"latencyExecute_mean":0,"latencyExecute":{"0":0,"25":0,"50":0,"75":0,"90":0,"95":0,"99":0,"99.5":0,"100":0},"latencyTotal_mean":0,"latencyTotal":{"0":0,"25":0,"50":0,"75":0,"90":0,"95":0,"99":0,"99.5":0,"100":0},"propertyValue_circuitBreakerRequestVolumeThreshold":20,"propertyValue_circuitBreakerSleepWindowInMilliseconds":5000,"propertyValue_circuitBreakerErrorThresholdPercentage":50,"propertyValue_circuitBreakerForceOpen":false,"propertyValue_circuitBreakerForceClosed":false,"propertyValue_circuitBreakerEnabled":true,"propertyValue_executionIsolationStrategy":"SEMAPHORE","propertyValue_executionIsolationThreadTimeoutInMilliseconds":60000,"propertyValue_executionTimeoutInMilliseconds":60000,"propertyValue_executionIsolationThreadInterruptOnTimeout":true,"propertyValue_executionIsolationThreadPoolKeyOverride":null,"propertyValue_executionIsolationSemaphoreMaxConcurrentRequests":10,"propertyValue_fallbackIsolationSemaphoreMaxConcurrentRequests":10,"propertyValue_metricsRollingStatisticalWindowInMilliseconds":10000,"propertyValue_requestCacheEnabled":true,"propertyValue_requestLogEnabled":true,"reportingHosts":1,"threadPool":"UserAssociationsDAO"}
data: {"type":"HystrixCommand","name":"getUserAssociation","group":"UserAssociationsDAO","currentTime":1462220674909,"isCircuitBreakerOpen":false,"errorPercentage":0,"errorCount":0,"requestCount":0,"rollingCountBadRequests":0,"rollingCountCollapsedRequests":0,"rollingCountEmit":0,"rollingCountExceptionsThrown":0,"rollingCountFailure":0,"rollingCountFallbackEmit":0,"rollingCountFallbackFailure":0,"rollingCountFallbackMissing":0,"rollingCountFallbackRejection":0,"rollingCountFallbackSuccess":0,"rollingCountResponsesFromCache":0,"rollingCountSemaphoreRejected":0,"rollingCountShortCircuited":0,"rollingCountSuccess":0,"rollingCountThreadPoolRejected":0,"rollingCountTimeout":0,"currentConcurrentExecutionCount":0,"rollingMaxConcurrentExecutionCount":0,"latencyExecute_mean":0,"latencyExecute":{"0":0,"25":0,"50":0,"75":0,"90":0,"95":0,"99":0,"99.5":0,"100":0},"latencyTotal_mean":0,"latencyTotal":{"0":0,"25":0,"50":0,"75":0,"90":0,"95":0,"99":0,"99.5":0,"100":0},"propertyValue_circuitBreakerRequestVolumeThreshold":20,"propertyValue_circuitBreakerSleepWindowInMilliseconds":5000,"propertyValue_circuitBreakerErrorThresholdPercentage":50,"propertyValue_circuitBreakerForceOpen":false,"propertyValue_circuitBreakerForceClosed":false,"propertyValue_circuitBreakerEnabled":true,"propertyValue_executionIsolationStrategy":"SEMAPHORE","propertyValue_executionIsolationThreadTimeoutInMilliseconds":60000,"propertyValue_executionTimeoutInMilliseconds":60000,"propertyValue_executionIsolationThreadInterruptOnTimeout":true,"propertyValue_executionIsolationThreadPoolKeyOverride":null,"propertyValue_executionIsolationSemaphoreMaxConcurrentRequests":10,"propertyValue_fallbackIsolationSemaphoreMaxConcurrentRequests":10,"propertyValue_metricsRollingStatisticalWindowInMilliseconds":10000,"propertyValue_requestCacheEnabled":true,"propertyValue_requestLogEnabled":true,"reportingHosts":1,"threadPool":"UserAssociationsDAO"}
Gradle dependency from client side:-
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-starter-parent:Brixton.M5"
}
}
dependencies {
compile ("org.springframework.cloud:spring-cloud-starter-hystrix:1.0.6.RELEASE")
compile 'org.springframework.cloud:spring-cloud-netflix-hystrix-stream:1.1.0.M2'
compile ('org.springframework.cloud:spring-cloud-starter-bus-amqp:1.0.6.RELEASE')
compile ("org.springframework.boot:spring-boot-starter-actuator")
compile ("org.springframework.cloud:spring-cloud-starter-eureka")
compile ("org.springframework.cloud:spring-cloud-config-client")
compile ("org.codehaus.sonar-plugins.java:sonar-jacoco-plugin:2.3")
compile ("org.springframework.boot:spring-boot-starter-web")
compile ("org.codehaus.jackson:jackson-mapper-asl:1.9.2")
compile ('com.netflix.hystrix:hystrix-javanica:1.5.2')
compile ("mysql:mysql-connector-java:5.1.34")
compile ("org.springframework:spring-webmvc:4.2.2.RELEASE")
compile ("org.springframework.boot:spring-boot-starter-data-jpa")
providedRuntime ("org.springframework.boot:spring-boot-starter-tomcat")
testCompile ("org.springframework.boot:spring-boot-starter-test")
querydslapt ("org.hibernate:hibernate-jpamodelgen:5.0.5.Final")
compile 'org.springframework.cloud:spring-cloud-starter-sleuth:1.0.0.M1'
compile 'org.springframework.cloud:spring-cloud-sleuth-core:1.0.0.M1'
}
So I do have a Rabbit MQ server runninng and the turbineAMQP project as well.
My turbineAMQP annotated class:-
#SpringBootApplication
#Configuration
#EnableAutoConfiguration
#EnableTurbineAmqp
#EnableDiscoveryClient
public class TurbineApplication {
public static void main(String[] args) {
SpringApplication.run(TurbineApplication.class, args);
}
}
application.yml
info:
component: Turbine
endpoints:
restart:
enabled: true
shutdown:
enabled: true
turbine:
amqp:
port: 8989
management:
port: 8990
spring:
rabbitmq:
host: localhost
port: 5672
username: guest
password: guest
eureka:
client:
serviceUrl:
defaultZone: ${eurekaurl:http://localhost:8761/eureka/}
gradle dependency on Turbine:-
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-starter-parent:Brixton.M5"
}
}
dependencies {
compile('org.springframework.boot:spring-boot-starter-actuator')
compile('org.springframework.boot:spring-boot-actuator-docs')
compile('org.springframework.cloud:spring-cloud-starter-config')
compile('org.springframework.cloud:spring-cloud-config-client')
compile('org.springframework.cloud:spring-cloud-starter-turbine-amqp:1.0.6.RELEASE')
compile('org.springframework.cloud:spring-cloud-starter-eureka')
compile('org.springframework.boot:spring-boot-starter-logging')
compile("org.springframework.boot:spring-boot-starter-web")
testCompile('org.springframework.boot:spring-boot-starter-test')
}
when I try to hit http://localhost:8989/turbine.stream it just says ping and this is what i see in the logs when i try to put the turbione.stream though it is not working in hystrix dashboard.
2016-05-02 13:55:05.865 INFO 9028 --- [o-eventloop-3-4] o.s.c.n.t.amqp.TurbineAmqpConfiguration : SSE Request Received
2016-05-02 13:55:05.906 ERROR 9028 --- [o-eventloop-3-3] i.r.netty.server.DefaultErrorHandler : Unexpected error in RxNetty.
java.io.IOException: An established connection was aborted by the software in your host machine
at sun.nio.ch.SocketDispatcher.read0(Native Method) ~[na:1.8.0_66]
at sun.nio.ch.SocketDispatcher.read(Unknown Source) ~[na:1.8.0_66]
at sun.nio.ch.IOUtil.readIntoNativeBuffer(Unknown Source) ~[na:1.8.0_66]
at sun.nio.ch.IOUtil.read(Unknown Source) ~[na:1.8.0_66]
at sun.nio.ch.SocketChannelImpl.read(Unknown Source) ~[na:1.8.0_66]
at io.netty.buffer.PooledUnsafeDirectByteBuf.setBytes(PooledUnsafeDirectByteBuf.java:311) ~[netty-buffer-4.0.27.Final.jar:4.0.27.Final]
at io.netty.buffer.AbstractByteBuf.writeBytes(AbstractByteBuf.java:881) ~[netty-buffer-4.0.27.Final.jar:4.0.27.Final]
at io.netty.channel.socket.nio.NioSocketChannel.doReadBytes(NioSocketChannel.java:241) ~[netty-transport-4.0.27.Final.jar:4.0.27.Final]
at io.netty.channel.nio.AbstractNioByteChannel$NioByteUnsafe.read(AbstractNioByteChannel.java:119) ~[netty-transport-4.0.27.Final.jar:4.0.27.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:511) [netty-transport-4.0.27.Final.jar:4.0.27.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:468) [netty-transport-4.0.27.Final.jar:4.0.27.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:382) [netty-transport-4.0.27.Final.jar:4.0.27.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:354) [netty-transport-4.0.27.Final.jar:4.0.27.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$2.run(SingleThreadEventExecutor.java:111) [netty-common-4.0.27.Final.jar:4.0.27.Final]
at io.netty.util.concurrent.DefaultThreadFactory$DefaultRunnableDecorator.run(DefaultThreadFactory.java:137) [netty-common-4.0.27.Final.jar:4.0.27.Final]
at java.lang.Thread.run(Unknown Source) [na:1.8.0_66]
What is it that I am doing wrong here to get the turbine.stream to work.
my turbine knows about RabbitMQ but the client side service donot. Is there a need for me to tell the service also I know that turbine knows about all the hystrix.stream(s) from eureka so is turbine responsible to queue the hystrix.stream in Rabbit MQ.
Any help is appreciated I have been stuck in this for a while now and there are no good example that help.

How to add into Turbine additional Hystrix metrics aggregations

My setup is spring boot cloud using netflix library
I managed to have Turbine aggregating Hystrix metrics from one service. However when I add more services I cant see them.
This is my setup (also uploaded this into github at:
Project On Github
Service 1:
FlightIntegrationService:
#SpringBootApplication
#EnableCircuitBreaker
#EnableDiscoveryClient
#ComponentScan("com.bootnetflix")
public class FlightIntegrationApplication {
..
}
application.yaml
server:
port: 0
eureka:
instance:
leaseRenewalIntervalInSeconds: 10
metadataMap:
instanceId: ${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${random.value}}}
client:
registryFetchIntervalSeconds: 5
bootstrap.yaml
spring:
application:
name: flight-integration-service
service 2:
Coupon service:
#SpringBootApplication
#EnableCircuitBreaker
#EnableDiscoveryClient
#ComponentScan("com.bootnetflix")
public class CouponServiceApp {
..
}
application yaml:
server:
port: 0
eureka:
instance:
leaseRenewalIntervalInSeconds: 10
metadataMap:
instanceId: ${vcap.application.instance_id:${spring.application.name}:${spring.application.instance_id:${random.value}}}
client:
registryFetchIntervalSeconds: 5
Eureka app service:
#SpringBootApplication
#EnableEurekaServer
public class EurekaApplication {
Hystrix dashboard service:
#SpringBootApplication
#EnableHystrixDashboard
#Controller
public class HystrixDashboardApplication {
application.yaml:
info:
component: Hystrix Dashboard
endpoints:
restart:
enabled: true
shutdown:
enabled: true
server:
port: 7979
logging:
level:
ROOT: INFO
org.springframework.web: DEBUG
eureka:
client:
region: default
preferSameZone: false
us-east-1:
availabilityZones: default
instance:
virtualHostName: ${spring.application.name}
bootstrap.yaml
spring:
application:
name: hystrixdashboard
and finally Turbine-service:
EnableAutoConfiguration
#EnableTurbine
#EnableEurekaClient
#EnableHystrixDashboard
public class TurbineApplication {
application.yaml:
info:
component: Turbine
PREFIX:
endpoints:
restart:
enabled: true
shutdown:
enabled: true
server:
port: 8989
management:
port: 8990
eureka:
instance:
leaseRenewalIntervalInSeconds: 10
client:
serviceUrl:
defaultZone: http://localhost:8761/eureka/
#turbine:
# aggregator:
# clusterConfig: FLIGHT-INTEGRATION-SERVICE,COUPON-SERVICE
#appConfig: flight-integration-service,coupon-service
#turbine:
# clusterNameExpression: 'default'
# appConfig: flight-integration-service,coupon-service
turbine:
appConfig: coupon-service,flight-integration-service
clusterNameExpression: new String('default')
#As you can see I tried diff configurations.
What am i doing wrong? why I cant actually aggregate both services hystrix metrics(flight-integration service,coupon-service)
Thank you.
solved by #spencergibb suggestation. I added to each of the client the dependency of spring-boot-starter-amqp and created rabbitMQ broker. Turbine is aggregating all messages via amqp and I was able to see all Hystrix commands aggregated on my hystrix dashboard server

How to Secure Spring Cloud Config Server

I understand that a Spring Cloud Config Server can be protected using an user name and password , which has to be provided by the accessing clients.
How can i prevent the clients from storing these user name and
password as clear text in the bootstrap.yml files in the client
application/services ?
The very basic "basic authentication" (from here https://github.com/spring-cloud-samples/configserver)
You can add HTTP Basic authentication by including an extra dependency on Spring Security (e.g. via spring-boot-starter-security). The user name is "user" and the password is printed on the console on startup (standard Spring Boot approach). If using maven (pom.xml):
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
If you want custom user/password pairs, you need indicate in server configuration file
security:
basic:
enabled: false
and add this minimal Class in your code (BasicSecurityConfiguration.java):
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Configuration;
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder;
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
#Configuration
//#EnableGlobalMethodSecurity(prePostEnabled = true, securedEnabled = true)
public class BasicSecurityConfiguration extends WebSecurityConfigurerAdapter {
#Value("#{'${qa.admin.password:admin}'}") //property with default value
String admin_password;
#Value("#{'${qa.user.password:user}'}") //property with default value
String user_password;
#Autowired
public void configureGlobal(AuthenticationManagerBuilder auth) throws Exception {
auth
.inMemoryAuthentication()
.withUser("user").password(user_password).roles("USER")
.and()
.withUser("admin").password(admin_password).roles("USER", "ACTUATOR");
}
#Override
protected void configure(HttpSecurity http) throws Exception {
http
.csrf()
.disable()
.httpBasic()
.and()
.authorizeRequests()
.antMatchers("/encrypt/**").authenticated()
.antMatchers("/decrypt/**").authenticated()
//.antMatchers("/admin/**").hasAuthority("ROLE_ACTUATOR")
//.antMatchers("/qa/**").permitAll()
;
}
}
#Value("#{'${qa.admin.password:admin}'}") allow passwords to be defined in property configuration file, environment variables or command line.
For example (application.yml):
server:
port: 8888
security:
basic:
enabled: false
qa:
admin:
password: adminadmin
user:
password: useruser
management:
port: 8888
context-path: /admin
logging:
level:
org.springframework.cloud: 'DEBUG'
spring:
cloud:
config:
server:
git:
ignoreLocalSshSettings: true
uri: ssh://git#gitlab.server.corp/repo/configuration.git
This works for me.
Edit: Instead of the Class, you can put basic user configuration directly in application.yaml:
security:
basic:
enabled: true
path: /**
ignored: /health**,/info**,/metrics**,/trace**
user:
name: admin
password: tupassword
For Spring Boot 2 the configuration in application.yml are now under spring.security.* (https://docs.spring.io/spring-boot/docs/current/reference/html/appendix-application-properties.html#security-properties)
spring.security:
basic:
enabled: true
path: /**
ignored: /health**,/info**,/metrics**,/trace**
user:
name: admin
password: tupassword
Basic authentication configuration that works for me.
Server-side:
Needed depedency: org.springframework.boot:spring-boot-starter-security
bootstrap.yml
server:
port: 8888
spring:
cloud:
config:
server:
git:
uri: git#bitbucket.org:someRepo/repoName.git
hostKeyAlgorithm: ssh-rsa
hostKey: "general hostKey for bitbucket.org"
security:
user:
name: yourUser
password: yourPassword
Client-side:
bootstrap.yml
spring:
application:
name: config
profiles:
active: dev
cloud:
config:
uri: http://localhost:8888
username: yourUser
password: yourPassword
management:
security:
enabled: false
Sources: Spring doc security feautres, Spring cloud config client security
encrypted text can be placed in bootstrap.yml.
Check -> http://projects.spring.io/spring-cloud/spring-cloud.html#_encryption_and_decryption

Resources