Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
E
Event Bus
Manage
Activity
Members
Labels
Plan
Issues
0
Issue boards
Milestones
Iterations
Wiki
Requirements
Code
Merge requests
0
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Libero
Event Bus
Commits
b4309528
Commit
b4309528
authored
5 years ago
by
Peter Hooper
Browse files
Options
Downloads
Patches
Plain Diff
Move EventBus into its own file
parent
fe560100
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/event-bus/index.ts
+2
-43
2 additions, 43 deletions
src/event-bus/index.ts
with
2 additions
and
43 deletions
src/event-bus/index.ts
+
2
−
43
View file @
b4309528
// Abstract Message Queue - types and interfaces
/**
* TODO: Once agreed, add these to DefinitelyTyped so they can be shared.
*/
export
type
EventType
=
string
;
export
interface
Event
<
T
extends
object
>
{
readonly
eventType
:
EventType
;
readonly
id
:
string
;
// Generated when the event is emitted
readonly
created
:
Date
;
readonly
payload
:
T
;
// The actual data the event is carrying.
// version: has been removed - so we can remain weakly typed
// context: has also been removed - if you need information about the origin
// source of the event then put it in the payload.
}
export
interface
EventPublisher
{
// Promise<boolean> should this become void | exception? we only need to know if something went wrong
publish
<
T
extends
object
>
(
event
:
Event
<
T
>
):
Promise
<
boolean
>
;
}
export
interface
EventSubscriber
{
// handler: returns whether or not we should ack the message
subscribe
<
T
extends
object
>
(
eventType
:
string
,
handler
:
(
event
:
Event
<
T
>
)
=>
Promise
<
boolean
>
):
void
;
}
export
abstract
class
EventBus
{
// register the following:
// - eventsToHandle - a list of events you will publish/subscribe to
// - serviceName - used when subscribing to generate a unique queue for holding
// incoming messages of the form: `consumer__${eventType}__${serviceName}`
constructor
(
readonly
eventsToHandle
:
EventType
[],
readonly
serviceName
:
string
)
{}
destroy
():
Promise
<
void
>
{
return
Promise
.
resolve
();
}
}
// This isn't generic enough
export
interface
EventConfig
{
url
:
string
;
}
export
*
from
'
./event-bus
'
;
export
*
from
'
./types
'
;
This diff is collapsed.
Click to expand it.
Preview
0%
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment