Cannot connect to jhipster spring registry on docker via IDE - java

I'm running JHipster registry in a docker container.
All applications running on docker can connect and register in registry endpoint (port 8761).
But when I try to connect an application running on my IDEA, I receive a error when trying to connect to the registry endpoint:
2016-07-21 10:35:24.912 INFO 1455 --- [ restartedMain] a.b.p.App2App : Started App2App in 14.944 seconds (JVM running for 15.912)
2016-07-21 10:35:24.913 INFO 1455 --- [ restartedMain] a.b.p.App2App :
----------------------------------------------------------
Application 'app2' is running! Access URLs:
Local: http://127.0.0.1:8081
External: http://192.168.1.104:8081
----------------------------------------------------------
2016-07-21 10:35:24.913 INFO 1455 --- [ restartedMain] a.b.p.App2App :
----------------------------------------------------------
Config Server: Connected to the JHipster Registry running in Docker
----------------------------------------------------------
2016-07-21 10:35:24.915 DEBUG 1455 --- [nfoReplicator-0] s.n.www.protocol.http.HttpURLConnection : sun.net.www.MessageHeader#33e72d406 pairs: {GET /config/application/prod/master HTTP/1.1: null}{Accept: application/json, application/*+json}{Authorization: Basic YWRtaW46YWRtaW4=}{User-Agent: Java/1.8.0_65}{Host: localhost:8761}{Connection: keep-alive}
2016-07-21 10:35:25.057 DEBUG 1455 --- [nfoReplicator-0] s.n.www.protocol.http.HttpURLConnection : sun.net.www.MessageHeader#d6320d811 pairs: {null: HTTP/1.1 200 OK}{Server: Apache-Coyote/1.1}{X-Content-Type-Options: nosniff}{X-XSS-Protection: 1; mode=block}{Cache-Control: no-cache, no-store, max-age=0, must-revalidate}{Pragma: no-cache}{Expires: 0}{X-Application-Context: jhipster-registry:dev,native:8761}{Content-Type: application/json;charset=UTF-8}{Transfer-Encoding: chunked}{Date: Thu, 21 Jul 2016 13:35:24 GMT}
2016-07-21 10:35:25.058 INFO 1455 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_APP2/app2:cddc722884843f95abdcf09d4996623d: registering service...
2016-07-21 10:35:25.059 ERROR 1455 --- [nfoReplicator-0] c.n.d.s.t.d.RedirectingEurekaHttpClient : Request execution error
com.sun.jersey.api.client.ClientHandlerException: java.net.UnknownHostException: registry
at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187)
at com.sun.jersey.api.client.filter.GZIPContentEncodingFilter.handle(GZIPContentEncodingFilter.java:123)
at com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27)
at com.sun.jersey.api.client.Client.handle(Client.java:652)
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682)
at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:570)
at com.netflix.discovery.shared.transport.jersey.AbstractJerseyEurekaHttpClient.register(AbstractJerseyEurekaHttpClient.java:56)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.execute(EurekaHttpClientDecorator.java:59)
at com.netflix.discovery.shared.transport.decorator.MetricsCollectingEurekaHttpClient.execute(MetricsCollectingEurekaHttpClient.java:73)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.execute(EurekaHttpClientDecorator.java:59)
at com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient.executeOnNewServer(RedirectingEurekaHttpClient.java:118)
at com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient.execute(RedirectingEurekaHttpClient.java:79)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.execute(EurekaHttpClientDecorator.java:59)
at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:119)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.execute(EurekaHttpClientDecorator.java:59)
at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56)
at com.netflix.discovery.DiscoveryClient.register(DiscoveryClient.java:810)
at com.netflix.discovery.InstanceInfoReplicator.run(InstanceInfoReplicator.java:103)
at com.netflix.discovery.InstanceInfoReplicator$1.run(InstanceInfoReplicator.java:87)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.UnknownHostException: registry
at java.net.InetAddress.getAllByName0(InetAddress.java:1280)
at java.net.InetAddress.getAllByName(InetAddress.java:1192)
at java.net.InetAddress.getAllByName(InetAddress.java:1126)
at org.apache.http.impl.conn.SystemDefaultDnsResolver.resolve(SystemDefaultDnsResolver.java:45)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.resolveHostname(DefaultClientConnectionOperator.java:259)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:159)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:144)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:131)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:611)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:446)
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:882)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:117)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:55)
at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:173)
... 30 common frames omitted
2016-07-21 10:35:25.059 WARN 1455 --- [nfoReplicator-0] c.n.d.s.t.d.RetryableEurekaHttpClient : Request execution failure
2016-07-21 10:35:25.060 WARN 1455 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_APP2/app2:cddc722884843f95abdcf09d4996623d - registration failed Cannot 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:111)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.execute(EurekaHttpClientDecorator.java:59)
at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56)
at com.netflix.discovery.DiscoveryClient.register(DiscoveryClient.java:810)
at com.netflix.discovery.InstanceInfoReplicator.run(InstanceInfoReplicator.java:103)
at com.netflix.discovery.InstanceInfoReplicator$1.run(InstanceInfoReplicator.java:87)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
2016-07-21 10:35:25.060 WARN 1455 --- [nfoReplicator-0] c.n.discovery.InstanceInfoReplicator : There was a problem with the instance info replicator
com.netflix.discovery.shared.transport.TransportException: Cannot execute request on any known server
at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:111)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.execute(EurekaHttpClientDecorator.java:59)
at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56)
at com.netflix.discovery.DiscoveryClient.register(DiscoveryClient.java:810)
at com.netflix.discovery.InstanceInfoReplicator.run(InstanceInfoReplicator.java:103)
at com.netflix.discovery.InstanceInfoReplicator$1.run(InstanceInfoReplicator.java:87)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
The application connects to Register (see it in logs), but after that I receive the error:
UnknownHostException: registry
Did anyone know how can I connect to a registry running in docker?
My spring application.yml is:
eureka:
instance:
prefer-ip-address: true
client:
enabled: true
healthcheck:
enabled: true
registerWithEureka: true
fetchRegistry: true
serviceUrl:
defaultZone: http://admin:admin#localhost:8761/eureka/
The default zone in jhipster-registry is http://user:pass#register:8761/eureka.
If I change to localhost, like this:
eureka:
client:
serviceUrl:
defaultZone: http://admin:admin#localhost:8761/eureka/
It works, but in this case the services running in docker can't access the registry (reverse problem).
Thanks!

I had a similar issue. In 3.5.0, I was able to successfully start the docker based registry, and then start up non docker versions of a microservice and a gateway. With 3.5.1, I was no longer able to do that, getting the same error you are getting. I think it's related to https://github.com/jhipster/generator-jhipster/pull/3848. In any case, I just added an entry in my /etc/hosts file, pointing "registry" to 127.0.0.1, and it worked.

The localhost on docker which running microservice is not the same localhost on docker which running registry. I changed the localhost to the host's Intranet Address, It's work for me.
eureka:
instance:
prefer-ip-address: true
client:
service-url:
defaultZone: http://admin:${jhipster.registry.password}#10.31.224.228:8761/eureka/

Related

Embedded MongoDB not starting while running spring boot application

