Govern EventBus

Govern EventBus 是一个历经四年生产环境验证的事件驱动架构框架, 通过事件总线机制来治理微服务间的远程过程调用。

使用本地事务来支持微服务内强一致性,事件总线来实现微服务间的最终一致性,另外还提供了事件发布/订阅失败的自动补偿机制。

执行流

安装

初始化 db

create table compensate_leader
(
name varchar(16) not null
primary key,
term_start bigint unsigned not null,
term_end bigint unsigned not null,
transition_period bigint unsigned not null,
leader_id varchar(100) not null,
version int unsigned not null
); create table publish_event
(
id bigint unsigned auto_increment
primary key,
event_name varchar(100) not null,
event_data mediumtext not null,
status smallint unsigned not null,
published_time bigint unsigned default 0 not null,
version smallint unsigned not null,
create_time bigint unsigned not null
); create index idx_status
on publish_event (status); create table publish_event_compensate
(
id bigint unsigned auto_increment
primary key,
publish_event_id bigint unsigned not null,
start_time bigint unsigned not null,
taken bigint unsigned not null,
failed_msg text null
); create table publish_event_failed
(
id bigint unsigned auto_increment
primary key,
publish_event_id bigint unsigned not null,
failed_msg text not null,
create_time bigint unsigned not null
); create table subscribe_event
(
id bigint unsigned auto_increment
primary key,
subscribe_name varchar(100) not null,
status smallint unsigned not null,
subscribe_time bigint unsigned not null,
event_id bigint unsigned not null,
event_name varchar(100) not null,
event_data mediumtext not null,
event_create_time bigint unsigned not null,
version smallint unsigned not null,
create_time bigint unsigned not null,
constraint uk_subscribe_name_even_id_event_name
unique (subscribe_name, event_id, event_name)
); create index idx_status
on subscribe_event (status); create table subscribe_event_compensate
(
id bigint unsigned auto_increment
primary key,
subscribe_event_id bigint unsigned not null,
start_time bigint unsigned not null,
taken int unsigned not null,
failed_msg text null
); create table subscribe_event_failed
(
id bigint unsigned auto_increment
primary key,
subscribe_event_id bigint unsigned not null,
failed_msg text not null,
create_time bigint unsigned not null
); insert into compensate_leader
(name, term_start, term_end, transition_period, leader_id, version)
values ('publish_leader', 0, 0, 0, '', 0); insert into compensate_leader
(name, term_start, term_end, transition_period, leader_id, version)
values ('subscribe_leader', 0, 0, 0, '', 0);

Gradle

    val eventbusVersion = "0.9.2";
implementation("me.ahoo.eventbus:eventbus-spring-boot-starter:${eventbusVersion}")
implementation("me.ahoo.eventbus:eventbus-spring-boot-autoconfigure:${eventbusVersion}") {
capabilities {
requireCapability("me.ahoo.eventbus:rabbit-bus-support")
//requireCapability("me.ahoo.eventbus:kafka-bus-support")
}
}

Maven

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion>
<artifactId>demo</artifactId>
<properties>
<eventbus.version>0.9.2</eventbus.version>
</properties> <dependencies>
<dependency>
<groupId>me.ahoo.eventbus</groupId>
<artifactId>eventbus-spring-boot-starter</artifactId>
<version>${eventbus.version}</version>
</dependency>
<dependency>
<groupId>me.ahoo.eventbus</groupId>
<artifactId>eventbus-rabbit</artifactId>
<version>${eventbus.version}</version>
</dependency>
<!--<dependency>-->
<!-- <groupId>me.ahoo.eventbus</groupId>-->
<!-- <artifactId>eventbus-kafka</artifactId>-->
<!-- <version>${eventbus.version}</version>-->
<!--</dependency>-->
</dependencies>
</project>

Spring Boot Application Config

