043 Service bus Consumer for PhbkDivisionView - chempkovsky/CS82ANGULAR GitHub Wiki
- Create the Consumers folder to LpPhBkControllers project
- Repeat the steps
- Fourth page of the Wizard
- Fifth page of the Wizard
- Sixth page of the Wizard
- Open generated file
- Configuring MassTransit for an Application
- We have already created the service, which sends data to the bus.
- We have already created the Helper class which updates the data to the
- MassTransit introduces Consumer
- Now we need the code, which receives data from the Service bus and calls the methods of the Helper class.
- with
01025-.masstransit.consumer.cs
-Wizard's script we will generate the code for the Service bus Consumer.
- with
- Since we have two database contexts,
PhbkDbContext
andLpPhbkDbContext
, the question is which one to use to run the wizard script.-
PhbkDbContext
must be used to generate Lookup resource Service bus Consumer.
-
- with Visual Studio add
Consumers
-folder to LpPhBkControllers project
Click to show the picture
- repeat the steps of the article 042 starting from Run JavasScripts Wizard and until to the fourth step.
- On the Fourth page of the Wizard select
01025-.masstransit.consumer.cs
-script type and clickNext
-button
- On the Fifth page of the Wizard select
masstransit.consumer.cs.t4
-script and clickNext
-button
- On the Sixth page of the Wizard click
Save
-button. close the Wizard -
phbk-division-view.masstransit.consumer.cs
-file will be created.
- open
phbk-division-view.masstransit.consumer.cs
-file
Click to show the picture
- We need to make modifications of the
phbk-division-view.masstransit.consumer.cs
-file
-
replace the
using PhBkContext.PhBk;
-line with theusing LpPhBkContext.PhBk;
-
replace the
PhbkDbContext db
-code with the codeLpPhbkDbContext db
in thephbk-division-view.masstransit.consumer.cs
-file -
replace the
PhbkDbContext dbcontext
-code with the codeLpPhbkDbContext dbcontext
in thephbk-division-view.masstransit.consumer.cs
-file -
Note: The Lookup resource Helper and Consumer Classes are the only two classes that need to be modified after generation. We can not use
LpPhbkDbContext
to generatephbk-division-view.masstransit.consumer.cs
-file. Without additional foreign keys, the Wizard will not be able to recognize the group of tables as a lookup resource. To be recognizable as a lookup resource,LprDivision01
andLprDivision02
tables must have a foreign key, which referencesPhbkDivision
-table. In additionLprDivision02
must have a foreign key, which referencesPhbkEnterprise
-table... In short, find and replace-approach is optimal.
- open
phbk-division-view.masstransit.consumer.cs
-file- at the beginning of the file you will find instruction of how to setup the app to connect to Service bus
Click to show the code
...
/*
according to https://masstransit-project.com/usage/configuration.html#configuration
make sure Program.cs file contains the following code:
#region MassTransit config
using MassTransit;
#endregion
...
var builder = WebApplication.CreateBuilder(args);
...
#region MassTransit config
builder.Services.AddMassTransit(x => {
x.AddConsumer<PhbkDivisionViewExtForLkUpMsgConsumer>(typeof(PhbkDivisionViewExtForLkUpMsgConsumerDefinition));
//.Endpoint(e =>
//{
// override the default endpoint name
// e.Name = phbk-division-view;
// specify the endpoint as temporary (may be non-durable, auto-delete, etc.)
e.Temporary = false;
// specify an optional concurrent message limit for the consumer
e.ConcurrentMessageLimit = 8;
// only use if needed, a sensible default is provided, and a reasonable
// value is automatically calculated based upon ConcurrentMessageLimit if
// the transport supports it.
e.PrefetchCount = 16;
// set if each service instance should have its own endpoint for the consumer
// so that messages fan out to each instance.
e.InstanceId = "something-unique";
//});
x.UsingRabbitMq((context, configurator) => {
configurator.Host("192.168.100.4", "RabbitMq_virtual_host_name", h =>
{
h.Username("RabbitMq_admin_name");
h.Password("RabbitMq_admin_password");
//
// Cluster settings
//
// h.UseCluster((configureCluster) =>
// {
// configureCluster.Node("192.168.100.5");
// configureCluster.Node("192.168.100.6");
// ...
// configureCluster.Node("192.168.100.10");
// });
// h.PublisherConfirmation = true;
//h.ConfigureBatchPublish(configure =>
//{
//});
});
//
// Quorum Queue settings
//
// configurator.SetQuorumQueue(3);
//
configurator.ConfigureEndpoints(context);
});
});
builder.Services.AddOptions<MassTransitHostOptions>()
.Configure(options =>
{
// if specified, waits until the bus is started before
// returning from IHostedService.StartAsync
// default is false
options.WaitUntilStarted = true;
// if specified, limits the wait time when starting the bus
options.StartTimeout = TimeSpan.FromSeconds(10);
// if specified, limits the wait time when stopping the bus
options.StopTimeout = TimeSpan.FromSeconds(30);
});
#endregion
*/
...