Integration
The Spares Services offers some messages that can be published, as well as some
events that another services can consume to keep up to date with new and updated
spares.
First of all, we need a reference to the Spares.Application.Contracts
project,
as it's shown below:
XML |
---|
| <ProjectReference Include="$(ServicesPath)Spares\ITsynch.Suite.Spares.Application.Contracts\ITsynch.Suite.Spares.Application.Contracts.csproj" />
|
Messages
From your module, you are able to request two different Spare's actions, wait
for their response and then continue:
Create or update a Spare:
C# |
---|
| var correlationId = NewId.NextGuid();
var displayName = "SILENCER";
var code = "ENG00";
var price = 10.75;
var inStockQuantity = 10;
var unitOfMeasure = UnitOfMeasure.Each;
var client = this.ServiceProvider.GetRequiredService<IRequestClient<CreateOrUpdateSpare>>();
var spareUpdated = (await client.GetResponse<SpareUpdated>(new
{
CorrelationId = correlationId,
DisplayName = displayName,
Code = code,
Price = price,
InStockQuantity = inStockQuantity,
UnitOfMeasure = (int)unitOfMeasure,
MakerDisplayName = default(string),
MakerReference = default(string)
})).Message;
|
Events
On the other hand, you can consume the different Spare's events and perform the
actions you need to do in your project.
Spare Updated:
C# |
---|
| using ITsynch.Suite.Spares.Application;
using MassTransit;
using System.Threading.Tasks;
namespace ITsynch.Suite.Example.Application
{
public class SpareUpdatedConsumer : IConsumer<SpareUpdated>
{
public SpareUpdatedConsumer()
{
}
public async Task Consume(ConsumeContext<SpareUpdated> context)
{
// do some stuff
}
}
}
|
This event includes all the Spare's information mentioned in the previous
section.
Note
SpareUpdated
event is published when a Spare is updated but
also when a Spare is created.