Sping Boot & Spring Boot管理员无法从Docker容器发送警报电子邮件

mo49yndu  于 2022-12-22  发布在  Docker
关注(0)|答案(1)|浏览(327)

在我的公司里,我们正在尝试建立一个基于微服务的环境,所有的微服务都将被一个执行器应用程序监控。我们已经创建了两个应用程序,第一个微服务和spring boot管理项目,在本地一切都很顺利,然后我们在这两个应用程序上使用了docker,每个应用程序都有一个容器,现在开始解决问题。
这两个应用程序都运行在容器内部的端口8080上,然后我们为其访问分配了一个外部端口,这似乎影响了执行器的通信方式,因为现在我遇到了客户端应用程序关闭时的问题,管理员不会像在本地时那样发送任何电子邮件警报。
委托单位:
.特性:

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管理应用程序:
3、特性

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

这是我关闭客户端应用程序后得到的结果:

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

希望有人能帮我这个忙,谢谢

cbjzeqam

cbjzeqam1#

错误信息非常清楚,它说
邮件服务器连接失败。
Couldn't connect to host, port: smtp.office365.com, 587
所以这是一个网络问题。也许有某种防火墙阻止了请求或者Docker容器根本无法到达互联网。
也许可以和提供码头主机的人谈谈,并与他们检查连接规则。

相关问题