- Setup a working SuperBootstrapBase NuGet Package and configuration for your WebAPI project. Learn more
- Install the SuperBootstrapEvent NuGet Package.
- Add the following configuration in your
appsettings.json
file:
{
// other settings
"SuperBootstrap": {
// other superbootstrap settings
"Event": {
"Selected": "RabbitMq",
"Options": {
"RabbitMq": {
"HostName": "localhost",
"UserName": "guest",
"Password": "guest",
"Port": 5672,
"ExchangeName": "ex"
}
}
}
}
}
- In your controller class, you implement your publishers and/or your subscribers as follows:
public WeatherForecastController(ILogger<WeatherForecastController> logger,
ISuperBootstrapEventPublisher superBootstrapPublisher,
ICorrelationIdUtility correlationIdUtility)
{
_logger = logger;
_superBootstrapPublisher = superBootstrapPublisher;
_correlationIdUtility = correlationIdUtility;
}
[HttpGet("publish1")]
public async Task<ActionResult> PublishOne()
{
await _superBootstrapPublisher.PublishAsync(new SuperBootstrapEventPublishRequest
{
ObjectMessage = new DummyObject { Name = "ikan", Number = 123 },
CorrelationId = _correlationIdUtility.Get(),
TopicName = "event1"
});
return Ok();
}
[NonAction]
[SuperBootstrapEventSubscribe("event1")]
public void SubscriberOne(EventMessage eventMessage)
{
_logger.LogInformation($"1 -> {eventMessage.JsonMessage}");
}
- In your startup class, implement the superbootstrap event extension method:
public class Startup
{
public Startup(IConfiguration configuration)
{
Configuration = configuration;
}
public IConfiguration Configuration { get; }
public void ConfigureServices(IServiceCollection services)
{
// other services
services.AddBootstrapBase(Configuration);
services.AddBootstrapEvent(Configuration); // add this
}
// other
}
}