This is a small sample application that demonstrates some of the features of forthcoming release of RawRabbit 2.0.
- Clone the repo
git clone https://github.com/pardahlman/RawRabbit.Todo.git
- Restore packages
dotnet restore
- Run
RawRabbit.Todo.Web
andRawRabbit.Todo
is two seperate terminalsdotnet run
- Surf to
localhost:5000
Listing all todos as well as create a new todo is fully event driven. The controller publishes a message and returnsa 200 OK
. The front end is updated through a SignalR push.
[HttpGet]
[Route("api/todos/")]
public async Task<IActionResult> GetAllTodos()
{
await PublishAsync(new CreateTodoList {Count = int.MaxValue});
return Ok(new {success = true});
}
Messages are directed to the right (SignalR) client but using Message Context Forwarding.
The service uses the new way to Acknowledge messages. If not defined, the messages are auto acked.
await busClient.SubscribeAsync<CreateTodo, TodoContext>(async (msg, context) =>
{
if (msg.Todo == null)
{
return new Nack(false);
}
var created = await repo.AddAsync(msg.Todo);
await busClient.PublishAsync(new TodoCreated
{
Todo = created
});
return new Ack();
});
Get even better control over the client. Override configuration with the fluent IPipeContext
action
var todo = await BusClient.RequestAsync<TodoRequest, TodoResponse>(new TodoRequest {Id = id},
ctx => ctx.UseRequestTimeout(TimeSpan.FromSeconds(20))
);