{"id":15102601,"url":"https://github.com/ahoo-wang/govern-eventbus","last_synced_at":"2025-09-27T00:31:24.879Z","repository":{"id":40357695,"uuid":"253807025","full_name":"Ahoo-Wang/govern-eventbus","owner":"Ahoo-Wang","description":"Govern Service RPC \u0026 Event-Driven Architecture Framework || Govern EventBus is no longer maintained, please use Wow instead.","archived":true,"fork":false,"pushed_at":"2023-06-02T01:16:21.000Z","size":441,"stargazers_count":31,"open_issues_count":11,"forks_count":9,"subscribers_count":3,"default_branch":"master","last_synced_at":"2024-09-25T19:02:29.557Z","etag":null,"topics":["compensation","consistency","distributed","eda","event-driven","event-driven-architecture","eventbus","java","kafka","microservice","microservices","mq","publisher","rabbitmq","spring","spring-boot","subscriber"],"latest_commit_sha":null,"homepage":"","language":"Java","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/Ahoo-Wang.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2020-04-07T13:49:34.000Z","updated_at":"2024-06-10T03:52:18.000Z","dependencies_parsed_at":"2023-01-22T15:30:23.182Z","dependency_job_id":null,"html_url":"https://github.com/Ahoo-Wang/govern-eventbus","commit_stats":null,"previous_names":["ahoo-wang/smarteventbus"],"tags_count":6,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ahoo-Wang%2Fgovern-eventbus","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ahoo-Wang%2Fgovern-eventbus/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ahoo-Wang%2Fgovern-eventbus/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/Ahoo-Wang%2Fgovern-eventbus/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/Ahoo-Wang","download_url":"https://codeload.github.com/Ahoo-Wang/govern-eventbus/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":219871828,"owners_count":16554457,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["compensation","consistency","distributed","eda","event-driven","event-driven-architecture","eventbus","java","kafka","microservice","microservices","mq","publisher","rabbitmq","spring","spring-boot","subscriber"],"created_at":"2024-09-25T19:02:51.184Z","updated_at":"2025-09-27T00:31:24.386Z","avatar_url":"https://github.com/Ahoo-Wang.png","language":"Java","funding_links":[],"categories":[],"sub_categories":[],"readme":"# *Govern EventBus* is no longer maintained, please use [*Wow*](https://github.com/Ahoo-Wang/Wow) instead.\n\n\u003e [中文文档](./README.zh-CN.md)\n\n*Govern EventBus* is an *event-driven architecture* framework that has been validated in a four-year production\nenvironment, which governs remote procedure calls between microservices through event bus mechanism. Strong consistency\nwithin microservices is supported by local transactions, and final consistency between microservices is achieved by\nevent bus. In addition, automatic compensation of event publish / subscribe is provided.\n\n## Execution Flow\n\n\u003cp align=\"center\"\u003e\u003cimg src=\"./docs/Govern-EventBus.png\" alt=\"Govern EventBus\"/\u003e\u003c/p\u003e\n\n## Installation\n\n### init db\n\n``` sql\n\ncreate table simba_mutex\n(\n    mutex         varchar(66)     not null primary key comment 'mutex name',\n    acquired_at   bigint unsigned not null,\n    ttl_at        bigint unsigned not null,\n    transition_at bigint unsigned not null,\n    owner_id      char(32)        not null,\n    version       int unsigned    not null\n);\n\ncreate table if not exists cosid_machine\n(\n    name            varchar(100) not null comment '{namespace}.{machine_id}',\n    namespace       varchar(100) not null,\n    machine_id      integer      not null default 0,\n    last_timestamp  bigint       not null default 0,\n    instance_id     varchar(100) not null default '',\n    distribute_time bigint       not null default 0,\n    revert_time     bigint       not null default 0,\n    constraint cosid_machine_pk\n        primary key (name)\n) engine = InnoDB;\n\ncreate index if not exists idx_namespace on cosid_machine (namespace);\ncreate index if not exists idx_instance_id on cosid_machine (instance_id);\n\ncreate table publish_event\n(\n    id             bigint unsigned auto_increment\n        primary key,\n    event_name     varchar(100)              not null,\n    event_data_id  bigint unsigned default 0 not null,\n    event_data     mediumtext                not null,\n    status         smallint unsigned         not null,\n    published_time bigint unsigned default 0 not null,\n    version        smallint unsigned         not null,\n    create_time    bigint unsigned           not null\n);\n\ncreate\n    index idx_status\n    on publish_event (status);\n\ncreate table publish_event_compensate\n(\n    id               bigint unsigned auto_increment\n        primary key,\n    publish_event_id bigint unsigned not null,\n    start_time       bigint unsigned not null,\n    taken            bigint unsigned not null,\n    failed_msg       text            null\n);\n\ncreate table publish_event_failed\n(\n    id               bigint unsigned auto_increment\n        primary key,\n    publish_event_id bigint unsigned not null,\n    failed_msg       text            not null,\n    create_time      bigint unsigned not null\n);\n\ncreate table subscribe_event\n(\n    id                bigint unsigned auto_increment\n        primary key,\n    subscribe_name    varchar(100)              not null,\n    status            smallint unsigned         not null,\n    subscribe_time    bigint unsigned           not null,\n    event_id          bigint unsigned           not null,\n    event_name        varchar(100)              not null,\n    event_data_id     bigint unsigned default 0 not null,\n    event_data        mediumtext                not null,\n    event_create_time bigint unsigned           not null,\n    version           smallint unsigned         not null,\n    create_time       bigint unsigned           not null,\n    constraint uk_subscribe_name_even_id_event_name\n        unique (subscribe_name, event_id, event_name)\n);\n\ncreate\n    index idx_status\n    on subscribe_event (status);\n\ncreate table subscribe_event_compensate\n(\n    id                 bigint unsigned auto_increment\n        primary key,\n    subscribe_event_id bigint unsigned not null,\n    start_time         bigint unsigned not null,\n    taken              int unsigned    not null,\n    failed_msg         text            null\n);\n\ncreate table subscribe_event_failed\n(\n    id                 bigint unsigned auto_increment\n        primary key,\n    subscribe_event_id bigint unsigned not null,\n    failed_msg         text            not null,\n    create_time        bigint unsigned not null\n);\n\ninsert into simba_mutex\n    (mutex, acquired_at, ttl_at, transition_at, owner_id, version)\nvalues ('eventbus_publish_leader', 0, 0, 0, '', 0);\n\ninsert into simba_mutex\n    (mutex, acquired_at, ttl_at, transition_at, owner_id, version)\nvalues ('eventbus_subscribe_leader', 0, 0, 0, '', 0);\n\n```\n\n### Gradle\n\n\u003e Kotlin DSL\n\n```kotlin\n    val eventbusVersion = \"1.0.5\";\n    implementation(\"me.ahoo.eventbus:eventbus-spring-boot-starter:${eventbusVersion}\")\n    implementation(\"me.ahoo.eventbus:eventbus-spring-boot-autoconfigure:${eventbusVersion}\") {\n        capabilities {\n            requireCapability(\"me.ahoo.eventbus:rabbit-bus-support\")\n            //requireCapability(\"me.ahoo.eventbus:kafka-bus-support\")\n        }\n    }\n```\n\n### Maven\n\n```xml\n\u003c?xml version=\"1.0\" encoding=\"UTF-8\"?\u003e\n\n\u003cproject xmlns=\"http://maven.apache.org/POM/4.0.0\"\n         xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\"\n         xsi:schemaLocation=\"http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd\"\u003e\n\n    \u003cmodelVersion\u003e4.0.0\u003c/modelVersion\u003e\n    \u003cartifactId\u003edemo\u003c/artifactId\u003e\n    \u003cproperties\u003e\n        \u003ceventbus.version\u003e1.0.5\u003c/eventbus.version\u003e\n    \u003c/properties\u003e\n\n    \u003cdependencies\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003eme.ahoo.eventbus\u003c/groupId\u003e\n            \u003cartifactId\u003eeventbus-spring-boot-starter\u003c/artifactId\u003e\n            \u003cversion\u003e${eventbus.version}\u003c/version\u003e\n        \u003c/dependency\u003e\n        \u003cdependency\u003e\n            \u003cgroupId\u003eme.ahoo.eventbus\u003c/groupId\u003e\n            \u003cartifactId\u003eeventbus-rabbit\u003c/artifactId\u003e\n            \u003cversion\u003e${eventbus.version}\u003c/version\u003e\n        \u003c/dependency\u003e\n        \u003c!--\u003cdependency\u003e--\u003e\n        \u003c!--    \u003cgroupId\u003eme.ahoo.eventbus\u003c/groupId\u003e--\u003e\n        \u003c!--    \u003cartifactId\u003eeventbus-kafka\u003c/artifactId\u003e--\u003e\n        \u003c!--    \u003cversion\u003e${eventbus.version}\u003c/version\u003e--\u003e\n        \u003c!--\u003c/dependency\u003e--\u003e\n    \u003c/dependencies\u003e\n\u003c/project\u003e\n```\n\n### Spring Boot Application Config\n\n```yaml\nspring:\n  application:\n    name: eventbus-demo\n  rabbitmq:\n    host: localhost\n    username: eventbus\n    password: eventbus\n\n  shardingsphere:\n    datasource:\n      names: ds0\n      ds0:\n        type: com.zaxxer.hikari.HikariDataSource\n        jdbcUrl: jdbc:mariadb://localhost:3306/eventbus_db?serverTimezone=GMT%2B8\u0026characterEncoding=utf-8\n        username: root\n        password: root\n    props:\n      sql-show: true\n    rules:\n      sharding:\n        tables:\n          publish_event:\n            actual-data-nodes: ds0.publish_event_$-\u003e{202110..202112},ds0.publish_event_$-\u003e{202201..202212}\n            table-strategy:\n              standard:\n                sharding-column: create_time\n                sharding-algorithm-name: publish-event-interval\n          subscribe_event:\n            actual-data-nodes: ds0.subscribe_event_$-\u003e{202110..202112},ds0.subscribe_event_$-\u003e{202201..202212}\n            table-strategy:\n              standard:\n                sharding-column: event_create_time\n                sharding-algorithm-name: subscribe-event-interval\n        sharding-algorithms:\n          publish-event-interval:\n            type: COSID_INTERVAL\n            props:\n              logic-name-prefix: publish_event_\n              datetime-lower: 2021-10-01 00:00:00\n              datetime-upper: 2022-12-31 23:59:59\n              sharding-suffix-pattern: yyyyMM\n              datetime-interval-unit: MONTHS\n              datetime-interval-amount: 1\n          subscribe-event-interval:\n            type: COSID_INTERVAL\n            props:\n              logic-name-prefix: subscribe_event_\n              datetime-lower: 2021-10-01 00:00:00\n              datetime-upper: 2022-12-31 23:59:59\n              sharding-suffix-pattern: yyyyMM\n              datetime-interval-unit: MONTHS\n              datetime-interval-amount: 1\ngovern:\n  eventbus:\n    rabbit:\n      exchange: eventbus\n    compensate:\n      publish:\n        schedule:\n          initial-delay: 30s\n          period: 10s\n        range: 60D\n      subscribe:\n        schedule:\n          initial-delay: 30s\n          period: 10s\n      enabled: true\n    subscriber:\n      prefix: ${spring.application.name}.\n\ncosid:\n  namespace: ${spring.application.name}\n  segment:\n    enabled: true\n    mode: chain\n    chain:\n      safe-distance: 1\n    distributor:\n      jdbc:\n        enable-auto-init-id-segment: true\n    provider:\n      eventbus:\n        step: 100\n```\n\n## Get Started\n\n\u003e Generally, the *publisher* and the *subscriber* are not in the same application service.\n\u003e This is just for demonstration purposes.。\n\n\u003e [Demo](./eventbus-demo)\n\n### Publisher\n\n```java\n/**\n * Define publishing events\n */\npublic class OrderCreatedEvent {\n    private long orderId;\n\n    public long getOrderId() {\n        return orderId;\n    }\n\n    public void setOrderId(long orderId) {\n        this.orderId = orderId;\n    }\n\n    @Override\n    public String toString() {\n        return \"OrderCreatedEvent{\" +\n                \"orderId=\" + orderId +\n                \"}\";\n    }\n}\n```\n\n```java\npackage me.ahoo.eventbus.demo.service;\n\nimport me.ahoo.eventbus.core.annotation.Publish;\nimport me.ahoo.eventbus.demo.event.OrderCreatedEvent;\nimport org.springframework.stereotype.Service;\n\n/**\n * @author ahoo wang\n */\n@Service\npublic class OrderService {\n\n    @Publish\n    public OrderCreatedEvent createOrder() {\n        OrderCreatedEvent orderCreatedEvent = new OrderCreatedEvent();\n        orderCreatedEvent.setOrderId(1L);\n        return orderCreatedEvent;\n    }\n}\n\n```\n\n### Subscriber\n\n```java\npackage me.ahoo.eventbus.demo.service;\n\nimport lombok.extern.slf4j.Slf4j;\nimport me.ahoo.eventbus.core.annotation.Subscribe;\nimport me.ahoo.eventbus.demo.event.OrderCreatedEvent;\nimport org.springframework.stereotype.Service;\n\n@Slf4j\n@Service\npublic class NoticeService {\n\n    @Subscribe\n    public void handleOrderCreated(OrderCreatedEvent orderCreatedEvent) {\n        log.info(\"handleOrderCreated - event:[{}].\", orderCreatedEvent);\n        /**\n         * Execute business code\n         * send sms / email ?\n         */\n    }\n}\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahoo-wang%2Fgovern-eventbus","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fahoo-wang%2Fgovern-eventbus","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fahoo-wang%2Fgovern-eventbus/lists"}