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.os.walk() 一般用法为 import os ph=r'D:\temp\build' for root,dirs,files in os.walk(ph): print(root,dirs, ...

  2. 去空格的四则运算表达式求值-Java

    笔记 package com.daidai.day4.demo1; import java.util.ArrayList; import java.util.Arrays; import java.u ...

  3. Logtash遇到的异常和注意点

    1.Logtash遇到的异常和注意点 1.1 logstash使用kafka插件和es集成 如果logstash使用kafka插件和es集成,必须设置kafka插件参数 session_timeout ...

  4. Kafka 消息存储机制

    Kafka 消息以 Partition 作为存储单元,那么在 Partition 内消息是以什么样的格式存储的呢,如何处理 Partition 中的消息,又有哪些安全策略来保证消息不会丢失呢,这一篇我 ...

  5. Dynamic CRM登陆界面的客制化(持续更新)

    Dynamic CRM的登陆页面比较西化,不是很适合中国人使用.目前先把注销跳转的问题解决了. 服务端使用下面命令,将文件导出来 Export-AdfsWebTheme –Name default – ...

  6. 2020-BUAA-OO-面向对象设计与构造-第四单元总结&课程总结

    咱的OO结束辣! Part1: Unit4 Summary 本单元作业,我主要使用了适配器模式和访问者模式.总体上看,代码量和文件数量有所上升,但配合分包等措施后,文件结构清晰,各部分耦合度均较低.缺 ...

  7. 「HTML+CSS」--自定义加载动画【015】

    前言 Hello!小伙伴! 首先非常感谢您阅读海轰的文章,倘若文中有错误的地方,欢迎您指出- 哈哈 自我介绍一下 昵称:海轰 标签:程序猿一只|C++选手|学生 简介:因C语言结识编程,随后转入计算机 ...

  8. Centos6无法使用yum解决办法

    12月后Centos 6 系统无法使用yum出现错误(文章底部看) 相信已经有一部分朋友今天连接到CentOS 6的服务器后执行yum后发现报错,那么发生了什么? CentOS 6已经随着2020年1 ...

  9. Crackme_003

    功能: 拿到文件,先执行一下.功能如下: 1.nag窗口 会先出现如下nag窗口,持续几秒 2.注册窗口: 出现错误会提示:You Get Wrong  Try Again 破解: 1.查壳: 无壳, ...

  10. shell脚本 3 流程控制

    shell流程控制 流程控制是改变程序运行顺序的指令.linux shell有一套自己的流程控制语句,其中包括条件语句(if),循环语句(for,while),选择语句(case).下面我将通过例子介 ...