将消费/农产品事件表示为从微服务到消息队列的UML组件[kafka]序列/类图

您所在的位置:网站首页 kafka消费者命令行 将消费/农产品事件表示为从微服务到消息队列的UML组件[kafka]序列/类图

将消费/农产品事件表示为从微服务到消息队列的UML组件[kafka]序列/类图

2023-04-03 11:38| 来源: 网络整理| 查看: 265

百度翻译此文   有道翻译此文 问题描述

I have a usecase of producing some event, consuming event produced by other microservice & also produced by own.

How to represent the Kafka system, microservice in play & producing/consuming event in the sequence diagram/class diagram.

In the UML we have a special digram from DB, do we have any thing for Kafka & cron job?

推荐答案

The core of a microservice architecture using Kafka is asynchronous communication of event messages. The UML equivalent are UML signals. In a sequence diagram, you could show the exchange of messages/signals between participating lifelines. The name of the message would be the name of the signal (probably the Kafka topic) optinally followed by the attributes of the signal between parenthesis.

You would probably want to show the big picture, showing producers and consumers (classes or even microservice components) dialoguing, as if it would be directly between them, without showing the plumbing (Kafka, or other event-queues). But if you prefer to show the full picture, you could insert a lifeline for Kafka and let consumers and producers exchange messages with Kafka. But that would make the diagram much more complex, exspecially if you have more than one producer and one consumer.

In a class diagram, you'd probably focus on your own classes and the description of the signals:

Signals are like classes and allow to describe the content of Kafka event/messages (attributes of the signal). You can show consumer classes by showing that they have receptions (i.e. they can receive some signals). There's nothing foreseen for production os signals, but you could show with a dependency arrow for the relevant operations of your class what signals they could send.

It's not fully clear what other diagrams you are looking for:

In a component diagram, Kafka would be a component, with a Subscriber, and a Publisher interface provided. Maybe a couple more interfaces depending on your needs. Your microservices would be other components.

In a deployment diagram, you'd show the real distribution of all your Kafka nodes, with some annotations about what each is doing (e.g. Topics and Kafka partitions).

Activity diagrams can show complex workflows (including sending and accepting events). You could also use them to document a flow of events across several microservices (each represented with a partition in the UML diagram) if deemed useful.

P.S: There is no DB diagram in UML: you'd use a class diagram and show only the classes relevant for the DB. For cron jobs you need to be more specific: it is possible to show timing events/constraints in several behavioral diagrams (see this question for example). But you'd not show cron itself.

其他推荐答案

I would make a more radical proposal, yes Activity Diagrams are useful to present parallel workflows but in my opinion the ultimate tool to represent parallelity / multi-threaded flows are State Machines and State Machine Diagrams.

In this diagram in my blog, you can see how I have represent a parallel Workflow. In which Credit State Machine, Credit Score State Machine, Fraud Prevention State Machine and Adress Check State Machine working in parallel to fulfil a Business Case with the help of Apache Kafka.



【本文地址】


今日新闻


推荐新闻


CopyRight 2018-2019 办公设备维修网 版权所有 豫ICP备15022753号-3