spring:
application:
name: eventbus-demo
datasource:
url: jdbc:mysql://localhost:3306/eventbus_db?serverTimezone=GMT%2B8&characterEncoding=utf-8
username: root
password: root
rabbitmq:
host: localhost
username: eventbus
password: eventbus govern:
eventbus:
rabbit:
exchange: eventbus
compensate:
db:
publish:
schedule:
initial-delay: 30
period: 10
subscribe:
schedule:
initial-delay: 30
period: 10
enabled: true
subscriber:
prefix: ${spring.application.name}.

快速上手

一般情况下 PublisherSubscriber 不在同一个应用服务内。

这里只是作为演示用途。

Demo

Publisher

/**
* 定义发布事件
*/
public class OrderCreatedEvent {
private long orderId; public long getOrderId() {
return orderId;
} public void setOrderId(long orderId) {
this.orderId = orderId;
} @Override
public String toString() {
return "OrderCreatedEvent{" +
"orderId=" + orderId +
'}';
}
}
package me.ahoo.eventbus.demo.service;

import me.ahoo.eventbus.core.annotation.Publish;
import me.ahoo.eventbus.demo.event.OrderCreatedEvent;
import org.springframework.stereotype.Service; /**
* @author ahoo wang
*/
@Service
public class OrderService { @Publish
public OrderCreatedEvent createOrder() {
OrderCreatedEvent orderCreatedEvent = new OrderCreatedEvent();
orderCreatedEvent.setOrderId(1L);
return orderCreatedEvent;
}
}

Subscriber

package me.ahoo.eventbus.demo.service;

import lombok.extern.slf4j.Slf4j;
import me.ahoo.eventbus.core.annotation.Subscribe;
import me.ahoo.eventbus.demo.event.OrderCreatedEvent;
import org.springframework.stereotype.Service; @Slf4j
@Service
public class NoticeService { @Subscribe
public void handleOrderCreated(OrderCreatedEvent orderCreatedEvent) {
log.info("handleOrderCreated - event:[{}].", orderCreatedEvent);
/**
* 执行相应的业务代码
* send sms / email ?
*/
}
}

Govern EventBus - 历经多年生产环境验证的事件驱动架构框架的更多相关文章

  1. 马老师 生产环境mysql主从复制、架构优化方案

    Binlog日志(主服务器) => 中继日志(从服务器 运行一遍,保持一致).从服务器是否要二进制日志取决于架构设计.如果二进制保存足够稳定,从性能上来说,从服务器不需要二进制日志.默认情况下, ...

  2. Centos7 HyperLedger Fabric 1.4 生产环境部署

    Kafka生产环境部署案例采用三个排序(orderer)服务.四个kafka.三个zookeeper和四个节点(peer)组成,共准备八台服务器,每台服务器对应的服务如下所示: kafka案例网络拓扑 ...

  3. 15分钟从零开始搭建支持10w+用户的生产环境(四)

    上一篇文章,介绍了这个架构中,WebServer的选择,以及整个架构中扩展时的思路. 原文地址:15分钟从零开始搭建支持10w+用户的生产环境(三)   五.架构实践 前边用了三篇文章,详细介绍了这个 ...

  4. 使用 Kafka 在生产环境构建大规模机器学习

    智能实时应用为所有行业带来了革命性变化.机器学习及其分支深度学习正蓬勃发展,因为机器学习让计算机能够在无人指引的情况下挖掘深藏的洞见.这种能力正是多种领域所需要的,如非结构化数据分析.图像识别.语音识 ...

  5. (转) 将ASP.NET Core应用程序部署至生产环境中(CentOS7)

    原文链接: http://www.cnblogs.com/ants/p/5732337.html 阅读目录 环境说明 准备你的ASP.NET Core应用程序 安装CentOS7 安装.NET Cor ...

  6. .Net Core Linux centos7行—发布程序到生产环境

    实验demo现在需要发布到生产环境,发现在发布的时候要考虑到不一致的几个地方. 1.各类配置文件线下,线上不一致. 2.绑定的url不一致,可能是域名不一致,也可能是schema不一致(http,ht ...

  7. 将ASP.NET Core应用程序部署至生产环境中(CentOS7)

    这段时间在使用Rabbit RPC重构公司的一套系统(微信相关),而最近相关检验(逻辑测试.压力测试)已经完成,接近部署至线上生产环境从而捣鼓了ASP.NET Core应用程序在CentOS上的部署方 ...

  8. 生产环境使用 pt-table-checksum 检查MySQL数据一致性

    公司数据中心从托管机房迁移到阿里云,需要对mysql迁移(Replication)后的数据一致性进行校验,但又不能对生产环境使用造成影响,pt-table-checksum 成为了绝佳也是唯一的检查工 ...

  9. Greenplum 数据库安装部署(生产环境)

    Greenplum 数据库安装部署(生产环境) 硬件配置: 16 台 IBM X3650, 节点配置:CPU 2 * 8core,内存 128GB,硬盘 16 * 900GB,万兆网卡. 万兆交换机. ...

随机推荐

  1. python爬虫加定时任务,制作微信提醒备忘录

    一.任务的记录与提取 1.1 制作每日任务 为了便于爬取,推荐使用网页版的在线记事本,现在这种工具很多,我选择"石墨文档"进行操作演示.记录内容的 格式可以根据自己的需求和爬虫自行 ...

  2. windows创建签名文件pfx

    https://stackoverflow.com/questions/84847/how-do-i-create-a-self-signed-certificate-for-code-signing ...

  3. Java-TreeMap和Guava-HashMultiset

    一.Java-TreeMap 1.数据结构 底层数据结构是裸的红黑树,保证元素有序,没有比较器Comparator的情况按照key的自然排序,可自定义比较器.线程不安全. 可以存null,但是key不 ...

  4. 走进springboot

    SpringBoot基础 核心思想---自动装配---约定大于配置 开发环境:jdk1.8.maven.springboot.idea 一.快速构建一个springboot项目 1.1.进入sprin ...

  5. CyclicBarrier:人齐了,老司机就可以发车了!

    上一篇咱讲了 CountDownLatch 可以解决多个线程同步的问题,相比于 join 来说它的应用范围更广,不仅可以应用在线程上,还可以应用在线程池上.然而 CountDownLatch 却是一次 ...

  6. [SIGIR2020] Sequential Recommendation with Self-Attentive Multi-Adversarial Network

    这篇论文主要提出了一个网络,成为Multi-Factor Generative Adversarial Network,直接翻译过来的话就是多因子生成对抗网络.主要是期望能够探究影响推荐的其他因子(因 ...

  7. 北航OO第四单元作业总结(4.1~4.3)及课程总结

    前言 在学习过JML规格描述语言之后,本单元进行了UML(Unified Modeling Language)的学习.和JML单纯用语言描述的形式不同,UML通过可视化的图形形式,对一系列有关类的元素 ...

  8. 搜狗高级架构师帮你系统掌握TypeScript开发

    JavaScript 是一门动态弱类型语言,对变量的类型非常宽容,而且不会在这些变量和它们的调用者之间建立结构化的契约. Angular 已经使用 TypeScript 重构了代码,另一大前端框架 V ...

  9. 几十行代码实现ASP.NET Core自动依赖注入

    在开发.NET Core web服务的时候,我们习惯使用自带的依赖注入容器来进行注入. 于是就会经常进行一个很频繁的的重复动作:定义一个接口->写实现类->注入 有时候会忘了写Add这一步 ...

  10. teprunner测试平台测试计划批量运行用例

    本文开发内容 上一篇文章已经把pytest引入到测试平台中,通过多线程和多进程的方式,运行测试用例.有了这个基础,做批量运行用例的功能就很简单了,只需要前端传入一个CaseList即可.本文的后端代码 ...