https://github.com/june-it/mystack.localmessage
开源的轻量级本地消息总线类库
https://github.com/june-it/mystack.localmessage
local-event message-bus mystack request-response
Last synced: about 2 months ago
JSON representation
开源的轻量级本地消息总线类库
- Host: GitHub
- URL: https://github.com/june-it/mystack.localmessage
- Owner: june-it
- License: mit
- Created: 2024-08-22T07:05:40.000Z (9 months ago)
- Default Branch: master
- Last Pushed: 2024-12-18T03:47:13.000Z (5 months ago)
- Last Synced: 2025-02-01T16:09:59.755Z (4 months ago)
- Topics: local-event, message-bus, mystack, request-response
- Language: C#
- Homepage:
- Size: 28.3 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# MyStack.LocalMessage
Open-source lightweight local message bus library
| nuget | stats |
| ----------- | ----------- |
| [](https://www.nuget.org/packages/MyStack.LocalMessage) | [](https://www.nuget.org/stats/packages/MyStack.LocalMessage?groupby=Version) |# Getting Started
## Add Service Support
```
services.AddLocalMessage(Assembly.GetExecutingAssembly());
```## 1、Event Subscription and Publication
### Define Events
```
public class HelloEvent: ILocalEvent
{
}```
### Subscribe to Events
```
public class HelloEventHandler : ILocalEventHandler
{
public async Task HandleAsync(HelloEvent eventData, CancellationToken cancellationToken = default)
{
await Task.CompletedTask;
}
}
```
### Publish Events
```
await eventBus.PublishAsync(new HelloEvent());
```
## 2、Request/Response Subscription and Publication
### Define Requests
```
public class Ping : IRequest
{
}
```
### Define Responses
```
public class Pong
{
}
```### Subscribe to Requests and Return Response Results
```
public class PingHandler : IRequestHandler
{
public Task HandleAsync(Ping eventData, CancellationToken cancellationToken = default)
{
return Task.FromResult(new Pong());
}
}
```
### Publish Requests
```
var pongMessage = eventBus.SendAsync(ping);
```## 3、Wrapped Event Data Subscription and Publication
### Define Wrapped Event Data
```
public class WrappedEventData
{
}```
### Subscribe to Wrapped Event Data
```
public class WrappedEventHandler : ILocalEventHandler>
{
public async Task HandleAsync(LocalEventWrapper eventData, CancellationToken cancellationToken = default)
{
await Task.CompletedTask;
}
}
```### Publish Wrapped Event Data
```
eventBus.SendAsync(new WrappedEventData());
```# License
MIT