当前位置:网站首页>Does stream even have application advanced learning? As a programmer, you know what
Does stream even have application advanced learning? As a programmer, you know what
2022-06-25 14:16:00 【Java enthusiast】
Stream Advanced application
In the microservices architecture , Fine grained services are more prone to frequent distributed integration and interaction .
Service interaction pattern based on message oriented middleware , Or build an event driven architecture model , It can help businesses establish and implement the core domain event driven interaction mechanism .
Field events (Domain Event) The communication of changes the state of domain objects , For example, the order creation event 、 Inventory addition event .
A domain event can express the behavior that is taking place on a domain object . The occurrence of domain events is accompanied by modified data 、 Time stamp 、 polymerization ID And other additional information . In the microservices architecture , Domain events to publish / Subscription mode , Publish events to MQ middleware , Allow multiple different microservices to subscribe to events and consume events , This event may be an order creation event (OrderCreateEvent) Or order modification event (CustomerModifyEvent).
All the above methods follow the object-oriented method , However, these objects shuttle among producers 、 Distributed message queues and consumers , It becomes a shared class library , When many microservices need to rely on shared class libraries , A high degree of coupling . This shared distributed object implements remote invocation by marking the shared object as jar Packages are shared by different microservices , It is also a typical antipattern in distributed systems , When a domain event is modified , Every dependent microservice will be affected .
Use SCS adopt Spring Message Public message event mechanism , It can support event driven architecture , At the same time, avoid relying on sharing Domain object type . And now we have SCS Based on some meta annotations of Spring The implementation of some small features is similar to CORS Of EDA framework .
SpringCloudStream Handling events
SCS Provides @StreamListener Annotations to control how serialization is done , It acts as an input to the method and executes the method , for example :

The new event distribution feature is in @StreamListener I added Condition Property to make it possible to route messages to multiple listeners ,Condition The value of is in SPEL An expression boolean value .Condition Apply to incoming messages , Ability to calculate any message payload 、 A specific message header or a combination thereof . This provides an extremely flexible routing mechanism , There is no need to define classes for different event types . for example , We define a band String eventType Attribute Event type ,SCS Will provide out of the box functionality :

among ,Event The type is defined as follows :

Customized event annotations
though however can With send use through use Of Event class type , but yes still however Need to be want through too @StreamListener Annotations to join SEL Condition Annotation to filter , It's troublesome to use . Now we're based on @StreamListener Annotations implement custom event annotations , We directly locate our method by event type . Custom annotation @EventHandler Is defined as follows :


adopt @EventHandler The definition of , We can simplify the event listening annotation to the following form :

here , We can do this by Condition The expression is transformed into a template implementation , heavy load SCS It's about The reason is @StreamListener notes Explain Of BeanPostProcessor , this sample through too eventType You can implement the method of identifying events . Overloaded functions are as follows :

Next , We can use custom @EnableEventHandling Annotation to introduce this configuration:

I People repair Change EventHandler notes Explain , set The righteous One individual eventType Belong to sex Come on do Condition Another name for :

then , We can use custom event handling annotations , Just provide the event type , You can send subscription events from consumers :

Microservice integration architectures tend to use standardized services HTTP、 be based on REST API Integration with the architecture interaction pattern . Besides , Considering the performance, you can also use RPC How to invoke . For asynchronous interactive processes , Using message queue can realize full decoupling and heterogeneous integration between microservices .
Spring Cloud Provides Spring Cloud Stream frame , It can mask the details of the underlying communication technology , And a message based lightweight microservice integration solution is implemented .
You can also use Spring Cloud Stream The implementation is based on event driven and CQRS System architecture .
The content of this article is MOM asynchronous communication ,Stream Advanced application
边栏推荐
- 论文阅读:Graph Contrastive Learning with Augmentations
- Discriminative v.s.Generative
- Windows下MySQL的安装和删除
- 阻止深度神经网络过拟合(Mysteries of Neural Networks Part II)
- About reconnection of STM32 using lan8720a plug-in network cable
- Getting started with numpy Library
- go---- mgo
- Stream竟然还有应用进阶学习?作为程序员的你知道吗
- 通达信股票账户开户安全吗
- 电脑必须打开的设置
猜你喜欢

Shell string variable

Kubernetes cluster construction of multiple ECS

JVM 用工具分析OOM经典案例

Reading the "clean" series for the first time, I didn't think it was a good book

Renix perf: detailed explanation of IP network performance test tools and test case parameters

测一测你的挣钱能力有多强?未来的你将从事什么职业?

楼宇自动化专用BACnet网关BL103

'NVIDIA SMI' is not an internal or external command, nor is it a runnable program or batch file

What if the CPU temperature of Dell computer is too high

NVM installation and use tutorial
随机推荐
Shell array
Pourquoi les programmeurs devraient - ils être plus doux?
Renix Perf: IP网络性能测试工具及测试用例参数详解
哈希表、哈希冲突
shell 字符串变量
untiy强制刷新UI
shell 运算符
Typescript and go --- essence
Qt内存映射
'NVIDIA SMI' is not an internal or external command, nor is it a runnable program or batch file
使用KVM虚拟化部署EVE-NG
还没弄明白微服务数据架构事务管理+ACID+一致性+CAP+BASE理论吗,看完彻底解决疑惑
JS functions
NR-ARFCN和信道栅格、同步栅格和GSCN
Tencent cloud builds a Socks5 multi IP proxy server to realize the perfect building of a game with a single window and a single IP. Tutorial attached tool "suggestions collection"
VGA display of de2-115 FPGA development board
Syntax 'trap'
Kubernetes cluster construction of multiple ECS
完整详细的汇编实验报告
shell 数组