I am trying to connect to a rabitmq from a springbok app with a newly created user on rabbitmq but according to logs the app is always trying to connect with the default guest user
the rabbitmq logs
2019-02-13 00:12:38.860 [error] <0.1318.0> Error on AMQP connection <0.1318.0> (192.168.1.185:60124 -> 192.168.1.185:5672, state: starting):
PLAIN login refused: user 'guest' can only connect via localhost
the yaml spring boot app config
spring:
rabbitmq:
host: 111.111.111.111
port: 5672
username: user1
password: user1
connectionName: com.test.user
the spring boot error log
Caused by: com.rabbitmq.client.AuthenticationFailureException: ACCESS_REFUSED - Login was refused using authentication mechanism PLAIN. For details see the broker logfile.
at com.rabbitmq.client.impl.AMQConnection.start(AMQConnection.java:362)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1104)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1054)
at com.rabbitmq.client.ConnectionFactory.newConnection(ConnectionFactory.java:1218)
at org.springframework.amqp.rabbit.connection.AbstractConnectionFactory.createBareConnection(AbstractConnectionFactory.java:471)
... 10 common frames omitted
In the springboot app, under resources, you may create one application.properties file and configure the following information.
spring.rabbitmq.host=111.111.111.111
spring.rabbitmq.port=5672
spring.rabbitmq.username=user1
spring.rabbitmq.password=user1
you may write as:
rabbitmq:
config:
host: 111.111.111.111
port: 5672
username: user1
password: user1
connectionName: com.test.user
Related
Here in my company we are trying to stablish a micro service based environment, where all the micro services to come will be monitored by an actuator application. We've created two applications, the first micro service and the spring boot admin project, locally all went well and all, then we used docker on this two applications, a container for each one and here start the problems.
Both applications run on port 8080 inside the container, then we assign an external port for its access, this seems to affect the way actuator communicates because now I'm having issues when the client application goes down, the admin is not sending any emails alerting as it did when locally. Here're my configs (changing some parameters):
Client:
.properties:
server.port=8080
spring.boot.admin.client.instance.name=Monitoramento Catracas
spring.boot.admin.client.url=http://my-ip:6060
spring.boot.admin.client.instance.service-base-url=http://my-ip:7070
docker-compose.yml:
services:
my-service:
build:
context: ./
dockerfile: my-file.dockerfile
image: test/my-image
container_name: my-container
ports:
- 7070:8080
Spring Boot Admin Application:
.properties
spring.mail.host=smtp.office365.com
spring.mail.port=587
spring.mail.username=email#email
spring.mail.password=12345
spring.mail.properties.mail.smtp.auth=true
spring.mail.properties.mail.smtp.starttls.enable=true
server.port=6060
spring.boot.admin.notify.mail.enabled=true
spring.boot.admin.notify.mail.from=email#email
spring.boot.admin.notify.mail.to=email_2#email
spring.boot.admin.notify.mail.template=classpath:templates/email-template.html
docker-compose.yml:
services:
ms-admin:
build:
context: ./ms-admin
dockerfile: ms-admin.dockerfile
image: cap/ms-admin
container_name: ms-admin
ports:
- 6060:8080
And this is what I get when I turn off the client application:
2022-12-09 17:06:10.534 WARN 1 --- [or-http-epoll-3] d.c.b.a.s.notify.NotificationTrigger : Couldn't notify for event InstanceStatusChangedEvent(super=InstanceEvent(instance=2cc8546ac366, version=4, timestamp=2022-12-09T17:06:10.275Z, type=STATUS_CHANGED), statusInfo=StatusInfo(status=OFFLINE, details={exception=org.springframework.web.reactive.function.client.WebClientRequestException, message=finishConnect(..) failed: Connection refused: /my-ip:7070; nested exception is io.netty.channel.AbstractChannel$AnnotatedConnectException: finishConnect(..) failed: Connection refused: /my-ip:7070}))
ms-monitoramento-hml |
ms-monitoramento-hml | org.springframework.mail.MailSendException: Mail server connection failed; nested exception is com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.office365.com, 587; timeout -1;
ms-monitoramento-hml | nested exception is:
ms-monitoramento-hml | java.net.UnknownHostException: smtp.office365.com. Failed messages: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.office365.com, 587; timeout -1;
ms-monitoramento-hml | nested exception is:
ms-monitoramento-hml | java.net.UnknownHostException: smtp.office365.com
ms-monitoramento-hml | Caused by: com.sun.mail.util.MailConnectException: Couldn't connect to host, port: smtp.office365.com, 587; timeout -1
ms-monitoramento-hml | at com.sun.mail.smtp.SMTPTransport.openServer(SMTPTransport.java:2210) ~[jakarta.mail-1.6.7.jar!/:1.6.7]
ms-monitoramento-hml | at com.sun.mail.smtp.SMTPTransport.protocolConnect(SMTPTransport.java:722) ~[jakarta.mail-1.6.7.jar!/:1.6.7]
ms-monitoramento-hml | at javax.mail.Service.connect(Service.java:342) ~[jakarta.mail-1.6.7.jar!/:1.6.7]
ms-monitoramento-hml | at org.springframework.mail.javamail.JavaMailSenderImpl.connectTransport(JavaMailSenderImpl.java:518) ~[spring-context-support-5.3.23.jar!/:5.3.23]
ms-monitoramento-hml | at org.springframework.mail.javamail.JavaMailSenderImpl.doSend(JavaMailSenderImpl.java:437) ~[spring-context-support-5.3.23.jar!/:5.3.23]
ms-monitoramento-hml | ... 124 common frames omitted
Hope someone can help me with this one, thanks
The error message is very clear, it says
Mail server connection failed.
Couldn't connect to host, port: smtp.office365.com, 587
So this is an network issue. Maybe there is some kind of firewall blocking the request or the docker containers are not able to reach the internet at all.
Maybe talk to the people who provide the docker host and check the connection rules with them.
I am trying to connect to Teradata from my spring boot project. But I am constantly getting unknown host exception. When I do Test Net Connection from Power shell, TCP Test Succeeded comes as true. Also I am able to connect to the Teradata from Teradata SQL assistant. Below is config from application config file. Properties in <> removed for security reason. the Teradata we have is via LDAP authentication
spring:
jpa:
show-sql: true
database-platform: org.hibernate.dialect.TeradataDialect
datasource:
driverClassName: com.teradata.jdbc.TeraDriver
url: jdbc:teradata://:/LOGMECH=LDAP,database=,charset=ASCII,tmode=ANSI
username:
password:
Exception is below: ( values in <> removed for security reason)
java.sql.SQLException: [Teradata JDBC Driver] [TeraJDBC 16.20.00.13] [Error 1000] [SQLState 08S01] Login failure for Connection to :1025 Tue Jul 05 23:12:11 CEST 2022 socket orig=:1025 cid=6007091b sess=0 java.net.UnknownHostException: HOSTNAME :1025
I have a spring boot app with simple GET method "sayHello" i have configured API gateway to route calls to my microservice module when uri pattern matches /ms1/**
Both gateway and microservice registered to the Registry service and dashboard displays both registered
API-GATEAY YAML configuration
server:
port: '8010'
spring:
application:
name: MY-GATEWAY
cloud:
compatibility-verifier:
enabled: false
gateway:
routes:
- id: MICRO-SERVICE1
uri: lb://MICRO-SERVICE1
predicates:
- Path=/ms1/**
eureka:
client:
register-with-eureka: true
fetch-registry: true
service-uri: http://localhost:8761/eureka/
intance:
hostname: localhost
MICRO-SERVICE1 YAML configuration
server:
port: '8030'
spring:
application:
name: MICRO-SERVICE1
eureka:
client:
register-with-eureka: true
fetch-registry: true
service-uri: http://localhost:8761/eureka/
intance:
hostname: localhost
Controller's GET method
#RestController
#RequestMapping("/ms1")
public class UATController {
#GetMapping(value = "/sayHello")
public #ResponseBody ResponseEntity<String> sayHello() {
String message = "Hello World";
return new ResponseEntity<String>(message, HttpStatus.OK);
}
}
I am getting following error when i access via gateway, however when i access my microservice directly it works any idea where i am wrong here?
http://localhost:8010/ms1/sayHello <- Not working via gateway
http://localhost:8030/ms1/sayHello <- Working direct access
Wed Dec 07 23:32:31 EST 2021
[83b324d4-2] There was an unexpected error (type=Internal Server Error, status=500).
Connection timed out: no further information: DESKTOP-1.verizon.net/192.168.1.160:8030
io.netty.channel.AbstractChannel$AnnotatedConnectException: Connection timed out: no further information: DESKTOP-1.verizon.net/192.168.1.160:8030
Suppressed: The stacktrace has been enhanced by Reactor, refer to additional information below:
Error has been observed at the following site(s):
*__checkpoint ⇢ org.springframework.cloud.gateway.filter.WeightCalculatorWebFilter [DefaultWebFilterChain]
*__checkpoint ⇢ org.springframework.boot.actuate.metrics.web.reactive.server.MetricsWebFilter [DefaultWebFilterChain]
*__checkpoint ⇢ HTTP GET "/ms1/sayHello" [ExceptionHandlingWebHandler]
Original Stack Trace:
Caused by: java.net.ConnectException: Connection timed out: no further information
at java.base/sun.nio.ch.Net.pollConnect(Native Method)
at java.base/sun.nio.ch.Net.pollConnectNow(Net.java:672)
at java.base/sun.nio.ch.SocketChannelImpl.finishConnect(SocketChannelImpl.java:946)
at io.netty.channel.socket.nio.NioSocketChannel.doFinishConnect(NioSocketChannel.java:330)
at io.netty.channel.nio.AbstractNioChannel$AbstractNioUnsafe.finishConnect(AbstractNioChannel.java:334)
at io.netty.channel.nio.NioEventLoop.processSelectedKey(NioEventLoop.java:707)
at io.netty.channel.nio.NioEventLoop.processSelectedKeysOptimized(NioEventLoop.java:655)
at io.netty.channel.nio.NioEventLoop.processSelectedKeys(NioEventLoop.java:581)
at io.netty.channel.nio.NioEventLoop.run(NioEventLoop.java:493)
at io.netty.util.concurrent.SingleThreadEventExecutor$4.run(SingleThreadEventExecutor.java:986)
at io.netty.util.internal.ThreadExecutorMap$2.run(ThreadExecutorMap.java:74)
at io.netty.util.concurrent.FastThreadLocalRunnable.run(FastThreadLocalRunnable.java:30)
at java.base/java.lang.Thread.run(Thread.java:833)
I have faced the same issue today as well when running the micro services, the gateway and the Eureka discovery all on localhost.
I was able to solve it by adding eureka.instance.preferIpAddress=true to my application.properties of the micro services. That property causes that the services will advertise their IP addresses instead of the host names. More info here under point 2.6: https://cloud.spring.io/spring-cloud-netflix/multi/multi_spring-cloud-eureka-server.html. My guess is that there was an issue with forwarding the requests to the microservices due to using localhost.
Edit: Here are my settings
There is nothing special in my setup. These are the values I am using in my application.properties
The microservice is using:
spring.cloud.discovery.enabled=true
spring.application.name=[The name of my app]
eureka.client.register.with-eureka=true
eureka.client.service-url.defaultZone=http://localhost:8999/eureka
eureka.instance.prefer-ip-address=true
The properties for the gateway are similar to the service one.
The load balancing part looks like this:
spring.cloud.gateway.routes[0].id=[Same name as my app]
spring.cloud.gateway.routes[0].uri=lb://[name of my app]
spring.cloud.gateway.routes[0].predicates=Path=/test/**
Where test/** is the part of the Rest URL of my application
Adding DESKTOP-1.verizon.net to hosts file worked, following is entry I have added to C:\Windows\System32\drivers\etc\hosts file. Unfortunately eureka.instance.prefer-ip-address=true didn't work for me
127.0.0.1 DESKTOP-1.verizon.net
have added this settings in yml file in all services and its work for me.
eureka:
instance:
prefer-ip-address: true
I just faced the same issue, and in my case, I had a problem with port number. I was using the code below to set up the port for me:
server:
port: ${random.int(8010,8013)}
I noticed when the service starts, even though the log shows "Tomcat started on port(s): 8010", on Eureka's page shows "host.docker.internal:my-service:8011"
This error happens randomly, because sometimes when you re-start the microservice, it is able to register on Eureka correctly.
You can do a simple test using a non-random port number.
I haven't figured out how to solve it for random port number.
UPDATING:
I did this and worked fine for me:
server:
port: 0
spring:
application:
name: user-service
eureka:
instance:
hostname: localhost
prefer-ip-address: true
client:
serviceUrl:
defaultZone: http://localhost:9000/eureka/
I am trying to create new datasource in the Weblogic 12c (version: 12.2.1.3.0).
Below are the details of the databasource:
Name: TestDataSource
JNDI Name: jdbc/test.data
DatabaseType: Oracle
Database Driver: Oracle's Driver (Thin XA) for Instance
connections; Verions: Any
Database Name: XXXX
Host Name: xxxxxx
Port: 1521
Database User Name: XXXX
Password: XXXX
Driver Class Name: oracle.jdbc.OracleDriver
Select Targets: serverName
After saving I am getting below exception:
oracle.net.ns.NetException: Listener refused the connection with the following error: ORA-12519, TNS:no appropriate service handler found
Substituted for the exception oracle.net.ns.NetException which lacks a String contructor, original message - Listener refused the connection with the following error: ORA-12519, TNS:no appropriate service handler found
I am able to connect to the same database via SQLDeveloper without any error.
Please let me know if I am missing any property or step while setup.
I have a relatively simple setup. A Spring Could Config server, and a Spring Cloud Eureka server. (I refer Eureka server as Discover everywhere in my config...) The config server uses a Git repository for finding the appropriate config.
Everything is in Docker containers. I use docker-compose to build my services. The Gateway server should wait for config server to come up. I'll provide the source of the file further down.
So, when I build and start the containers, the discovery (Eureka) server doesn't want to come up. It exits with an exception. It is really long, so I just add the most important part here:
019-01-27 23:52:17,494 [INFO ] o.s.c.c.c.ConfigServicePropertySourceLocator.getRemoteEnvironment [main] – Fetching config from server at : http://tao-elszamolas-config:9001
2019-01-27 23:52:17,898 [INFO ] o.s.c.c.c.ConfigServicePropertySourceLocator.getRemoteEnvironment [main] – Connect Timeout Exception on Url - http://tao-elszamolas-config:9001. Will be trying the next url if available
2019-01-27 23:52:17,902 [ERROR ] o.s.b.SpringApplication.reportFailure [main] – Application run failed
java.lang.IllegalStateException: Could not locate PropertySource and the fail fast property is set, failing
... Something...Something
Caused by: org.springframework.web.client.ResourceAccessException: I/O error on GET request for "http://tao-elszamolas-config:9001/discovery-server/prod": Connection refused (Connection refused); nested exception is java.net.ConnectException: Connection refused (Connection refused)
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:743) ~[spring-web-5.1.3.RELEASE.jar!/:5.1.3.RELEASE]
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:669) ~[spring-web-5.1.3.RELEASE.jar!/:5.1.3.RELEASE]
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:578) ~[spring-web-5.1.3.RELEASE.jar!/:5.1.3.RELEASE]
at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.getRemoteEnvironment(ConfigServicePropertySourceLocator.java:218) ~[spring-cloud-config-client-2.1.0.RC3.jar!/:2.1.0.RC3]
at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.locate(ConfigServicePropertySourceLocator.java:96) ~[spring-cloud-config-client-2.1.0.RC3.jar!/:2.1.0.RC3]
... 15 more
Caused by: java.net.ConnectException: Connection refused (Connection refused)
at java.net.PlainSocketImpl.socketConnect(Native Method) ~[?:?]
at java.net.AbstractPlainSocketImpl.doConnect(AbstractPlainSocketImpl.java:399) ~[?:?]
at java.net.AbstractPlainSocketImpl.connectToAddress(AbstractPlainSocketImpl.java:242) ~[?:?]
at java.net.AbstractPlainSocketImpl.connect(AbstractPlainSocketImpl.java:224) ~[?:?]
at java.net.Socket.connect(Socket.java:591) ~[?:?]
at java.net.Socket.connect(Socket.java:540) ~[?:?]
at sun.net.NetworkClient.doConnect(NetworkClient.java:182) ~[?:?]
at sun.net.www.http.HttpClient.openServer(HttpClient.java:474) ~[?:?]
at sun.net.www.http.HttpClient.openServer(HttpClient.java:569) ~[?:?]
at sun.net.www.http.HttpClient.<init>(HttpClient.java:242) ~[?:?]
at sun.net.www.http.HttpClient.New(HttpClient.java:341) ~[?:?]
at sun.net.www.http.HttpClient.New(HttpClient.java:362) ~[?:?]
at sun.net.www.protocol.http.HttpURLConnection.getNewHttpClient(HttpURLConnection.java:1242) ~[?:?]
at sun.net.www.protocol.http.HttpURLConnection.plainConnect0(HttpURLConnection.java:1181) ~[?:?]
at sun.net.www.protocol.http.HttpURLConnection.plainConnect(HttpURLConnection.java:1075) ~[?:?]
at sun.net.www.protocol.http.HttpURLConnection.connect(HttpURLConnection.java:1009) ~[?:?]
at org.springframework.http.client.SimpleBufferingClientHttpRequest.executeInternal(SimpleBufferingClientHttpRequest.java:76) ~[spring-web-5.1.3.RELEASE.jar!/:5.1.3.RELEASE]
at org.springframework.http.client.AbstractBufferingClientHttpRequest.executeInternal(AbstractBufferingClientHttpRequest.java:48) ~[spring-web-5.1.3.RELEASE.jar!/:5.1.3.RELEASE]
at org.springframework.http.client.AbstractClientHttpRequest.execute(AbstractClientHttpRequest.java:53) ~[spring-web-5.1.3.RELEASE.jar!/:5.1.3.RELEASE]
at org.springframework.web.client.RestTemplate.doExecute(RestTemplate.java:734) ~[spring-web-5.1.3.RELEASE.jar!/:5.1.3.RELEASE]
at org.springframework.web.client.RestTemplate.execute(RestTemplate.java:669) ~[spring-web-5.1.3.RELEASE.jar!/:5.1.3.RELEASE]
at org.springframework.web.client.RestTemplate.exchange(RestTemplate.java:578) ~[spring-web-5.1.3.RELEASE.jar!/:5.1.3.RELEASE]
at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.getRemoteEnvironment(ConfigServicePropertySourceLocator.java:218) ~[spring-cloud-config-client-2.1.0.RC3.jar!/:2.1.0.RC3]
at org.springframework.cloud.config.client.ConfigServicePropertySourceLocator.locate(ConfigServicePropertySourceLocator.java:96) ~[spring-cloud-config-client-2.1.0.RC3.jar!/:2.1.0.RC3]
... 15 more
The only exception what I found in the Config server log is the one complaining about the connection to Discovery (Eureka) server. Yes, I try to register my config service inEureka for looking it up at startup of further microservices.
The connection is refused which means, the config server is not running at the time when Eureka server is trying to get its config or it is not listening on the given port, 9001.
How is it possible? I used the depends_on in my compose file, so it should wait for that.
Or why it finishes working? If I do the same thing on local without docker then it keeps trying to connect to Config, until the config server starts up. I'd like achieve the same behaviour using Docker.
Any advice would be appreciated!
And finally here are my config files:
docker-compose.yml:
version: "3"
services:
tao-elszamolas-config:
build: ./tao-elszamolas-config
container_name: tao-elszamolas-config
ports:
- "9001:9001"
volumes:
- "/tao-elszamolas/logs:/var/log/tao-elszamolas"
networks:
- taonetwork
tao-elszamolas-discovery:
build: ./tao-elszamolas-discovery
container_name: tao-elszamolas-discovery
depends_on:
- tao-elszamolas-config
ports:
- "9002:9002"
volumes:
- "/tao-elszamolas/logs:/var/log/tao-elszamolas"
networks:
- taonetwork
networks:
taonetwork:
driver: bridge
Dockerfile of Config Server:
FROM openjdk:11-jdk-slim
MAINTAINER BeszterceKK
COPY ./tao-elszamolas-config.jar /usr/src/taoelszamolas/tao-elszamolas-config.jar
WORKDIR /var/log/tao-elszamolas
WORKDIR /usr/src/taoelszamolas
ENV SPRING_PROFILES_ACTIVE prod
EXPOSE 9001
ENTRYPOINT ["java", "-DlogFileLocation=/var/log/tao-elszamolas", "-jar", "tao-elszamolas-config.jar"]
application.yml for Config server:
server:
port: 9001
spring:
application:
name: config-server
cloud:
config:
server:
git:
uri: https://github.com/something/something
username: something
password: something
skip-ssl-validation: true
security:
user:
name: something
password: something
eureka:
client:
serviceUrl:
defaultZone: http://something:something#tao-elszamolas-discovery:9002/eureka/
info:
artifact: tao-elszamolas-config
name: TAO Elszamolas Config Application
description: Tao elszamolas microservice elosztott szolgaltatas konfiguracio
version: 1.0.0
Dockerfile of Discovery (Eureka) Server:
FROM openjdk:11-jdk-slim
MAINTAINER BeszterceKK
COPY ./tao-elszamolas-discovery.jar /usr/src/taoelszamolas/tao-elszamolas-discovery.jar
WORKDIR /var/log/tao-elszamolas
WORKDIR /usr/src/taoelszamolas
ENV SPRING_PROFILES_ACTIVE prod
EXPOSE 9002
ENTRYPOINT ["java", "-DlogFileLocation=/var/log/tao-elszamolas", "-jar", "tao-elszamolas-discovery.jar"]
bootstrap.yml for Discovery (Eureka) server:
spring:
application:
name: discovery-server
cloud:
config:
fail-fast: true
name: discovery-server
uri: http://tao-elszamolas-config:9001
username: something
password: something
application.yml for Discovery (Eureka) server:
server:
port: 9002
eureka:
instance:
hostname: tao-elszamolas-discovery
client:
registerWithEureka: false
fetchRegistry: false
serviceUrl:
defaultZone: http://tao-elszamolas-discovery:9002/eureka
info:
artifact: tao-elszamolas-discovery
name: TAO Elszamolas Eureka Szolgaltatas monitor
description: Tao elszamolas automatikus szolgaltatas regisztracio
version: 1.0.0
And finally, this is how I start my containers. It is simply:
docker-compose up -d
The whole application stack works on local without Docker. So I guess the problem is with my Docker configuration.
One more thing to mention, generally, I don't want to publish the ports to host, only expose them on my custom network between the containers. This is why I tried to replace the PORTS with EXPOSE, but it didn't really help.
for startup Compose does not wait until a container is “ready” (whatever that means for your particular application) - only until it’s running
So, you should refer : https://docs.docker.com/compose/startup-order/
for wait until for config server container is ready first (already listened on port 9001), then starting Eureka server container.
You registry service try to start before configuration service is up. You have to force him to wait.
You can do it with condition: service_started, like below. But I think it is not working with version 3
version: '2.1'
# ...
tao-elszamolas-discovery:
build: ./tao-elszamolas-discovery
container_name: tao-elszamolas-discovery
depends_on:
- tao-elszamolas-config:
condition: service_started
ports:
- "9002:9002"
volumes:
- "/tao-elszamolas/logs:/var/log/tao-elszamolas"
networks:
- taonetwork
A solution for version 3 is to use healthcheck and restart: on-failure
Take a look at this post
Another solution is to use entrypoint section to launch a batch file at start which is pinging configuration service container while it is not responding.