简体   繁体   English

微服务,如何在任务完成时通知后端

[英]Microservices, how to notify backend when task complete

For example, if i have main application (backend) and some microservice, eg for image cropping.例如,如果我有主应用程序(后端)和一些微服务,例如用于图像裁剪。 User loads an image, making request to backend, backend using rabbitmq posts new task in the queue, then image cropping service pickup a task, completes it and i need somehow notify backend.用户加载图像,向后端发出请求,后端使用rabbitmq 在队列中发布新任务,然后图像裁剪服务拾取任务,完成它,我需要以某种方式通知后端。 What is options for this?这有什么选择? I need another microservice for such notifications?对于此类通知,我需要另一个微服务吗?

so... there are reaaaaaaly many ways to do that.所以......有很多方法可以做到这一点。

On the high level, what you want to achieve is to produce an event that 1 or more services can react to.在高层次上,您想要实现的是产生一个或多个服务可以响应的事件。 Now depending on what you have available, you can produce the event in a number of different ways.现在,根据您可用的资源,您可以通过多种不同的方式生成事件。

  1. if you want to be completely platform independent, you can use Apache Kafka.如果你想完全独立于平台,你可以使用 Apache Kafka。 It's a popular service specifically for what we need -> publishing events and processing them at mass-scale.这是一项很受欢迎的服务,专门针对我们的需求 -> 发布事件并大规模处理它们。 Kafka can be clustered, partitioned, have multiple parallel consumers of the same type (like multiple instances of your main backend service) or different types (3 different microservices that happen to be interested in a specific event). Kafka 可以集群、分区、具有多个相同类型的并行消费者(例如主后端服务的多个实例)或不同类型(碰巧对特定事件感兴趣的 3 个不同微服务)。 This bad boy just has it all and is famous for that.这个坏男孩拥有一切,并因此而闻名。 You can set up a cluster yourself or use one that comes out-of-the-box with some of the cloud platforms (like AWS for instance), but this might be more expensive and difficult to use compared to some cloud-specific fully-managed solutions.您可以自己设置一个集群,也可以使用某些云平台(例如 AWS)开箱即用的集群,但与某些特定于云的完全不同的云平台相比,这可能更昂贵且更难使用 -托管解决方案。

  2. if you're running your stuff on the google cloud, you can make it easier and cheaper by using the PubSub service.如果你在谷歌云上运行你的东西,你可以通过使用 PubSub 服务使它更容易和更便宜。 PubSub is a fully managed service that is scaled out-of-the-box (welcome to the cloud! you don't need to scale or cluster anything by yourself!). PubSub 是一项完全托管的服务,可开箱即用(欢迎使用云!您无需自行扩展或集群任何东西!)。

  3. if you're running on AWS, you can use SNS, or a more recent alternative - EventBridge (kinda like SNS, but booooooy what can it not do?).如果您在 AWS 上运行,则可以使用 SNS 或更新的替代方案 - EventBridge(有点像 SNS,但它不能做什么?)。 Yeah... I would recommend EventBridge.是的...我会推荐 EventBridge。 It can just do more... with the target filtering rules, payload transformations, it can automatically trigger more things...它可以做更多的事情……有了目标过滤规则、有效载荷转换,它可以自动触发更多事情……

  4. Azure... ehm... Event Hub... but I haven't worked with this one yet... I'm not much of an Azurer... because you know... nobody uses azure for this kind of stuff... Azure...呃...事件中心...但我还没有使用过这个...我不是一个 Azurer...因为你知道...没有人使用 azure 来做这种事情东西...

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM