当前位置:网站首页>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
边栏推荐
- 哈希表、哈希冲突
- 多臺雲服務器的 Kubernetes 集群搭建
- untiy强制刷新UI
- 完整详细的汇编实验报告
- 打新债是不是不安全
- Golang project dependency management tool go vendor, go Mod
- [world history] Episode 1: people in the Stone Age
- Rust,程序員創業的最佳選擇?
- Is it safe for Guosen Securities to open a stock account? Excuse me?
- VGA display of de2-115 FPGA development board
猜你喜欢
【Proteus仿真】51单片机+DS1302+lcd1602显示
Rust, the best choice for programmers to start a business?
Data acquisition system gateway acquisition plant efficiency
Experts' suggestions | 8 measures to accelerate your innovative career planning and growth
当了六年程序员第一次搞懂微服务架构的数据一致性,真不容易
用NumPy实现神经网络(Mysteries of Neural Networks Part III)
深入理解深度神经网络背后的数学(Mysteries of Neural Networks Part I)
对白:推荐系统快速入门路线及各知识点总结
Application of tactile intelligent sharing-rk3568 in financial self-service terminal
一次性讲清楚 Handler 可能导致的内存泄漏和解决办法 | 开发者说·DTalk
随机推荐
网络远程访问的方式使用树莓派
算力&NFT交易平台F3.xyz旗下独家权益NFT项目Hash Eagle将盛大发行
哈希錶、哈希沖突
shell 变量 入门
英語中的九大詞性與九大時態
通达信股票账户开户安全吗
[world history] Episode 1: people in the Stone Age
让PyTorch训练速度更快,你需要掌握这17种方法
JVM uses tools to analyze classic cases of OOM
关于STM32使用LAN8720A插拔网线重连
Untiy force refresh UI
Golang project dependency management tool go vendor, go Mod
shell 运算符
使用调试工具调试博图TCP连接所遇到的问题
Where can the brightness of win7 display screen be adjusted
Nr-arfcn and channel grid, synchronous grid and GSCN
论文阅读:Graph Contrastive Learning with Augmentations
哈希表、哈希冲突
专家建议|8大措施加速你的创新职业规划和成长
Is it safe for Guosen Securities to open an account?