Skip to content

Latest commit

 

History

History
34 lines (24 loc) · 761 Bytes

README.md

File metadata and controls

34 lines (24 loc) · 761 Bytes

Introduction

Simple implementation of an event bus using kotlin coroutines shared flow

How to Use

Create the event:

class OrderWasCreated (override val occurredOn: OffsetDateTime = OffsetDateTime.now()) : DomainEvent

Create the subscriber:

class OrderWasCreatedSubscriber : DomainEventSubscriber<OrderWasCreated> {
    override fun consume(event: OrderWasCreated) {
        println("Order created")
    }
}

Register the subscriber in the event bus:

val eventBus = SharedFlowEventBus()
                        .subscribe(OrderWasCreatedSubscriber())

Publish the event:

eventBus.publish(OrderWasCreated())