418.A Event Consumer for Lookup Resource Entities of ABP framework applications - chempkovsky/CS82ANGULAR GitHub Wiki
-
Note 1: Even though the repository and entity were created using the
LpPhbkDbContext
-DbContext, the next two classes must be generated using thefirstappDbContext
-DbContext. -
Note 2: Even though the code we are going to generate is for back-end implementation, we will use
Script Wizard
for this purpose - Create
Helper
-folder in therupbes.firstapp.Application.csproj
-project - Modify Directory.Build.props-files (we have two files) to switch the solution in the modeling mode.
- Right click
Helper
-folder of therupbes.firstapp.Application.csproj
-project- in the pop-up menu select
WebApi Services Wizard
- in the pop-up menu select
Click to show the picture
- on the second page select
firstappDbContext
-DbContext
Click to show the picture
- on the third page select
PhbkDivisionDto
-Dto
Click to show the picture
- on the fourth page select
01020-lookupheper
-Action type
Click to show the picture
- on the fifth page select
lookupheper.abp.cs.t4
-script
Click to show the picture
- click
Next
andsave
-buttons.phbk-division-dto.lookupheper.cs
file will be created -
Open
phbk-division-dto.lookupheper.cs
file and manually add correctusing ...
operators- It must be
using rupbes.firstapp.LpPhBk;
- It must be
Click to show the code
#nullable disable
using System.Threading.Tasks;
using Volo.Abp.Linq;
using System.Linq;
using Volo.Abp.Uow;
using Volo.Abp.Domain.Repositories;
using rupbes.firstapp.LpPhBk; // <<<---- THIS LINE WAS ADDED MANUALLY
// using rupbes.firstapp.Phbk;
namespace rupbes.firstapp.Helper {
public static class M2mUpdaterPhbkDivisionDto {
public static async Task<LpdDivision> SelDictItemForLpdDivisionDto(ILpdDivisionDtoRepo _rp, PhbkDivisionEto vm) {
using (_rp.DisableTracking()) {
IQueryable<LpdDivision> query = await _rp.GetQueryableAsync(); // db.LpdDivisionDbSet;
// "It Skipped" Info: for scalar prop = [DivisionNameId] of searchVM = [LpdDivisionDto] could not find mapped Unique Key property of the Entity = [LpdDivision]
// maybe it requires additional code related to nullable values
query = query.Where(p => p.DivisionName == vm.DivisionName);
//LpdDivision rslt = await query.FirstOrDefaultAsync();
// if(rslt != null) db.Entry(rslt).State = EntityState.Detached;
LpdDivision rslt = await _rp.AsyncExecuter.FirstOrDefaultAsync(query);
return rslt;
}
}
public static async Task<LpdDivision> InsDictItemForLpdDivisionDto(IUnitOfWorkManager _uowmng, ILpdDivisionDtoRepo _rp, PhbkDivisionEto vm) {
LpdDivision entityToAdd = new LpdDivision();
// "It Skipped" Info: scalar prop = [DivisionNameId] of searchVM = [LpdDivisionDto] is in primary key. Pay special attention if it should be defined with your special value. For instance, Guid.NewGuid().ToString("N");
// entityToAdd.DivisionNameId = // Guid.NewGuid().ToString("N");
entityToAdd.DivisionName = vm.DivisionName; // scalar prop names are identical
// pay special attention to primKey values
// db.LpdDivisionDbSet.Add(entityToAdd);
// await db.SaveChangesAsync();
// db.Entry(entityToAdd).State = EntityState.Detached;
await _rp.InsertAsync(entityToAdd);
await _uowmng.Current.SaveChangesAsync();
return entityToAdd;
}
// action: 1 - insert; 2 - update; 3 - delete
public static async Task UpdateForLprDivision01Dto(IUnitOfWorkManager _uowmng, // firstappDbContext db,
ILprDivision01DtoRepo _rpILprDivision01DtoRepo,
ILpdDivisionDtoRepo _rpILpdDivisionDtoRepo,
int action, PhbkDivisionEto oldObj, PhbkDivisionEto newObj) {
if ( (action < 1) || (action > 3)) return; // or throw exception
if ( ((action == 2) || (action == 3)) && (oldObj == null) ) return; // or throw exception
if ( ((action == 1) || (action == 2)) && (newObj == null) ) return; // or throw exception
// 2 - update; 3 - delete
if ((action == 2) || (action == 3)) {
bool readyToDel = true;
LprDivision01 LprDivision01DtoupdDelTmp = new LprDivision01() {
Id = oldObj.Id
}; // LprDivision01DtoupdDelTmp
if(readyToDel) {
LpdDivision LpdDivisionDtoupdDelTmp = await SelDictItemForLpdDivisionDto( // db, oldObj);
_rpILpdDivisionDtoRepo, oldObj);
readyToDel = LpdDivisionDtoupdDelTmp == null;
if(readyToDel) {
LprDivision01DtoupdDelTmp.DivisionNameIdRef = LpdDivisionDtoupdDelTmp.DivisionNameId;
}
}
if(readyToDel) {
IQueryable<LprDivision01> m2mDelQuery = // db.LprDivision01DbSet;
await _rpILprDivision01DtoRepo.GetQueryableAsync();
m2mDelQuery = m2mDelQuery.Where(p=> p.Id == LprDivision01DtoupdDelTmp.Id);
m2mDelQuery = m2mDelQuery.Where(p=> p.DivisionNameIdRef == LprDivision01DtoupdDelTmp.DivisionNameIdRef);
// var delM2mRslt = await m2mDelQuery.FirstOrDefaultAsync();
var delM2mRslt = await _rpILprDivision01DtoRepo.AsyncExecuter.FirstOrDefaultAsync(m2mDelQuery);
if(delM2mRslt != null) {
// db.LprDivision01DbSet.Remove(delM2mRslt);
// db.SaveChanges();
// db.Entry(delM2mRslt).State = EntityState.Detached;
await _rpILprDivision01DtoRepo.DeleteAsync(delM2mRslt);
await _uowmng.Current.SaveChangesAsync();
}
}
}
// 1 - insert; 2 - update;
if ((action == 1) || (action == 2)) {
LprDivision01 LprDivision01DtoInsTmp = new LprDivision01() {
Id = newObj.Id
}; // LprDivision01DtoInsTmp
LpdDivision LpdDivisionDtoInsTmp = await SelDictItemForLpdDivisionDto( // db, newObj);
_rpILpdDivisionDtoRepo, newObj);
if(LpdDivisionDtoInsTmp == null) {
LpdDivisionDtoInsTmp = await InsDictItemForLpdDivisionDto( // db, newObj);
_uowmng, _rpILpdDivisionDtoRepo, newObj);
}
LprDivision01DtoInsTmp.DivisionNameIdRef = LpdDivisionDtoInsTmp.DivisionNameId;
IQueryable<LprDivision01> m2mInsQuery = // db.LprDivision01DbSet;
await _rpILprDivision01DtoRepo.GetQueryableAsync();
m2mInsQuery = m2mInsQuery.Where(p=> p.Id == LprDivision01DtoInsTmp.Id);
m2mInsQuery = m2mInsQuery.Where(p=> p.DivisionNameIdRef == LprDivision01DtoInsTmp.DivisionNameIdRef);
// var insM2mRslt = await m2mInsQuery.FirstOrDefaultAsync();
var insM2mRslt = await _rpILprDivision01DtoRepo.AsyncExecuter.FirstOrDefaultAsync(m2mInsQuery);
if(insM2mRslt != null) return;
// db.LprDivision01DbSet.Add(LprDivision01DtoInsTmp);
// await db.SaveChangesAsync();
// db.Entry(LprDivision01DtoInsTmp).State = EntityState.Detached;
await _rpILprDivision01DtoRepo.InsertAsync(insM2mRslt);
await _uowmng.Current.SaveChangesAsync();
return;
}
}
// action: 1 - insert; 2 - update; 3 - delete
public static async Task UpdateForLprDivision02Dto(IUnitOfWorkManager _uowmng, // firstappDbContext db,
ILprDivision02DtoRepo _rpILprDivision02DtoRepo,
ILpdDivisionDtoRepo _rpILpdDivisionDtoRepo,
int action, PhbkDivisionEto oldObj, PhbkDivisionEto newObj) {
if ( (action < 1) || (action > 3)) return; // or throw exception
if ( ((action == 2) || (action == 3)) && (oldObj == null) ) return; // or throw exception
if ( ((action == 1) || (action == 2)) && (newObj == null) ) return; // or throw exception
// 2 - update; 3 - delete
if ((action == 2) || (action == 3)) {
bool readyToDel = true;
LprDivision02 LprDivision02DtoupdDelTmp = new LprDivision02() {
Id = oldObj.Id,
EntrprsIdRef = oldObj.EntrprsIdRef,
}; // LprDivision02DtoupdDelTmp
if(readyToDel) {
LpdDivision LpdDivisionDtoupdDelTmp = await SelDictItemForLpdDivisionDto( // db, oldObj);
_rpILpdDivisionDtoRepo, oldObj);
readyToDel = LpdDivisionDtoupdDelTmp == null;
if(readyToDel) {
LprDivision02DtoupdDelTmp.DivisionNameIdRef = LpdDivisionDtoupdDelTmp.DivisionNameId;
}
}
if(readyToDel) {
IQueryable<LprDivision02> m2mDelQuery = // db.LprDivision02DbSet;
await _rpILprDivision02DtoRepo.GetQueryableAsync();
m2mDelQuery = m2mDelQuery.Where(p=> p.Id == LprDivision02DtoupdDelTmp.Id);
m2mDelQuery = m2mDelQuery.Where(p=> p.EntrprsIdRef == LprDivision02DtoupdDelTmp.EntrprsIdRef);
m2mDelQuery = m2mDelQuery.Where(p=> p.DivisionNameIdRef == LprDivision02DtoupdDelTmp.DivisionNameIdRef);
// var delM2mRslt = await m2mDelQuery.FirstOrDefaultAsync();
var delM2mRslt = await _rpILprDivision02DtoRepo.AsyncExecuter.FirstOrDefaultAsync(m2mDelQuery);
if(delM2mRslt != null) {
// db.LprDivision02DbSet.Remove(delM2mRslt);
// db.SaveChanges();
// db.Entry(delM2mRslt).State = EntityState.Detached;
await _rpILprDivision02DtoRepo.DeleteAsync(delM2mRslt);
await _uowmng.Current.SaveChangesAsync();
}
}
}
// 1 - insert; 2 - update;
if ((action == 1) || (action == 2)) {
LprDivision02 LprDivision02DtoInsTmp = new LprDivision02() {
Id = newObj.Id,
EntrprsIdRef = newObj.EntrprsIdRef,
}; // LprDivision02DtoInsTmp
LpdDivision LpdDivisionDtoInsTmp = await SelDictItemForLpdDivisionDto( // db, newObj);
_rpILpdDivisionDtoRepo, newObj);
if(LpdDivisionDtoInsTmp == null) {
LpdDivisionDtoInsTmp = await InsDictItemForLpdDivisionDto( // db, newObj);
_uowmng, _rpILpdDivisionDtoRepo, newObj);
}
LprDivision02DtoInsTmp.DivisionNameIdRef = LpdDivisionDtoInsTmp.DivisionNameId;
IQueryable<LprDivision02> m2mInsQuery = // db.LprDivision02DbSet;
await _rpILprDivision02DtoRepo.GetQueryableAsync();
m2mInsQuery = m2mInsQuery.Where(p=> p.Id == LprDivision02DtoInsTmp.Id);
m2mInsQuery = m2mInsQuery.Where(p=> p.EntrprsIdRef == LprDivision02DtoInsTmp.EntrprsIdRef);
m2mInsQuery = m2mInsQuery.Where(p=> p.DivisionNameIdRef == LprDivision02DtoInsTmp.DivisionNameIdRef);
// var insM2mRslt = await m2mInsQuery.FirstOrDefaultAsync();
var insM2mRslt = await _rpILprDivision02DtoRepo.AsyncExecuter.FirstOrDefaultAsync(m2mInsQuery);
if(insM2mRslt != null) return;
// db.LprDivision02DbSet.Add(LprDivision02DtoInsTmp);
// await db.SaveChangesAsync();
// db.Entry(LprDivision02DtoInsTmp).State = EntityState.Detached;
await _rpILprDivision02DtoRepo.InsertAsync(insM2mRslt);
await _uowmng.Current.SaveChangesAsync();
return;
}
}
// action: 1 - insert; 2 - update; 3 - delete
public static async Task UpdateForPhbkDivisionDto(IUnitOfWorkManager _uowmng, // firstappDbContext db,
ILprDivision01DtoRepo _rpILprDivision01DtoRepo,
ILpdDivisionDtoRepo _rpILpdDivisionDtoRepo,
ILprDivision02DtoRepo _rpILprDivision02DtoRepo,
int action, PhbkDivisionEto oldObj, PhbkDivisionEto newObj) {
if ( (action < 1) || (action > 3)) return; // or throw exception
if ( ((action == 2) || (action == 3)) && (oldObj == null) ) return; // or throw exception
if ( ((action == 1) || (action == 2)) && (newObj == null) ) return; // or throw exception
// 3 - delete; 2 - update
if ((action == 3) || (action == 2)) {
bool readyToDel = true;
LprDivision01 LprDivision01DtoupdDelTmp = new LprDivision01() {
Id = oldObj.Id
}; // LprDivision01DtoupdDelTmp
LpdDivision LpdDivisionDtodelTmp = await SelDictItemForLpdDivisionDto( //db, oldObj);
_rpILpdDivisionDtoRepo, oldObj);
readyToDel = true;
if (readyToDel) {
readyToDel = LpdDivisionDtodelTmp != null;
if(readyToDel) {
LprDivision01DtoupdDelTmp.DivisionNameIdRef = LpdDivisionDtodelTmp.DivisionNameId;
}
}
if(readyToDel) {
IQueryable<LprDivision01> LprDivision01DtoDelQuery = // db.LprDivision01DbSet;
await _rpILprDivision01DtoRepo.GetQueryableAsync();
LprDivision01DtoDelQuery = LprDivision01DtoDelQuery.Where(p=> p.Id == LprDivision01DtoupdDelTmp.Id);
LprDivision01DtoDelQuery = LprDivision01DtoDelQuery.Where(p=> p.DivisionNameIdRef == LprDivision01DtoupdDelTmp.DivisionNameIdRef);
// var LprDivision01DtoDelRslt = await LprDivision01DtoDelQuery.FirstOrDefaultAsync();
var LprDivision01DtoDelRslt = await _rpILprDivision01DtoRepo.AsyncExecuter.FirstOrDefaultAsync(LprDivision01DtoDelQuery);
if(LprDivision01DtoDelRslt != null) {
// db.LprDivision01DbSet.Remove(LprDivision01DtoDelRslt);
// db.SaveChanges();
// db.Entry(LprDivision01DtoDelRslt).State = EntityState.Detached;
await _rpILprDivision01DtoRepo.DeleteAsync(LprDivision01DtoDelRslt);
await _uowmng.Current.SaveChangesAsync();
}
}
LprDivision02 LprDivision02DtoupdDelTmp = new LprDivision02() {
Id = oldObj.Id,
EntrprsIdRef = oldObj.EntrprsIdRef,
}; // LprDivision02DtoupdDelTmp
readyToDel = true;
if (readyToDel) {
readyToDel = LpdDivisionDtodelTmp != null;
if(readyToDel) {
LprDivision02DtoupdDelTmp.DivisionNameIdRef = LpdDivisionDtodelTmp.DivisionNameId;
}
}
if(readyToDel) {
IQueryable<LprDivision02> LprDivision02DtoDelQuery = // db.LprDivision02DbSet;
await _rpILprDivision02DtoRepo.GetQueryableAsync();
LprDivision02DtoDelQuery = LprDivision02DtoDelQuery.Where(p=> p.Id == LprDivision02DtoupdDelTmp.Id);
LprDivision02DtoDelQuery = LprDivision02DtoDelQuery.Where(p=> p.EntrprsIdRef == LprDivision02DtoupdDelTmp.EntrprsIdRef);
LprDivision02DtoDelQuery = LprDivision02DtoDelQuery.Where(p=> p.DivisionNameIdRef == LprDivision02DtoupdDelTmp.DivisionNameIdRef);
// var LprDivision02DtoDelRslt = await LprDivision02DtoDelQuery.FirstOrDefaultAsync();
var LprDivision02DtoDelRslt = await _rpILprDivision02DtoRepo.AsyncExecuter.FirstOrDefaultAsync(LprDivision02DtoDelQuery);
if(LprDivision02DtoDelRslt != null) {
// db.LprDivision02DbSet.Remove(LprDivision02DtoDelRslt);
// db.SaveChanges();
// db.Entry(LprDivision02DtoDelRslt).State = EntityState.Detached;
await _rpILprDivision02DtoRepo.DeleteAsync(LprDivision02DtoDelRslt);
await _uowmng.Current.SaveChangesAsync();
}
}
}
// 1 - insert; 2 - update
if ((action == 1) || (action == 2)) {
LprDivision01 LprDivision01DtoInsTmp = new LprDivision01() {
Id = newObj.Id
}; // LprDivision01DtoInsTmp
LpdDivision LpdDivisionDtoInsTmp = await SelDictItemForLpdDivisionDto( //db, newObj);
_rpILpdDivisionDtoRepo, newObj);
if(LpdDivisionDtoInsTmp == null) {
LpdDivisionDtoInsTmp = await InsDictItemForLpdDivisionDto( // db, newObj);
_uowmng, _rpILpdDivisionDtoRepo, newObj);
}
LprDivision01DtoInsTmp.DivisionNameIdRef = LpdDivisionDtoInsTmp.DivisionNameId;
IQueryable<LprDivision01> LprDivision01DtoInsQuery = // db.LprDivision01DbSet;
await _rpILprDivision01DtoRepo.GetQueryableAsync();
LprDivision01DtoInsQuery = LprDivision01DtoInsQuery.Where(p=> p.Id == LprDivision01DtoInsTmp.Id);
LprDivision01DtoInsQuery = LprDivision01DtoInsQuery.Where(p=> p.DivisionNameIdRef == LprDivision01DtoInsTmp.DivisionNameIdRef);
// var LprDivision01DtoinsRslt = await LprDivision01DtoInsQuery.FirstOrDefaultAsync();
var LprDivision01DtoinsRslt = await _rpILprDivision01DtoRepo.AsyncExecuter.FirstOrDefaultAsync(LprDivision01DtoInsQuery);
if(LprDivision01DtoinsRslt == null) {
// db.LprDivision01DbSet.Add(LprDivision01DtoInsTmp);
// await db.SaveChangesAsync();
// db.Entry(LprDivision01DtoInsTmp).State = EntityState.Detached;
await _rpILprDivision01DtoRepo.InsertAsync(LprDivision01DtoInsTmp);
await _uowmng.Current.SaveChangesAsync();
}
LprDivision02 LprDivision02DtoInsTmp = new LprDivision02() {
Id = newObj.Id,
EntrprsIdRef = newObj.EntrprsIdRef,
}; // LprDivision02DtoInsTmp
LprDivision02DtoInsTmp.DivisionNameIdRef = LpdDivisionDtoInsTmp.DivisionNameId;
IQueryable<LprDivision02> LprDivision02DtoInsQuery = // db.LprDivision02DbSet;
await _rpILprDivision02DtoRepo.GetQueryableAsync();
LprDivision02DtoInsQuery = LprDivision02DtoInsQuery.Where(p=> p.Id == LprDivision02DtoInsTmp.Id);
LprDivision02DtoInsQuery = LprDivision02DtoInsQuery.Where(p=> p.EntrprsIdRef == LprDivision02DtoInsTmp.EntrprsIdRef);
LprDivision02DtoInsQuery = LprDivision02DtoInsQuery.Where(p=> p.DivisionNameIdRef == LprDivision02DtoInsTmp.DivisionNameIdRef);
// var LprDivision02DtoinsRslt = await LprDivision02DtoInsQuery.FirstOrDefaultAsync();
var LprDivision02DtoinsRslt = await _rpILprDivision02DtoRepo.AsyncExecuter.FirstOrDefaultAsync(LprDivision02DtoInsQuery);
if(LprDivision02DtoinsRslt == null) {
// db.LprDivision02DbSet.Add(LprDivision02DtoInsTmp);
// await db.SaveChangesAsync();
// db.Entry(LprDivision02DtoInsTmp).State = EntityState.Detached;
await _rpILprDivision02DtoRepo.InsertAsync(LprDivision02DtoInsTmp);
await _uowmng.Current.SaveChangesAsync();
}
}
}
}
}
-
Create
Consumer
-folder in therupbes.firstapp.Application.csproj
-project -
Right click
Consumer
-folder of therupbes.firstapp.Application.csproj
-project- in the pop-up menu select
WebApi Services Wizard
- in the pop-up menu select
-
Repeat all the steps described above until fourth page
-
on the fourth page select
01025-masstransit.consumer.cs
-Action type
Click to show the picture
- on the fifth page select
consumer.abp.cs.t4
-script.phbk-division-dto.masstransit.consumer.cs
file will be created.
Click to show the picture
-
Open
phbk-division-dto.masstransit.consumer.cs
file and manually add twousing...
-operators- It must be
using rupbes.firstapp.Helper;
andusing rupbes.firstapp.LpPhBk;
- It must be
Click to show the code
#nullable disable
using rupbes.firstapp.Helper;
using rupbes.firstapp.LpPhBk;
using System.Threading.Tasks;
using Volo.Abp.DependencyInjection;
using Volo.Abp.EventBus.Distributed;
using Volo.Abp.Linq;
using Volo.Abp.MultiTenancy;
using Volo.Abp.Uow;
/*
according to https://abp.io/docs/latest/framework/infrastructure/event-bus/distributed
and according to https://abp.io/docs/latest/framework/infrastructure/event-bus/distributed/rabbitmq
==1==
in `appsettings.json` of the `XXXXX.YYYYY.HttpApi.Host.csproj`-project add the setting like below
{
...
"RabbitMQ": {
"Connections": {
"Default": {
"HostName": "123.123.123.123"
"Port": "5672"
},
"SecondConnection": {
"HostName": "10.183.96.51"
"Port": "5672"
}
},
"EventBus": {
"ClientName": "firstapp",
"ExchangeName": "firstappExchange",
"ConnectionName": "SecondConnection",
"VirtualHost": "abpphbkhost"
}
}
...
}
==2==
modify the `XXXXX.YYYYY.HttpApi.Host.csproj`-file. Set correct Version (in our case Version="9.1.3" )
<ItemGroup>
<PackageReference Include="Volo.Abp.EventBus.RabbitMQ" Version="9.1.3" />
</ItemGroup>
==3==
in the class `YYYYYHttpApiHostModule` of the `XXXXX.YYYYY.HttpApi.Host.csproj`-project modify:
[DependsOn(
...
typeof(AbpEventBusRabbitMqModule)
)]
public class YYYYYHttpApiHostModule : AbpModule {
...
...
public override void ConfigureServices(ServiceConfigurationContext context)
{
var configuration = context.Services.GetConfiguration();
var hostingEnvironment = context.Services.GetHostingEnvironment();
...
...
string rmqCnn = configuration["RabbitMQ:EventBus:ConnectionName"]!;
Configure<AbpRabbitMqOptions>(options =>
{
if (!int.TryParse(configuration["RabbitMQ:Connections:" + rmqCnn + ":Port"], out int rmqPort) )
{
rmqPort = 5672;
}
options.Connections.Default.UserName = "abpadmin";
options.Connections.Default.Password = "abpadmin";
options.Connections.Default.HostName = configuration["RabbitMQ:Connections:" + rmqCnn + ":HostName"]!;
options.Connections.Default.Port = rmqPort;
options.Connections.Default.VirtualHost = configuration["RabbitMQ:EventBus:VirtualHost"];
});
Configure<AbpRabbitMqEventBusOptions>(options =>
{
options.ClientName = configuration["RabbitMQ:EventBus:ClientName"]!;
options.ExchangeName = configuration["RabbitMQ:EventBus:ExchangeName"]!;
options.PrefetchCount = 1;
options.ExchangeArguments["x-delayed-type"] = "direct";
options.QueueArguments["x-message-ttl"] = 60000;
});
...
...
}
...
...
}
==3==
in a command-line terminal on a server with RabbitMQ installed
run the commands to created user (user name= "abpadmin" and password "abpadmin"):
rabbitmqctl add_user "abpadmin" "abpadmin"
rabbitmqctl set_user_tags abpadmin administrator
rabbitmqctl set_permissions -p "/" "abpadmin" ".*" ".*" ".*"
rabbitmqctl set_topic_permissions -p "/" "abpadmin" ".*" ".*" ".*"
rabbitmqctl list_users
in a command line terminal on a server with RabbitMQ installed
run the commands to created virtual host ("abpphbkhost")
run commands to assign rights to user ("abpadmin") on virtual host ("abpphbkhost")
rabbitmqctl add_vhost abpphbkhost
rabbitmqctl set_vhost_limits -p abpphbkhost "{'max-queues': 30, 'max-connections': 25}"
rabbitmqctl set_permissions -p "abpphbkhost" "abpadmin" ".*" ".*" ".*"
rabbitmqctl set_topic_permissions -p "abpphbkhost" "abpadmin" ".*" ".*" ".*"
rabbitmqctl list_exchanges -p "abpphbkhost"
*/
namespace rupbes.firstapp.Consumer {
// public class MyHandler : ILocalEventHandler<PhbkDivisionEtoEx>, ITransientDependency
public class PhbkDivisionDtoExtForLkUpMsgConsumer : IDistributedEventHandler<PhbkDivisionEtoEx>, ITransientDependency {
public IAbpLazyServiceProvider LazyServiceProvider { get; set; } = default!;
public IUnitOfWorkManager UnitOfWorkManager => LazyServiceProvider.LazyGetRequiredService<IUnitOfWorkManager>();
public ICurrentTenant CurrentTenant => LazyServiceProvider.LazyGetRequiredService<ICurrentTenant>();
public ILprDivision01DtoRepo rpILprDivision01DtoRepo => LazyServiceProvider.LazyGetRequiredService<ILprDivision01DtoRepo>();
public ILpdDivisionDtoRepo rpILpdDivisionDtoRepo => LazyServiceProvider.LazyGetRequiredService<ILpdDivisionDtoRepo>();
public ILprDivision02DtoRepo rpILprDivision02DtoRepo => LazyServiceProvider.LazyGetRequiredService<ILprDivision02DtoRepo>();
public PhbkDivisionDtoExtForLkUpMsgConsumer() { }
// 1. the method must be declared as virtual
// 2. without [UnitOfWork]-attribure it does not work
[UnitOfWork]
public virtual async Task HandleEventAsync(PhbkDivisionEtoEx eventData)
{
using (this.CurrentTenant.Change(eventData.TenantId))
{
await M2mUpdaterPhbkDivisionDto.UpdateForPhbkDivisionDto(
_uowmng : this.UnitOfWorkManager,
_rpILprDivision01DtoRepo : this.rpILprDivision01DtoRepo,
_rpILpdDivisionDtoRepo : this.rpILpdDivisionDtoRepo,
_rpILprDivision02DtoRepo : this.rpILprDivision02DtoRepo,
action : eventData.Action,
oldObj : eventData.OldVals,
newObj : eventData.NewVals);
}
}
}
}
- Follow the instructions at the begining of the
phbk-division-dto.masstransit.consumer.cs
-file- How to modify
appsettings.json
-file - How to modify
...HttpApi.Host.csproj
-file: add a reference ontoVolo.Abp.EventBus.RabbitMQ
-package - How to modify
...HttpApiHostModule
-class:Configure<AbpRabbitMqOptions>(options => ...)
andConfigure<AbpRabbitMqEventBusOptions>(options => ...)
- How to configure
RabbitMq
-server: add virtual host, add user, add rights to the user
- How to modify