I have created a sample spring application that has mongoDB dependency added in pom.xml. I haven't added any code apart from the dependencies but I get the following error when I try running it. I have tried multiple approaches and workaround but I still see the same error.
2022-09-07 14:55:21.496 INFO 6932 --- [ main] com.sensor.metrics.MetricsApplication : Starting MetricsApplication using Java 13.0.2 on DESKTOP-GO61V4S with PID 6932 (D:\Java Project\metrics2\metrics\target\classes started by prate in D:\Java Project\metrics2\metrics)
2022-09-07 14:55:21.499 INFO 6932 --- [ main] com.sensor.metrics.MetricsApplication : The following 1 profile is active: "local"
2022-09-07 14:55:22.106 INFO 6932 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data Reactive MongoDB repositories in DEFAULT mode.
2022-09-07 14:55:22.117 INFO 6932 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 6 ms. Found 0 Reactive MongoDB repository interfaces.
2022-09-07 14:55:24.118 INFO 6932 --- [ main] org.mongodb.driver.client : MongoClient with metadata {"driver": {"name": "mongo-java-driver|reactive-streams|spring-boot", "version": "4.6.1"}, "os": {"type": "Windows", "name": "Windows 10", "architecture": "amd64", "version": "10.0"}, "platform": "Java/Oracle Corporation/13.0.2+8"} created with settings MongoClientSettings{readPreference=primary, writeConcern=WriteConcern{w=null, wTimeout=null ms, journal=null}, retryWrites=true, retryReads=true, readConcern=ReadConcern{level=null}, credential=null, streamFactoryFactory=NettyStreamFactoryFactory{eventLoopGroup=io.netty.channel.nio.NioEventLoopGroup#3c79088e, socketChannelClass=class io.netty.channel.socket.nio.NioSocketChannel, allocator=PooledByteBufAllocator(directByDefault: true), sslContext=null}, commandListeners=[], codecRegistry=ProvidersCodecRegistry{codecProviders=[ValueCodecProvider{}, BsonValueCodecProvider{}, DBRefCodecProvider{}, DBObjectCodecProvider{}, DocumentCodecProvider{}, IterableCodecProvider{}, MapCodecProvider{}, GeoJsonCodecProvider{}, GridFSFileCodecProvider{}, Jsr310CodecProvider{}, JsonObjectCodecProvider{}, BsonCodecProvider{}, EnumCodecProvider{}, com.mongodb.Jep395RecordCodecProvider#4a37191a]}, clusterSettings={hosts=[localhost:27017], srvServiceName=mongodb, mode=SINGLE, requiredClusterType=UNKNOWN, requiredReplicaSetName='null', serverSelector='null', clusterListeners='[]', serverSelectionTimeout='30000 ms', localThreshold='30000 ms'}, socketSettings=SocketSettings{connectTimeoutMS=10000, readTimeoutMS=0, receiveBufferSize=0, sendBufferSize=0}, heartbeatSocketSettings=SocketSettings{connectTimeoutMS=10000, readTimeoutMS=10000, receiveBufferSize=0, sendBufferSize=0}, connectionPoolSettings=ConnectionPoolSettings{maxSize=100, minSize=0, maxWaitTimeMS=120000, maxConnectionLifeTimeMS=0, maxConnectionIdleTimeMS=0, maintenanceInitialDelayMS=0, maintenanceFrequencyMS=60000, connectionPoolListeners=[], maxConnecting=2}, serverSettings=ServerSettings{heartbeatFrequencyMS=10000, minHeartbeatFrequencyMS=500, serverListeners='[]', serverMonitorListeners='[]'}, sslSettings=SslSettings{enabled=false, invalidHostNameAllowed=false, context=null}, applicationName='null', compressorList=[], uuidRepresentation=JAVA_LEGACY, serverApi=null, autoEncryptionSettings=null, contextProvider=null}
2022-09-07 14:55:25.226 INFO 6932 --- [ main] o.s.b.web.embedded.netty.NettyWebServer : Netty started on port 8080
2022-09-07 14:55:25.246 INFO 6932 --- [ main] com.sensor.metrics.MetricsApplication : Started MetricsApplication in 4.192 seconds (JVM running for 4.615)
2022-09-07 14:55:29.317 INFO 6932 --- [localhost:27017] org.mongodb.driver.cluster : Exception in monitor thread while connecting to server localhost:27017
com.mongodb.MongoSocketOpenException: Exception opening socket
at com.mongodb.connection.netty.NettyStream$OpenChannelFutureListener.operationComplete(NettyStream.java:520) ~[mongodb-driver-core-4.6.1.jar:na]
at com.mongodb.connection.netty.NettyStream$OpenChannelFutureListener.operationComplete(NettyStream.java:488) ~[mongodb-driver-core-4.6.1.jar:na]
at io.netty.util.concurrent.DefaultPromise.notifyListener0(DefaultPromise.java:578) ~[netty-common-4.1.79.Final.jar:4.1.79.Final]
at io.netty.util.concurrent.DefaultPromise.notifyListeners0(DefaultPromise.java:571) ~[netty-common-4.1.79.Final.jar:4.1.79.Final]
at io.netty.util.concurrent.DefaultPromise.notifyListenersNow(DefaultPromise.java:550) ~[netty-common-4.1.79.Final.jar:4.1.79.Final]
at io.netty.util.concurrent.DefaultPromise.notifyListeners(DefaultPromise.java:491) ~[netty-common-4.1.79.Final.jar:4.1.79.Final]
at io.netty.util.concurrent.DefaultPromise.setValue0(DefaultPromise.java:616) ~[netty-common-4.1.79.Final.jar:4.1.79.Final]
at io.netty.util.concurrent.DefaultPromise.setFailure0(DefaultPromise.java:609) ~[netty-common-4.1.79.Final.jar:4.1.79.Final]
at io.netty.util.concurrent.DefaultPromise.tryFailure(DefaultPromise.java:117) ~[netty-common-4.1.79.Final.jar:4.1.79.Final]
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.fulfillConnectPromise(AbstractNioChannel.java:321) ~[netty-transport-4.1.79.Final.jar:4.1.79.Final]
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:337) ~[netty-transport-4.1.79.Final.jar:4.1.79.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:710) ~[netty-transport-4.1.79.Final.jar:4.1.79.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:658) ~[netty-transport-4.1.79.Final.jar:4.1.79.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:584) ~[netty-transport-4.1.79.Final.jar:4.1.79.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:496) ~[netty-transport-4.1.79.Final.jar:4.1.79.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[netty-common-4.1.79.Final.jar:4.1.79.Final]
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.79.Final.jar:4.1.79.Final]
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.79.Final.jar:4.1.79.Final]
at java.base/java.lang.Thread.run(Thread.java:830) ~[na:na]
Caused by: io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection refused: no further information: localhost/0:0:0:0:0:0:0:1:27017
Caused by: java.net.ConnectException: Connection refused: no further information
at java.base/sun.nio.ch.Net.pollConnect(Native Method) ~[na:na]
at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:579) ~[na:na]
at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:820) ~[na:na]
at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:337) ~[netty-transport-4.1.79.Final.jar:4.1.79.Final]
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:334) ~[netty-transport-4.1.79.Final.jar:4.1.79.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:710) ~[netty-transport-4.1.79.Final.jar:4.1.79.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:658) ~[netty-transport-4.1.79.Final.jar:4.1.79.Final]
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:584) ~[netty-transport-4.1.79.Final.jar:4.1.79.Final]
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:496) ~[netty-transport-4.1.79.Final.jar:4.1.79.Final]
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:997) ~[netty-common-4.1.79.Final.jar:4.1.79.Final]
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74) ~[netty-common-4.1.79.Final.jar:4.1.79.Final]
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30) ~[netty-common-4.1.79.Final.jar:4.1.79.Final]
at java.base/java.lang.Thread.run(Thread.java:830) ~[na:na]

Spring Cloud Kubernetes application does not detect when it is running in a pod

