英文:
App with Event logger on port:8080 listening calls from API port:8090 in SpringBoot
问题
我正在尝试创建一个具有通知服务的应用程序,每当API上进行呼叫时都会触发通知。
我是否可以在端口8080上创建一个记录器,并在服务器上运行应用程序时让它监听另一个服务器上运行的API。
这两个应用程序都在本地机器上使用Docker进行测试。
到目前为止,我一直在阅读https://www.baeldung.com/spring-boot-logging,以便实现它,但我在理解路径映射方面遇到了问题。
有什么建议吗?
英文:
I'm trying to create an app with notification service whenever a call is made on API.
Is it possible for me to create a logger on port:8080 and when app is run on the server it listens to api running on another server.
Both applications are run on local machine for testing purposes using Docker.
So far I've been reading https://www.baeldung.com/spring-boot-logging in order to implement it but I'm having problems with understanding the path mapping.
Any ideas?
答案1
得分: 0
首先让我们为这两个应用程序命名:
- API - 您想要监视的API服务
- Monitor - 想要查看对(1)发出了哪些调用的应用程序
有几种方法可以实现这一目标。
a) 在Monitor上打开一个套接字以接收传入的流量。手动通信IP地址和套接字端口给API服务器,让它建立与Monitor的连接并通过此“管道”发送一些数据包。这是最低级的方法,简单但非常脆弱,因为您必须协调服务的启动,并决定应用程序交换数据的“协议”。
b) REST:在Monitor应用程序上创建一个RESTful控制器,接受POST请求。手动通信IP地址和端口给API服务器。需要时向Monitor应用程序发起POST请求。这种方法更加健壮,但仍然需要谨慎地启动服务器。
c) 消息队列。安装消息队列系统,如RabbitMQ或ActiveMQ(可在Docker容器中使用)。API服务器将消息发布到队列,Monitor订阅队列。更加健壮,但仍然需要每个应用程序知道MQ服务器的地址,但现在可以以任何顺序停止/启动这两个应用程序。
d) Java日志文章是进入Java日志的良好起点。大多数用例会将日志记录到本地服务器上的本地文件中。还有一些将日志发送到远程位置的后端日志记录实现(我认为该文章没有涵盖它们),以及添加自定义接收此日志流量的方法。在此选项中,在API端,它将使用普通的日志记录代码,不知道日志的下游消费情况。您的监视应用程序将需要与特定的日志记录系统紧密集成。
英文:
First let's name the two applications:
- API - the API service that you want to monitor
- Monitor - which wants to see what calls are made to (1)
There are several ways to achieve this.
a) Open up a socket on Monitor for inbound traffic. Communicate the IP address and socket port manually to the API server, have it open up the connection to the Monitor and send some packet of data down this "pipe". This is the lowest level approach simple, but very fragile as you have to coordinate the starting of the services, and decide on a "protocol" for how the applications exchange data.
b) REST: Create a RESTful controller on the Monitor app that accepts a POST. Communicate the IP address and port manually to the API server. Initiate a POST request to the Monitor app when needed. This is more robust but still suffers from needing careful starting of the servers
c) Message Queue. install a message queue system like RabbitMQ or ActiveMQ (available in Docker containers). API server publishes a message to a Queue. Monitor subscribes to the Queue. Must more robust, still requires each application to be advised of the address of the MQ server, but now you can stop/start the two applications in any order
d) The java logging article is good started into java logging. Most use cases log to a local file on the local server. There are some implementations of backend logging that send logs to remote places (I don't think that article covers them), and there are ways of adding your own custom receiver of this log traffic. In this option, on the API side, it would use ordinary logging code with no knowledge of the downstream consumption of the logging. Your monitor app would need to integrate tightly into a particular logging system with this approach.
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论