An open API service indexing awesome lists of open source software.

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

开源的轻量级本地消息总线类库

Awesome Lists containing this project

README

        

# MyStack.LocalMessage

Open-source lightweight local message bus library

| nuget | stats |
| ----------- | ----------- |
| [![nuget](https://img.shields.io/nuget/v/MyStack.LocalMessage.svg?style=flat-square)](https://www.nuget.org/packages/MyStack.LocalMessage) | [![stats](https://img.shields.io/nuget/dt/MyStack.LocalMessage.svg?style=flat-square)](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