Expected Behavior
According to the Spring Cloud Kubernetes documentation, all that is necessary for a Spring application to detect when it's running in a pod is to add Spring Cloud Kubernetes to the classpath with the spring-cloud-kubernetes-all dependency.
This triggers two events:
If present the application-kubernetes.yml profile is loaded.
The Kubernetes implementation of DiscoveryClient is used for service discovery, leveraging KubeDNS instead of the default of Eureka.
This environment awareness is described here:
https://cloud.spring.io/spring-cloud-static/spring-cloud-kubernetes/1.1.0.RELEASE/reference/html/#kubernetes-profile-autoconfiguration
and here:
https://cloud.spring.io/spring-cloud-static/spring-cloud-kubernetes/1.1.0.RELEASE/reference/html/#discoveryclient-for-kubernetes
Actual Behavior
After booting the Spring Cloud Kubernetes application using the following yaml and accessing it's actuator endpoint at http://minikube-ip:port/actuator/env via a NodePort, I see there are no active profiles set, even though a application-kubernetes.yml exists in the resources folder:
{
"activeProfiles": [],
...
Upon further investigation in the http://minikube-ip:port/actuator/info endpoint, I see that the Spring application isn't aware it's in a pod at all, as evidenced by:
{
"kubernetes": {
"inside": false
}
}
My Code
SpringCloudGateway
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.gateway.route.RouteLocator;
import org.springframework.cloud.gateway.route.builder.RouteLocatorBuilder;
import org.springframework.context.annotation.Bean;
#SpringBootApplication
#EnableDiscoveryClient
public class Gateway {
public static void main(String[] args) {
SpringApplication.run(Gateway.class, args);
}
#Bean
public RouteLocator myRoutes(RouteLocatorBuilder builder) {
return builder.routes()
.route(p -> p.path("/captcha").filters(f -> f.stripPrefix(1)).uri("lb://captcha").id("captcha"))
.build();
}
}
SpringCloudGateway build.gradle
plugins {
id 'java'
id 'org.springframework.boot' version '2.2.6.RELEASE'
id 'io.spring.dependency-management' version '1.0.10.RELEASE'
id 'idea'
id 'eclipse'
id 'com.google.cloud.tools.jib' version '1.6.1'
id 'com.diffplug.gradle.spotless' version '4.5.1'
}
ext {
springCloudVersion = 'Hoxton.SR5'
}
java {
sourceCompatibility = JavaVersion.VERSION_11
targetCompatibility = JavaVersion.VERSION_11
}
dependencies {
implementation "org.springframework.cloud:spring-cloud-starter-netflix-eureka-client"
implementation "org.springframework.cloud:spring-cloud-starter-gateway"
implementation 'org.springframework.cloud:spring-cloud-starter-kubernetes-all'
implementation 'org.springframework.boot:spring-boot-starter-actuator'
testImplementation "org.springframework.boot:spring-boot-starter-test"
testImplementation "org.springframework.cloud:spring-cloud-starter-netflix-eureka-server"
}
dependencyManagement {
imports {
mavenBom "org.springframework.cloud:spring-cloud-dependencies:$springCloudVersion"
}
}
SpringCloudGateway application.yml
server:
port: 8760
spring:
application:
name: gateway
cloud:
kubernetes:
enabled: false
eureka:
client:
enabled: true
registerWithEureka: true
serviceUrl:
defaultZone: ${EUREKA_SERVER:http://localhost:8761/eureka}
management:
endpoints:
web:
exposure:
include: "*"
SpringCloudGateway application-kubernetes.yml
spring:
cloud:
kubernetes:
enabled: true
eureka:
client:
enabled: false
SpringCloudGateway deployment.yml
apiVersion: apps/v1
kind: Deployment
metadata:
creationTimestamp: null
generation: 1
labels:
run: gateway
name: gateway
spec:
replicas: 2
revisionHistoryLimit: 2
selector:
matchLabels:
run: gateway
strategy:
rollingUpdate:
maxSurge: 25%
maxUnavailable: 25%
type: RollingUpdate
template:
metadata:
creationTimestamp: null
labels:
run: gateway
spec:
hostname: gateway
containers:
- image: gateway-image
imagePullPolicy: Never
name: gateway
ports:
- containerPort: 8760
protocol: TCP
Logs of the SpringCloudGateway pod
. ____ _ __ _ _
/\\ / ___'_ __ _ _(_)_ __ __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
\\/ ___)| |_)| | | | | || (_| | ) ) ) )
' |____| .__|_| |_|_| |_\__, | / / / /
=========|_|==============|___/=/_/_/_/
:: Spring Boot :: (v2.2.6.RELEASE)
2020-12-06 17:15:11.468 INFO 1 --- [ main] b.c.PropertySourceBootstrapConfiguration : Located property source: [BootstrapPropertySource {name='bootstrapProperties-configmap.gateway.default'}]
2020-12-06 17:15:11.507 INFO 1 --- [ main] com.example.gateway.Gateway : No active profile set, falling back to default profiles: default
2020-12-06 17:15:17.627 WARN 1 --- [ main] o.s.boot.actuate.endpoint.EndpointId : Endpoint ID 'service-registry' contains invalid characters, please migrate to a valid format.
2020-12-06 17:15:18.358 INFO 1 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=2ddf218c-a309-33c9-a6e4-7f9ba9a5c5f9
2020-12-06 17:15:19.199 INFO 1 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.client.loadbalancer.reactive.LoadBalancerBeanPostProcessorAutoConfiguration' of type [org.springframework.cloud.client.loadbalancer.reactive.LoadBalancerBeanPostProcessorAutoConfiguration] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-12-06 17:15:19.212 INFO 1 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'org.springframework.cloud.client.loadbalancer.reactive.LoadBalancerBeanPostProcessorAutoConfiguration$ReactiveLoadBalancerConfig' of type [org.springframework.cloud.client.loadbalancer.reactive.LoadBalancerBeanPostProcessorAutoConfiguration$ReactiveLoadBalancerConfig] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-12-06 17:15:19.217 INFO 1 --- [ main] trationDelegate$BeanPostProcessorChecker : Bean 'deferringLoadBalancerExchangeFilterFunction' of type [org.springframework.cloud.client.loadbalancer.reactive.DeferringLoadBalancerExchangeFilterFunction] is not eligible for getting processed by all BeanPostProcessors (for example: not eligible for auto-proxying)
2020-12-06 17:15:20.700 WARN 1 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
2020-12-06 17:15:20.700 INFO 1 --- [ main] c.n.c.sources.URLConfigurationSource : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2020-12-06 17:15:20.722 WARN 1 --- [ main] c.n.c.sources.URLConfigurationSource : No URLs will be polled as dynamic configuration sources.
2020-12-06 17:15:20.722 INFO 1 --- [ main] c.n.c.sources.URLConfigurationSource : To enable URLs as dynamic configuration sources, define System property archaius.configurationSource.additionalUrls or make config.properties available on classpath.
2020-12-06 17:15:28.046 INFO 1 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [After]
2020-12-06 17:15:28.046 INFO 1 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [Before]
2020-12-06 17:15:28.047 INFO 1 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [Between]
2020-12-06 17:15:28.047 INFO 1 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [Cookie]
2020-12-06 17:15:28.047 INFO 1 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [Header]
2020-12-06 17:15:28.047 INFO 1 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [Host]
2020-12-06 17:15:28.048 INFO 1 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [Method]
2020-12-06 17:15:28.048 INFO 1 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [Path]
2020-12-06 17:15:28.048 INFO 1 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [Query]
2020-12-06 17:15:28.048 INFO 1 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [ReadBodyPredicateFactory]
2020-12-06 17:15:28.049 INFO 1 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [RemoteAddr]
2020-12-06 17:15:28.049 INFO 1 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [Weight]
2020-12-06 17:15:28.049 INFO 1 --- [ main] o.s.c.g.r.RouteDefinitionRouteLocator : Loaded RoutePredicateFactory [CloudFoundryRouteService]
2020-12-06 17:15:29.685 INFO 1 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 18 endpoint(s) beneath base path '/actuator'
2020-12-06 17:15:30.893 WARN 1 --- [ main] ockingLoadBalancerClientRibbonWarnLogger : You already have RibbonLoadBalancerClient on your classpath. It will be used by default. As Spring Cloud Ribbon is in maintenance mode. We recommend switching to BlockingLoadBalancerClient instead. In order to use it, set the value of `spring.cloud.loadbalancer.ribbon.enabled` to `false` or remove spring-cloud-starter-netflix-ribbon from your project.
2020-12-06 17:15:30.974 WARN 1 --- [ main] eactorLoadBalancerClientRibbonWarnLogger : You have RibbonLoadBalancerClient on your classpath. LoadBalancerExchangeFilterFunction that uses it under the hood will be used by default. Spring Cloud Ribbon is now in maintenance mode, so we suggest switching to ReactorLoadBalancerExchangeFilterFunction instead. In order to use it, set the value of `spring.cloud.loadbalancer.ribbon.enabled` to `false` or remove spring-cloud-starter-netflix-ribbon from your project.
2020-12-06 17:15:31.303 INFO 1 --- [ main] o.s.c.n.eureka.InstanceInfoFactory : Setting initial instance status as: STARTING
2020-12-06 17:15:31.981 INFO 1 --- [ main] com.netflix.discovery.DiscoveryClient : Initializing Eureka in region us-east-1
2020-12-06 17:15:32.390 INFO 1 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using JSON encoding codec LegacyJacksonJson
2020-12-06 17:15:32.390 INFO 1 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using JSON decoding codec LegacyJacksonJson
WARNING: An illegal reflective access operation has occurred
WARNING: Illegal reflective access by com.thoughtworks.xstream.core.util.Fields (file:/app/libs/xstream-1.4.11.1.jar) to field java.util.TreeMap.comparator
WARNING: Please consider reporting this to the maintainers of com.thoughtworks.xstream.core.util.Fields
WARNING: Use --illegal-access=warn to enable warnings of further illegal reflective access operations
WARNING: All illegal access operations will be denied in a future release
2020-12-06 17:15:33.180 INFO 1 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using XML encoding codec XStreamXml
2020-12-06 17:15:33.181 INFO 1 --- [ main] c.n.d.provider.DiscoveryJerseyProvider : Using XML decoding codec XStreamXml
2020-12-06 17:15:34.185 INFO 1 --- [ main] c.n.d.s.r.aws.ConfigClusterResolver : Resolving eureka endpoints via configuration
2020-12-06 17:15:34.253 INFO 1 --- [ main] com.netflix.discovery.DiscoveryClient : Disable delta property : false
2020-12-06 17:15:34.253 INFO 1 --- [ main] com.netflix.discovery.DiscoveryClient : Single vip registry refresh property : null
2020-12-06 17:15:34.258 INFO 1 --- [ main] com.netflix.discovery.DiscoveryClient : Force full registry fetch : false
2020-12-06 17:15:34.263 INFO 1 --- [ main] com.netflix.discovery.DiscoveryClient : Application is null : false
2020-12-06 17:15:34.264 INFO 1 --- [ main] com.netflix.discovery.DiscoveryClient : Registered Applications size is zero : true
2020-12-06 17:15:34.266 INFO 1 --- [ main] com.netflix.discovery.DiscoveryClient : Application version is -1: true
2020-12-06 17:15:34.266 INFO 1 --- [ main] com.netflix.discovery.DiscoveryClient : Getting all instance registry info from the eureka server
2020-12-06 17:15:34.735 ERROR 1 --- [ main] c.n.d.s.t.d.RedirectingEurekaHttpClient : Request execution error. endpoint=DefaultEndpoint{ serviceUrl='http://localhost:8761/eureka/}
com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused (Connection refused)
at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187) ~[jersey-apache-client4-1.19.1.jar:1.19.1]
at com.sun.jersey.api.client.filter.GZIPContentEncodingFilter.handle(GZIPContentEncodingFilter.java:123) ~[jersey-client-1.19.1.jar:1.19.1]
at com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27) ~[eureka-client-1.9.21.jar:1.9.21]
at com.sun.jersey.api.client.Client.handle(Client.java:652) ~[jersey-client-1.19.1.jar:1.19.1]
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682) ~[jersey-client-1.19.1.jar:1.19.1]
at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74) ~[jersey-client-1.19.1.jar:1.19.1]
at com.sun.jersey.api.client.WebResource$Builder.get(WebResource.java:509) ~[jersey-client-1.19.1.jar:1.19.1]
at com.netflix.discovery.shared.transport.jersey.AbstractJerseyEurekaHttpClient.getApplicationsInternal(AbstractJerseyEurekaHttpClient.java:196) ~[eureka-client-1.9.21.jar:1.9.21]
at com.netflix.discovery.shared.transport.jersey.AbstractJerseyEurekaHttpClient.getApplications(AbstractJerseyEurekaHttpClient.java:167) ~[eureka-client-1.9.21.jar:1.9.21]
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$6.execute(EurekaHttpClientDecorator.java:137) ~[eureka-client-1.9.21.jar:1.9.21]
at com.netflix.discovery.shared.transport.decorator.MetricsCollectingEurekaHttpClient.execute(MetricsCollectingEurekaHttpClient.java:73) ~[eureka-client-1.9.21.jar:1.9.21]
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134) ~[eureka-client-1.9.21.jar:1.9.21]
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$6.execute(EurekaHttpClientDecorator.java:137) ~[eureka-client-1.9.21.jar:1.9.21]
at com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient.executeOnNewServer(RedirectingEurekaHttpClient.java:118) ~[eureka-client-1.9.21.jar:1.9.21]
at com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient.execute(RedirectingEurekaHttpClient.java:79) ~[eureka-client-1.9.21.jar:1.9.21]
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134) ~[eureka-client-1.9.21.jar:1.9.21]
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$6.execute(EurekaHttpClientDecorator.java:137) ~[eureka-client-1.9.21.jar:1.9.21]
at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:120) ~[eureka-client-1.9.21.jar:1.9.21]
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134) ~[eureka-client-1.9.21.jar:1.9.21]
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$6.execute(EurekaHttpClientDecorator.java:137) ~[eureka-client-1.9.21.jar:1.9.21]
at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77) ~[eureka-client-1.9.21.jar:1.9.21]
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.getApplications(EurekaHttpClientDecorator.java:134) ~[eureka-client-1.9.21.jar:1.9.21]
at com.netflix.discovery.DiscoveryClient.getAndStoreFullRegistry(DiscoveryClient.java:1081) ~[eureka-client-1.9.21.jar:1.9.21]
at com.netflix.discovery.DiscoveryClient.fetchRegistry(DiscoveryClient.java:995) ~[eureka-client-1.9.21.jar:1.9.21]
at com.netflix.discovery.DiscoveryClient.<init>(DiscoveryClient.java:438) ~[eureka-client-1.9.21.jar:1.9.21]
at com.netflix.discovery.DiscoveryClient.<init>(DiscoveryClient.java:282) ~[eureka-client-1.9.21.jar:1.9.21]
at com.netflix.discovery.DiscoveryClient.<init>(DiscoveryClient.java:278) ~[eureka-client-1.9.21.jar:1.9.21]
at org.springframework.cloud.netflix.eureka.CloudEurekaClient.<init>(CloudEurekaClient.java:67) ~[spring-cloud-netflix-eureka-client-2.2.3.RELEASE.jar:2.2.3.RELEASE]
at org.springframework.cloud.netflix.eureka.EurekaClientAutoConfiguration$RefreshableEurekaClientConfiguration.eurekaClient(EurekaClientAutoConfiguration.java:316) ~[spring-cloud-netflix-eureka-client-2.2.3.RELEASE.jar:2.2.3.RELEASE]
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.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:154) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:651) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.beans.factory.support.ConstructorResolver.instantiateUsingFactoryMethod(ConstructorResolver.java:636) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.instantiateUsingFactoryMethod(AbstractAutowireCapableBeanFactory.java:1338) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBeanInstance(AbstractAutowireCapableBeanFactory.java:1177) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.doCreateBean(AbstractAutowireCapableBeanFactory.java:557) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:517) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.lambda$doGetBean$1(AbstractBeanFactory.java:359) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.cloud.context.scope.GenericScope$BeanLifecycleWrapper.getBean(GenericScope.java:389) ~[spring-cloud-context-2.2.3.RELEASE.jar:2.2.3.RELEASE]
at org.springframework.cloud.context.scope.GenericScope.get(GenericScope.java:186) ~[spring-cloud-context-2.2.3.RELEASE.jar:2.2.3.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.doGetBean(AbstractBeanFactory.java:356) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:202) ~[spring-beans-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.aop.target.SimpleBeanTargetSource.getTarget(SimpleBeanTargetSource.java:35) ~[spring-aop-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration.getTargetObject(EurekaRegistration.java:129) ~[spring-cloud-netflix-eureka-client-2.2.3.RELEASE.jar:2.2.3.RELEASE]
at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration.getEurekaClient(EurekaRegistration.java:117) ~[spring-cloud-netflix-eureka-client-2.2.3.RELEASE.jar:2.2.3.RELEASE]
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.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:282) ~[spring-core-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.cloud.context.scope.GenericScope$LockedScopedProxyFactoryBean.invoke(GenericScope.java:499) ~[spring-cloud-context-2.2.3.RELEASE.jar:2.2.3.RELEASE]
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:749) ~[spring-aop-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:691) ~[spring-aop-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaRegistration$$EnhancerBySpringCGLIB$$e39a6809.getEurekaClient(<generated>) ~[spring-cloud-netflix-eureka-client-2.2.3.RELEASE.jar:2.2.3.RELEASE]
at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.maybeInitializeClient(EurekaServiceRegistry.java:57) ~[spring-cloud-netflix-eureka-client-2.2.3.RELEASE.jar:2.2.3.RELEASE]
at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaServiceRegistry.register(EurekaServiceRegistry.java:38) ~[spring-cloud-netflix-eureka-client-2.2.3.RELEASE.jar:2.2.3.RELEASE]
at org.springframework.cloud.netflix.eureka.serviceregistry.EurekaAutoServiceRegistration.start(EurekaAutoServiceRegistration.java:83) ~[spring-cloud-netflix-eureka-client-2.2.3.RELEASE.jar:2.2.3.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.doStart(DefaultLifecycleProcessor.java:182) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.access$200(DefaultLifecycleProcessor.java:53) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor$LifecycleGroup.start(DefaultLifecycleProcessor.java:360) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.startBeans(DefaultLifecycleProcessor.java:158) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.context.support.DefaultLifecycleProcessor.onRefresh(DefaultLifecycleProcessor.java:122) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.finishRefresh(AbstractApplicationContext.java:894) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.finishRefresh(ReactiveWebServerApplicationContext.java:129) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:553) ~[spring-context-5.2.5.RELEASE.jar:5.2.5.RELEASE]
at org.springframework.boot.web.reactive.context.ReactiveWebServerApplicationContext.refresh(ReactiveWebServerApplicationContext.java:66) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.SpringApplication.refresh(SpringApplication.java:747) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.SpringApplication.refreshContext(SpringApplication.java:397) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:315) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1226) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at org.springframework.boot.SpringApplication.run(SpringApplication.java:1215) ~[spring-boot-2.2.6.RELEASE.jar:2.2.6.RELEASE]
at com.example.gateway.Gateway.main(Gateway.java:17) ~[classes/:na]
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.base/java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:na]
at java.base/java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399) ~[na:na]
at java.base/java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242) ~[na:na]
at java.base/java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224) ~[na:na]
at java.base/java.net.SocksSocketImpl.connect(SocksSocketImpl.java:403) ~[na:na]
at java.base/java.net.Socket.connect(Socket.java:591) ~[na:na]
at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:121) ~[httpclient-4.5.12.jar:4.5.12]
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180) ~[httpclient-4.5.12.jar:4.5.12]
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:144) ~[httpclient-4.5.12.jar:4.5.12]
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:134) ~[httpclient-4.5.12.jar:4.5.12]
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:605) ~[httpclient-4.5.12.jar:4.5.12]
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:440) ~[httpclient-4.5.12.jar:4.5.12]
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835) ~[httpclient-4.5.12.jar:4.5.12]
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:118) ~[httpclient-4.5.12.jar:4.5.12]
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56) ~[httpclient-4.5.12.jar:4.5.12]
at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:173) ~[jersey-apache-client4-1.19.1.jar:1.19.1]
... 75 common frames omitted
2020-12-06 17:15:34.738 WARN 1 --- [ main] c.n.d.s.t.d.RetryableEurekaHttpClient : Request execution failed with message: java.net.ConnectException: Connection refused (Connection refused)
2020-12-06 17:15:34.748 ERROR 1 --- [ main] com.netflix.discovery.DiscoveryClient : DiscoveryClient_GATEWAY/gateway:gateway:8760 - was unable to refresh its cache! status = Cannot execute request on any known server
As you can see, it's still trying to connect to Eureka.
Versions
Spring Cloud: Hoxton.SR5
Jib
Minikube: 1.15.1
K8s: 1.19
Java: 11
Any help would be greatly appreciated! Thank you!
Are you sure you should have spring.cloud.kubernetes.enabled=false in your application.yml? If I understand the docs correctly, you need to leave it to the default value (true) in order for it to do the detection and load the kubernetes profile.
If you disable it, it will never load your application-kubernetes.yaml, so setting it to true inside that file will have no effect.
As I understand it you can turn off kubernetes features (e.g. spring.cloud.kubernetes.config.enabled=false) in your main YAML, but not the entire k8s integration if you want profile autoconfiguration to work.
Here is the application.yml, application-kubernetes.yml, and build.gradle combo that finally worked for me:
build.gradle
dependencies {
implementation "org.springframework.boot:spring-boot-starter-webflux"
implementation "org.springframework.boot:spring-boot-starter-security"
implementation "org.springframework.security:spring-security-oauth2-client"
implementation "org.springframework.cloud:spring-cloud-starter-gateway"
implementation "org.springframework.cloud:spring-cloud-starter-netflix-eureka-client"
implementation "org.springframework.cloud:spring-cloud-starter-gateway"
implementation "org.springframework.cloud:spring-cloud-starter-kubernetes-all"
implementation 'org.springframework.boot:spring-boot-starter-actuator'
testImplementation "org.springframework.boot:spring-boot-starter-test"
testImplementation "org.springframework.cloud:spring-cloud-starter-netflix-eureka-server"
}
application.yml
server:
port: 8080
spring:
application:
name: gateway
cloud:
kubernetes:
loadbalancer:
enabled: false
enabled: false
gateway:
routes:
- predicates:
- Path=/**
id: r-core
uri: lb://r-core
eureka:
client:
registerWithEureka: true
serviceUrl:
defaultZone: ${EUREKA_SERVER:http://localhost:8761/eureka}
management:
endpoints:
web:
exposure:
include:
- mappings
- env
- health
- info
application-kubernetes.yml
spring:
cloud:
loadbalancer:
ribbon:
enabled: false
discovery:
locator:
enabled: true
kubernetes:
loadbalancer:
enabled: true
enabled: true
eureka:
client:
enabled: false

SpringBoot + RabbitMQ throwing error : java.net.ConnectException: Connection refused

I have hosted a multimodule project on heroku and receiving the following error when trying to run my Spring Boot Application.
2018-06-13T05:34:47.611296+00:00 app[web.1]: 2018-06-13 05:34:47.611 INFO 4 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'rabbitConnectionFactory' has been autodetected for JMX exposure
2018-06-13T05:34:47.617422+00:00 app[web.1]: 2018-06-13 05:34:47.617 INFO 4 --- [ main] 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]
2018-06-13T05:34:47.646470+00:00 app[web.1]: 2018-06-13 05:34:47.646 INFO 4 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 2147483647
2018-06-13T05:34:47.660578+00:00 app[web.1]: 2018-06-13 05:34:47.660 INFO 4 --- [ container-1] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [localhost:5672]
2018-06-13T05:34:47.680639+00:00 app[web.1]: 2018-06-13 05:34:47.679 ERROR 4 --- [ container-1] o.s.a.r.l.SimpleMessageListenerContainer : Failed to check/redeclare auto-delete queue(s).
2018-06-13T05:34:47.680646+00:00 app[web.1]:
2018-06-13T05:34:47.680648+00:00 app[web.1]: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
2018-06-13T05:34:47.680650+00:00 app[web.1]: at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:62) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
2018-06-13T05:34:47.680651+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:476) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
2018-06-13T05:34:47.680656+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:614) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
2018-06-13T05:34:47.680658+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.createConnection(ConnectionFactoryUtils.java:240) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
2018-06-13T05:34:47.680659+00:00 app[web.1]: at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1797) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
The issue I see is, it is trying to connect some localhost whereas I have my addon CloudAMQP
Little Lemur added in heroku and I have added these to my both Application.yml file:
spring:
profiles: heroku
mvc:
async:
request-timeout: 3600000
rabbitmq:
addresses: amqp://****:*****#puma.rmq.cloudamqp.com/uyjgxslh
host: puma.rmq.cloudamqp.com
port: 1883
username: ****:****
password: *****
In my webModule I have this code:
#SpringBootApplication
public class SpringBootHerokuExampleApplication {
public final static String PDF_MERGE_QUEUE= "pdf-merge-queue";
#Bean
Queue queue(){
return new Queue(PDF_MERGE_QUEUE, false);
}
#Bean
TopicExchange exchange(){
return new TopicExchange("pdf-nerge-exchange");
}
#Bean
Binding binding(Queue queue, TopicExchange topicExchange){
return BindingBuilder.bind(queue).to(topicExchange).with(PDF_MERGE_QUEUE);
}
#Bean
SimpleMessageListenerContainer container(ConnectionFactory connectionFactory,
MessageListenerAdapter listenerAdapter){
SimpleMessageListenerContainer container = new SimpleMessageListenerContainer();
container.setConnectionFactory(connectionFactory);
container.setQueueNames(PDF_MERGE_QUEUE);
container.setMessageListener(listenerAdapter);
return container;
}
#Bean
MessageListenerAdapter listenerAdapter(RabbitMQListener rabbitMQListener){
return new MessageListenerAdapter(rabbitMQListener, "receiveMessage");
}
public static void main(String[] args) {
SpringApplication.run(SpringBootHerokuExampleApplication.class, args);
}
}
and in my worker module main method:
public class SpringBootHerokuExampleApplication {
public final static String PDF_MERGE_QUEUE= "pdf-merge-queue";
public static void main(String[] args) {
SpringApplication.run(SpringBootHerokuExampleApplication.class, args);
}
}
Please find below some more stack trace from Heroku logs :
handler of type [class org.springframework.web.servlet.resource.ResourceHttpRequestHandler]
2018-06-13T05:54:13.871350+00:00 app[worker.1]: 2018-06-13 05:54:13.870 INFO 4 --- [ main] o.s.b.a.e.web.EndpointLinksResolver : Exposing 2 endpoint(s) beneath base path '/actuator'
2018-06-13T05:54:13.897860+00:00 app[worker.1]: 2018-06-13 05:54:13.897 INFO 4 --- [ main] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Mapped "{[/actuator/health],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping$OperationHandler.handle(javax.servlet.http.HttpServletRequest,java.util.Map<java.lang.String, java.lang.String>)
2018-06-13T05:54:13.899632+00:00 app[worker.1]: 2018-06-13 05:54:13.899 INFO 4 --- [ main] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Mapped "{[/actuator/info],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto public java.lang.Object org.springframework.boot.actuate.endpoint.web.servlet.AbstractWebMvcEndpointHandlerMapping$OperationHandler.handle(javax.servlet.http.HttpServletRequest,java.util.Map<java.lang.String, java.lang.String>)
2018-06-13T05:54:13.901591+00:00 app[worker.1]: 2018-06-13 05:54:13.901 INFO 4 --- [ main] s.b.a.e.w.s.WebMvcEndpointHandlerMapping : Mapped "{[/actuator],methods=[GET],produces=[application/vnd.spring-boot.actuator.v2+json || application/json]}" onto protected java.util.Map<java.lang.String, java.util.Map<java.lang.String, org.springframework.boot.actuate.endpoint.web.Link>> org.springframework.boot.actuate.endpoint.web.servlet.WebMvcEndpointHandlerMapping.links(javax.servlet.http.HttpServletRequest,javax.servlet.http.HttpServletResponse)
2018-06-13T05:54:14.128560+00:00 app[worker.1]: 2018-06-13 05:54:14.128 INFO 4 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Registering beans for JMX exposure on startup
2018-06-13T05:54:14.145677+00:00 app[worker.1]: 2018-06-13 05:54:14.145 INFO 4 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Bean with name 'rabbitConnectionFactory' has been autodetected for JMX exposure
2018-06-13T05:54:14.154055+00:00 app[worker.1]: 2018-06-13 05:54:14.153 INFO 4 --- [ main] 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]
2018-06-13T05:54:14.199050+00:00 app[worker.1]: 2018-06-13 05:54:14.197 INFO 4 --- [ main] o.s.c.support.DefaultLifecycleProcessor : Starting beans in phase 2147483647
2018-06-13T05:54:14.230846+00:00 app[worker.1]: 2018-06-13 05:54:14.230 INFO 4 --- [cTaskExecutor-1] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [localhost:5672]
2018-06-13T05:54:14.425996+00:00 app[worker.1]: 2018-06-13 05:54:14.425 INFO 4 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8080 (http) with context path ''
2018-06-13T05:54:14.437981+00:00 app[worker.1]: 2018-06-13 05:54:14.435 INFO 4 --- [ main] o.e.SpringBootHerokuExampleApplication : Started SpringBootHerokuExampleApplication in 13.198 seconds (JVM running for 14.523)
2018-06-13T05:54:14.969935+00:00 app[web.1]: 2018-06-13 05:54:14.969 WARN 4 --- [ container-2] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
2018-06-13T05:54:14.970343+00:00 app[web.1]: 2018-06-13 05:54:14.970 INFO 4 --- [ container-2] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer#362d89d0: tags=[{}], channel=null, acknowledgeMode=AUTO local queue size=0
2018-06-13T05:54:14.971125+00:00 app[web.1]: 2018-06-13 05:54:14.971 INFO 4 --- [ container-3] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [localhost:5672]
2018-06-13T05:54:14.971946+00:00 app[web.1]: 2018-06-13 05:54:14.971 ERROR 4 --- [ container-3] o.s.a.r.l.SimpleMessageListenerContainer : Failed to check/redeclare auto-delete queue(s).
2018-06-13T05:54:14.971948+00:00 app[web.1]:
2018-06-13T05:54:14.971951+00:00 app[web.1]: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
2018-06-13T05:54:14.971952+00:00 app[web.1]: at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:62) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
2018-06-13T05:54:14.971953+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:476) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
2018-06-13T05:54:14.971956+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:614) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
2018-06-13T05:54:14.971957+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.createConnection(ConnectionFactoryUtils.java:240) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
2018-06-13T05:54:14.971958+00:00 app[web.1]: at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1797) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
2018-06-13T05:54:14.971959+00:00 app[web.1]: at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1771) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
2018-06-13T05:54:14.971960+00:00 app[web.1]: at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1752) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
2018-06-13T05:54:14.971961+00:00 app[web.1]: at org.springframework.amqp.rabbit.core.RabbitAdmin.getQueueProperties(RabbitAdmin.java:338) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
2018-06-13T05:54:14.971962+00:00 app[web.1]: at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.redeclareElementsIfNecessary(AbstractMessageListenerContainer.java:1604) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
2018-06-13T05:54:14.971964+00:00 app[web.1]: at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:963) [spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
2018-06-13T05:54:14.971965+00:00 app[web.1]: at java.lang.Thread.run(Thread.java:748) [na:1.8.0_171-heroku]
2018-06-13T05:54:14.971967+00:00 app[web.1]: Caused by: java.net.ConnectException: Connection refused (Connection refused)
2018-06-13T05:54:14.971969+00:00 app[web.1]: at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_171-heroku]
2018-06-13T05:54:14.971971+00:00 app[web.1]: at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_171-heroku]
2018-06-13T05:54:14.971972+00:00 app[web.1]: at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_171-heroku]
2018-06-13T05:54:14.971973+00:00 app[web.1]: at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_171-heroku]
2018-06-13T05:54:14.971974+00:00 app[web.1]: at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_171-heroku]
2018-06-13T05:54:14.971975+00:00 app[web.1]: at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_171-heroku]
2018-06-13T05:54:14.971976+00:00 app[web.1]: at com.rabbitmq.client.impl.SocketFrameHandlerFactory.create(SocketFrameHandlerFactory.java:60) ~[amqp-client-5.1.2.jar!/:5.1.2]
2018-06-13T05:54:14.971977+00:00 app[web.1]: at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:955) ~[amqp-client-5.1.2.jar!/:5.1.2]
2018-06-13T05:54:14.971978+00:00 app[web.1]: at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:907) ~[amqp-client-5.1.2.jar!/:5.1.2]
2018-06-13T05:54:14.971979+00:00 app[web.1]: at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:847) ~[amqp-client-5.1.2.jar!/:5.1.2]
2018-06-13T05:54:14.971980+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:449) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
2018-06-13T05:54:14.971981+00:00 app[web.1]: ... 9 common frames omitted
2018-06-13T05:54:14.971982+00:00 app[web.1]:
2018-06-13T05:54:14.972042+00:00 app[web.1]: 2018-06-13 05:54:14.971 INFO 4 --- [ container-3] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [localhost:5672]
2018-06-13T05:54:19.262272+00:00 app[worker.1]: 2018-06-13 05:54:19.261 WARN 4 --- [cTaskExecutor-1] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
2018-06-13T05:54:19.264406+00:00 app[worker.1]: 2018-06-13 05:54:19.264 INFO 4 --- [cTaskExecutor-1] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer#793be5ca: tags=[{}], channel=null, acknowledgeMode=AUTO local queue size=0
2018-06-13T05:54:19.272605+00:00 app[worker.1]: 2018-06-13 05:54:19.272 INFO 4 --- [cTaskExecutor-2] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [localhost:5672]
2018-06-13T05:54:19.976366+00:00 app[web.1]: 2018-06-13 05:54:19.976 WARN 4 --- [ container-3] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
2018-06-13T05:54:19.976491+00:00 app[web.1]: 2018-06-13 05:54:19.976 INFO 4 --- [ container-3] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer#42d37ed7: tags=[{}], channel=null, acknowledgeMode=AUTO local queue size=0
2018-06-13T05:54:19.977274+00:00 app[web.1]: 2018-06-13 05:54:19.977 INFO 4 --- [ container-4] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [localhost:5672]
2018-06-13T05:54:19.978248+00:00 app[web.1]: 2018-06-13 05:54:19.978 ERROR 4 --- [ container-4] o.s.a.r.l.SimpleMessageListenerContainer : Failed to check/redeclare auto-delete queue(s).
2018-06-13T05:54:19.978251+00:00 app[web.1]:
2018-06-13T05:54:19.978252+00:00 app[web.1]: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
2018-06-13T05:54:19.978253+00:00 app[web.1]: at org.springframework.amqp.rabbit.support.RabbitExceptionTranslator.convertRabbitAccessException(RabbitExceptionTranslator.java:62) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
2018-06-13T05:54:19.978255+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:476) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
2018-06-13T05:54:19.978256+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.CachingConnectionFactory.createConnection(CachingConnectionFactory.java:614) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
2018-06-13T05:54:19.978257+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.ConnectionFactoryUtils.createConnection(ConnectionFactoryUtils.java:240) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
2018-06-13T05:54:19.978258+00:00 app[web.1]: at org.springframework.amqp.rabbit.core.RabbitTemplate.doExecute(RabbitTemplate.java:1797) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
2018-06-13T05:54:19.978259+00:00 app[web.1]: at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1771) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
2018-06-13T05:54:19.978260+00:00 app[web.1]: at org.springframework.amqp.rabbit.core.RabbitTemplate.execute(RabbitTemplate.java:1752) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
2018-06-13T05:54:19.978261+00:00 app[web.1]: at org.springframework.amqp.rabbit.core.RabbitAdmin.getQueueProperties(RabbitAdmin.java:338) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
2018-06-13T05:54:19.978263+00:00 app[web.1]: at org.springframework.amqp.rabbit.listener.AbstractMessageListenerContainer.redeclareElementsIfNecessary(AbstractMessageListenerContainer.java:1604) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
2018-06-13T05:54:19.978264+00:00 app[web.1]: at org.springframework.amqp.rabbit.listener.SimpleMessageListenerContainer$AsyncMessageProcessingConsumer.run(SimpleMessageListenerContainer.java:963) [spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
2018-06-13T05:54:19.978265+00:00 app[web.1]: at java.lang.Thread.run(Thread.java:748) [na:1.8.0_171-heroku]
2018-06-13T05:54:19.978267+00:00 app[web.1]: Caused by: java.net.ConnectException: Connection refused (Connection refused)
2018-06-13T05:54:19.978268+00:00 app[web.1]: at java.net.PlainSocketImpl.socketConnect(Native Method) ~[na:1.8.0_171-heroku]
2018-06-13T05:54:19.978269+00:00 app[web.1]: at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350) ~[na:1.8.0_171-heroku]
2018-06-13T05:54:19.978270+00:00 app[web.1]: at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206) ~[na:1.8.0_171-heroku]
2018-06-13T05:54:19.978271+00:00 app[web.1]: at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188) ~[na:1.8.0_171-heroku]
2018-06-13T05:54:19.978272+00:00 app[web.1]: at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392) ~[na:1.8.0_171-heroku]
2018-06-13T05:54:19.978273+00:00 app[web.1]: at java.net.Socket.connect(Socket.java:589) ~[na:1.8.0_171-heroku]
2018-06-13T05:54:19.978274+00:00 app[web.1]: at com.rabbitmq.client.impl.SocketFrameHandlerFactory.create(SocketFrameHandlerFactory.java:60) ~[amqp-client-5.1.2.jar!/:5.1.2]
2018-06-13T05:54:19.978275+00:00 app[web.1]: at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:955) ~[amqp-client-5.1.2.jar!/:5.1.2]
2018-06-13T05:54:19.978276+00:00 app[web.1]: at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:907) ~[amqp-client-5.1.2.jar!/:5.1.2]
2018-06-13T05:54:19.978277+00:00 app[web.1]: at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:847) ~[amqp-client-5.1.2.jar!/:5.1.2]
2018-06-13T05:54:19.978278+00:00 app[web.1]: at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:449) ~[spring-rabbit-2.0.3.RELEASE.jar!/:2.0.3.RELEASE]
2018-06-13T05:54:19.978279+00:00 app[web.1]: ... 9 common frames omitted
2018-06-13T05:54:19.978280+00:00 app[web.1]:
2018-06-13T05:54:19.978370+00:00 app[web.1]: 2018-06-13 05:54:19.978 INFO 4 --- [ container-4] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [localhost:5672]
2018-06-13T05:54:24.281046+00:00 app[worker.1]: 2018-06-13 05:54:24.280 WARN 4 --- [cTaskExecutor-2] o.s.a.r.l.SimpleMessageListenerContainer : Consumer raised exception, processing can restart if the connection factory supports it. Exception summary: org.springframework.amqp.AmqpConnectException: java.net.ConnectException: Connection refused (Connection refused)
2018-06-13T05:54:24.281735+00:00 app[worker.1]: 2018-06-13 05:54:24.281 INFO 4 --- [cTaskExecutor-2] o.s.a.r.l.SimpleMessageListenerContainer : Restarting Consumer#7170b3b5: tags=[{}], channel=null, acknowledgeMode=AUTO local queue size=0
2018-06-13T05:54:24.291703+00:00 app[worker.1]: 2018-06-13 05:54:24.291 INFO 4 --- [cTaskExecutor-3] o.s.a.r.c.CachingConnectionFactory : Attempting to connect to: [localhost:5672]
Why is it trying to connect to localhost when I have specified host name explicitly in yml file? Any Idea?
Just found out that in yml file I have a profile named as heroku, when I removed it , it connected to the RabbitMQ in the given host.
If you are using spring boot you can configure Rabbit by spring cloud stream.
In this case you dont have to configure the beans and the configuration is much easier:
spring:
#---------------- RabbitMQ -----------------#
rabbitmq:
#Default username ans pass
dynamic: true
host: localhost
port: 5672
username: guest
password: guest
#---------------------------- RabbitMQ properties Commons ------------------------------#
cloud:
stream:
bindings:
springCloudBusInput:
destination: InputExchange
group: Queue
producer:
exchangeAutoDelete: false
springCloudBusOutput:
destination: InputExchange
group: Queue
consumer:
exchangeAutoDelete: false
Then you have to create the listener:
#Component
public class RemoteEventListener implements ApplicationListener<InputEvent> {
#Override
public void onApplicationEvent(InputEvent inputEvent) {
//whatever you want to do when a InputEvent Type is received in the queue
}
}
In this case My app is writing and receiving from the same exchange
and queue (Because of testing so stuff)
If you want to configure rabbit the way you shown, try to create a configuration class with the beans of the queue, exchange and biding with #Configuration. Dont declare the beans in your app class.
It seems it can not read the autodelete property of the queue, but if I'm not wrong I should take the default.
Maybe You have network issues
Check the rabbitmq and restart it
Can you acces to rabbitMq administrator interface?
About the comment about whi is trying to connect with localhost add this to your bean definition:
#Autowired
private ConnectionFactory rabbitConnectionFactory
#Bean
public RabbitTemplate rubeExchangeTemplate() {
RabbitTemplate r = new RabbitTemplate(rabbitConnectionFactory);
r.setExchange("rmq.rube.exchange");
r.setRoutingKey("rube.key");
r.setConnectionFactory(rabbitConnectionFactory);
return r;
}
also remove addresses of your application.yml

Connection refused: connect in jhipster

I am new to Jhipster. I have tried to run mvnw but request execution error of Connection refused: connect is occurred.
2017-07-14 10:36:17.411 INFO 19864 --- [ restartedMain] com.netflix.discovery.DiscoveryClient : Saw local status change event StatusChangeEvent [timestamp=1500008777411, current=UP, previous=STARTING]
2017-07-14 10:36:17.946 INFO 19864 --- [ restartedMain] com.lxisoft.diviso.DivisoApp : Started DivisoApp in 27.953 seconds (JVM running for 29.457)
2017-07-14 10:36:17.961 INFO 19864 --- [ restartedMain] com.lxisoft.diviso.DivisoApp :
----------------------------------------------------------
Application 'diviso' is running! Access URLs:
Local: http://localhost:8080
External: http://192.168.43.43:8080
Profile(s): [swagger, dev]
----------------------------------------------------------
2017-07-14 10:36:17.978 INFO 19864 --- [ restartedMain] com.lxisoft.diviso.DivisoApp :
----------------------------------------------------------
Config Server: Not found or not setup for this application
----------------------------------------------------------
2017-07-14 10:36:18.463 WARN 19864 --- [nfoReplicator-0] c.c.c.ConfigServicePropertySourceLocator : Could not locate PropertySource: I/O error on GET request for "http://localhost:8761/config/diviso/dev/master": Connection refused: connect; nested exception is java.net.ConnectException: Connection refused: connect
2017-07-14 10:36:18.467 INFO 19864 --- [nfoReplicator-0] com.netflix.discovery.DiscoveryClient : DiscoveryClient_DIVISO/diviso:44489811627d5f65d0e44a2af1489c68: registering service...
2017-07-14 10:36:20.480 ERROR 19864 --- [nfoReplicator-0] c.n.d.s.t.d.RedirectingEurekaHttpClient : Request execution error
com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: connect
at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:187)
at com.sun.jersey.api.client.filter.GZIPContentEncodingFilter.handle(GZIPContentEncodingFilter.java:123)
at com.netflix.discovery.EurekaIdentityHeaderFilter.handle(EurekaIdentityHeaderFilter.java:27)
at com.sun.jersey.api.client.Client.handle(Client.java:652)
at com.sun.jersey.api.client.WebResource.handle(WebResource.java:682)
at com.sun.jersey.api.client.WebResource.access$200(WebResource.java:74)
at com.sun.jersey.api.client.WebResource$Builder.post(WebResource.java:570)
at com.netflix.discovery.shared.transport.jersey.AbstractJerseyEurekaHttpClient.register(AbstractJerseyEurekaHttpClient.java:56)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.execute(EurekaHttpClientDecorator.java:59)
at com.netflix.discovery.shared.transport.decorator.MetricsCollectingEurekaHttpClient.execute(MetricsCollectingEurekaHttpClient.java:73)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.execute(EurekaHttpClientDecorator.java:59)
at com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient.executeOnNewServer(RedirectingEurekaHttpClient.java:118)
at com.netflix.discovery.shared.transport.decorator.RedirectingEurekaHttpClient.execute(RedirectingEurekaHttpClient.java:79)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.execute(EurekaHttpClientDecorator.java:59)
at com.netflix.discovery.shared.transport.decorator.RetryableEurekaHttpClient.execute(RetryableEurekaHttpClient.java:119)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator$1.execute(EurekaHttpClientDecorator.java:59)
at com.netflix.discovery.shared.transport.decorator.SessionedEurekaHttpClient.execute(SessionedEurekaHttpClient.java:77)
at com.netflix.discovery.shared.transport.decorator.EurekaHttpClientDecorator.register(EurekaHttpClientDecorator.java:56)
at com.netflix.discovery.DiscoveryClient.register(DiscoveryClient.java:798)
at com.netflix.discovery.InstanceInfoReplicator.run(InstanceInfoReplicator.java:104)
at com.netflix.discovery.InstanceInfoReplicator$1.run(InstanceInfoReplicator.java:88)
at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:511)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.access$201(ScheduledThreadPoolExecutor.java:180)
at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:293)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: java.net.ConnectException: Connection refused: connect
at java.net.DualStackPlainSocketImpl.waitForConnect(Native Method)
at java.net.DualStackPlainSocketImpl.socketConnect(DualStackPlainSocketImpl.java:85)
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:350)
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:206)
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:188)
at java.net.PlainSocketImpl.connect(PlainSocketImpl.java:172)
at java.net.SocksSocketImpl.connect(SocksSocketImpl.java:392)
at java.net.Socket.connect(Socket.java:589)
at org.apache.http.conn.scheme.PlainSocketFactory.connectSocket(PlainSocketFactory.java:121)
at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:180)
at org.apache.http.impl.conn.AbstractPoolEntry.open(AbstractPoolEntry.java:144)
at org.apache.http.impl.conn.AbstractPooledConnAdapter.open(AbstractPooledConnAdapter.java:134)
at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:610)
at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:445)
at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:118)
at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
at com.sun.jersey.client.apache4.ApacheHttpClient4Handler.handle(ApacheHttpClient4Handler.java:173)
... 30 common frames omitted
Could not locate PropertySource: I/O error on GET request for "http://localhost:8761/config/diviso/dev/master": Connection refused: connect; nested exception is java.net.ConnectException: Connection refused
This warning message means that your application could not connect to its spring cloud config server: JHipster Registry.
In dev profile, this is just a warning that you can ignore as your application can run with local application properties in sc/main/resources/config.
In prod profile, this would be an error and your application would not start. The registry must be started before your app because this is where your app gets its application properties from and registers itself as an Eureka client.
So in dev, you can ignore this warning or if it annoys you, you can start a registry.
If your app is a monolith application and not a microservice application, you can opt out the discovery client question, it'll be simpler to deploy if you don't need horizontal scaling.
The same issue happened with me, although I have already generated and modified my project before.
In case you are using MySql, go to phpMyAdmin page and type in your credentials. Worked for me.

Embedded Tomcat won't listen to port 80 in AWS Elastic Beanstalk

I'm launching a Spring Boot .jar with Embedded Tomcat to an Elastic Beanstalk (Java) instance.
server.port=80 in the configuration file, however EB won't let Tomcat bind to port 80.
What's preventing Tomcat from listening to port 80 and how do I fix it?
Here's the pertinent section of the logs:
Caused by: org.apache.catalina.LifecycleException: service.getName(): "Tomcat"; Protocol handler start failed
at org.apache.catalina.connector.Connector.startInternal(Connector.java:1000) ~[tomcat-embed-core-8.5.11.jar!/:8.5.11]
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150) ~[tomcat-embed-core-8.5.11.jar!/:8.5.11]
... 21 common frames omitted
Caused by: java.net.SocketException: Permission denied
at sun.nio.ch.Net.bind0(Native Method) ~[na:1.8.0_121]
at sun.nio.ch.Net.bind(Net.java:433) ~[na:1.8.0_121]
at sun.nio.ch.Net.bind(Net.java:425) ~[na:1.8.0_121]
at sun.nio.ch.ServerSocketChannelImpl.bind(ServerSocketChannelImpl.java:223) ~[na:1.8.0_121]
at sun.nio.ch.ServerSocketAdaptor.bind(ServerSocketAdaptor.java:74) ~[na:1.8.0_121]
at org.apache.tomcat.util.net.NioEndpoint.bind(NioEndpoint.java:210) ~[tomcat-embed-core-8.5.11.jar!/:8.5.11]
at org.apache.tomcat.util.net.AbstractEndpoint.start(AbstractEndpoint.java:980) ~[tomcat-embed-core-8.5.11.jar!/:8.5.11]
at org.apache.coyote.AbstractProtocol.start(AbstractProtocol.java:573) ~[tomcat-embed-core-8.5.11.jar!/:8.5.11]
at org.apache.catalina.connector.Connector.startInternal(Connector.java:993) ~[tomcat-embed-core-8.5.11.jar!/:8.5.11]
... 22 common frames omitted
2017-02-09 09:05:28.126 INFO 2451 --- [ main] o.apache.catalina.core.StandardService : Stopping service Tomcat
2017-02-09 09:05:28.156 INFO 2451 --- [ main] utoConfigurationReportLoggingInitializer :
Error starting ApplicationContext. To display the auto-configuration report re-run your application with 'debug' enabled.
2017-02-09 09:05:28.167 ERROR 2451 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
The Tomcat connector configured to listen on port 80 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 80, or configure this application to listen on another port.
2017-02-09 09:05:28.175 INFO 2451 --- [ main] ationConfigEmbeddedWebApplicationContext : Closing org.springframework.boot.context.embedded.AnnotationConfigEmbeddedWebApplicationContext#5387f9e0: startup date [Thu Feb 09 09:05:19 UTC 2017]; root of context hierarchy
2017-02-09 09:05:28.178 INFO 2451 --- [ main] o.s.j.e.a.AnnotationMBeanExporter : Unregistering JMX-exposed beans on shutdown
I assume topic starter already resolved this problem, but I'll post my solution here for the new people who'll be stuck on the same issue.
I've made my Spring Boot application accessible from port 80 on AWS Elastic Beanstalk by setting environment property SERVER_PORT to 5000 (you can set it in "Configuration" > "Software Configuration").
Idea taken from here

Categories