083 Preparing the Lookup resource application to run - chempkovsky/CS82ANGULAR GitHub Wiki
- Since, it's a demo project, we did not create separate WebApi app for the
PhbkEmployeeView
Lookup resource services, though it is highly recommended.- instead, we created a separate Dbcontext for the
PhbkEmployeeView
Lookup resource - instead, we created a separate consumer
- instead, we will create a separate copy of the Service Bus in the
LpPhBkWebApp
-app with a separate section in theappsettings.json
.
- instead, we created a separate Dbcontext for the
- Having three "instead", it'll be very easy to migrate to the separate WebApi app for the
PhbkEmployeeView
Lookup resource services.- What projects need to be created was described in the article 034 CREATING LOOKUP RESOURCE PROJECTS
- Detailed comments about configuration have already been made in the article 46
- We do not describe step by step instructions in this article
- the only information summary will be presented
-
the following elements must be added to the
appsettings.json
file- connection string for the
LpEmpPhBkContext
dbcontext -
PhbkEmployeeViewExtForLkUpConf
-section to configure second instance of the Service Bus
- connection string for the
-
We introduce
ConnectionStrings:LpEmpPhBkConnection
-item to configureLpEmpPhBkContext
-DbContext
Click to show the code
"ConnectionStrings": {
"LpPhnPhBkConnection": "Data Source=SVR2016SQL2017;Initial Catalog=LpPhnPhBkDbDef;Persist Security Info=True;User ID=sa;Password=your_password_heer",
"LpEmpPhBkConnection": "Data Source=SVR2016SQL2017;Initial Catalog=LpEmpPhBkDbDef;Persist Security Info=True;User ID=sa;Password=your_password_heer",
"LpPhBkConnection": "Data Source=SVR2016SQL2017;Initial Catalog=LpPhBkDbDef;Persist Security Info=True;User ID=sa;Password=your_password_heer",
},
- open
phbk-phone-view.extforlkup.interface.cs
mentioned in the article 077. In the end of the file you will find thePhbkPhoneViewExtForLkUpConf
-class along with the instructions on how to use it
Click to show the code
/*
In appsettings.json it must be added the section like below.
1. If a RabbitMq cluster is present:
"PhbkPhoneViewExtForLkUpConf": {
"HostName ": "192.168.100.3",
"Username": "Admin",
"Password": "Admin",
"VirtualHostName": "phbkhost",
"ClusterIpAddresses": [
"192.168.100.4",
"192.168.100.5",
"192.168.100.6"
]
}
2. If a RabbitMq cluster is not present:
"PhbkPhoneViewExtForLkUpConf": {
"HostName ": "192.168.100.3",
"Username": "Admin",
"Password": "Admin",
"VirtualHostName": "phbkhost",
"ClusterIpAddresses": []
}
3. In the Program.cs file add the code like below:
var builder = WebApplication.CreateBuilder(args);
...
ConfigurationManager configuration = builder.Configuration;
...
var myOptions = new PhbkPhoneViewExtForLkUpConf();
configuration.GetSection(PhbkPhoneViewExtForLkUpConf.ConfName).Bind(myOptions);
...
*/
public class PhbkPhoneViewExtForLkUpConf {
public static string ConfName = "PhbkPhoneViewExtForLkUpConf";
public string HostName { get; set; } = String.Empty;
public string Username { get; set; } = String.Empty;
public string Password { get; set; } = String.Empty;
public string VirtualHostName { get; set; } = String.Empty;
public string[] ClusterIpAddresses { get; set; } = null!;
}
- We will use the same RabbitMq server, Vhost, user as those desribed in the article 046. Thus, the
PhbkPhoneViewExtForLkUpConf
-section will be identical to thePhbkDivisionViewExtForLkUpConf
-section.
Click to show the code
"PhbkDivisionViewExtForLkUpConf": {
"HostName": "192.168.100.3",
"Username": "admin",
"Password": "admin",
"VirtualHostName": "phbkhost",
"ClusterIpAddresses": []
},
"PhbkEmployeeViewExtForLkUpConf": {
"HostName": "192.168.100.3",
"Username": "admin",
"Password": "admin",
"VirtualHostName": "phbkhost",
"ClusterIpAddresses": []
},
"PhbkPhoneViewExtForLkUpConf": {
"HostName": "192.168.100.3",
"Username": "admin",
"Password": "admin",
"VirtualHostName": "phbkhost",
"ClusterIpAddresses": []
}
- Open
Program.cs
-file of theLpPhBkWebApp
-project and registerLpPhnPhBkContext
-context
Click to show the code
...
var builder = WebApplication.CreateBuilder(args);
...
ConfigurationManager configuration = builder.Configuration;
...
builder.Services.AddDbContext<LpPhnPhBkContext>(options =>
options.UseSqlServer(configuration.GetConnectionString("LpPhnPhBkConnection")));
- to configure the second instance of the MassTransit Service Bus
- read the article first. (It gives an example configuration)
- Add the
IBusLpPhbkPhone.cs
-file in theConsumers
-folder of theLpPhBkControllers.csproj
-project with a code
Click to show the code
using MassTransit;
namespace LpPhBkControllers.Consumers
{
public interface IBusLpPhbkPhone : IBus
{
}
}
- Back to the
Program.cs
file- we get the
PhbkPhoneViewExtForLkUpConf
-section fromappsettings.json
-file - using
PhbkPhoneViewExtForLkUpConf
-section we configure second instance of the MassTransit Service Bus-
builder.Services.AddMassTransit<IBusLpPhbkPhone>
-code declares the second copy of the Service Bus.
-
- we get the
Click to show the code
#region MassTransit config
...
var phbkPhoneViewExtForLkUpConf = new PhbkPhoneViewExtForLkUpConf();
configuration.GetSection(PhbkPhoneViewExtForLkUpConf.ConfName).Bind(phbkPhoneViewExtForLkUpConf);
builder.Services.AddMassTransit<IBusLpPhbkPhone>(x => {
x.AddConsumer<PhbkPhoneViewExtForLkUpMsgConsumer>(typeof(PhbkPhoneViewExtForLkUpMsgConsumerDefinition));
//.Endpoint(e => {
// e.Name = "phbk-division-view";
//});
x.UsingRabbitMq((context, configurator) => {
configurator.Host(phbkPhoneViewExtForLkUpConf.HostName, phbkPhoneViewExtForLkUpConf.VirtualHostName, h => {
h.Username(phbkPhoneViewExtForLkUpConf.Username);
h.Password(phbkPhoneViewExtForLkUpConf.Password);
if (phbkPhoneViewExtForLkUpConf.ClusterIpAddresses != null)
{
if (phbkPhoneViewExtForLkUpConf.ClusterIpAddresses.Length > 0)
{
h.UseCluster((configureCluster) => {
for (int i = 0; i < phbkPhoneViewExtForLkUpConf.ClusterIpAddresses.Length; i++)
{
configureCluster.Node(phbkPhoneViewExtForLkUpConf.ClusterIpAddresses[i]);
}
});
}
}
// h.PublisherConfirmation = true;
// h.ConfigureBatchPublish(configure => { });
});
configurator.ConfigureEndpoints(context);
//
// Quorum Queue settings
//
// configurator.SetQuorumQueue(3);
//
});
});
#endregion
- we add the same PhbkPhoneViewExtForLkUpConf-section as for appsettings json for LpPhBkWebApp
Click to show the code
"PhbkDivisionViewExtForLkUpConf": {
"HostName": "192.168.100.3",
"Username": "admin",
"Password": "admin",
"VirtualHostName": "phbkhost",
"ClusterIpAddresses": []
},
"PhbkEmployeeViewExtForLkUpConf": {
"HostName": "192.168.100.3",
"Username": "admin",
"Password": "admin",
"VirtualHostName": "phbkhost",
"ClusterIpAddresses": []
},
"PhbkPhoneViewExtForLkUpConf": {
"HostName": "192.168.100.3",
"Username": "admin",
"Password": "admin",
"VirtualHostName": "phbkhost",
"ClusterIpAddresses": []
}
- read the article first. (It gives an example configuration)
- Add the
IBusLpPhbkPhone.cs
-file in theMassTansitBuses
-folder of thePhBkControllers.csproj
-project with a code
- Add the
Click to show the code
using MassTransit;
namespace PhBkControllers.MassTansitBuses
{
public interface IBusLpPhbkPhone : IBus
{
}
}
- Back to the
Program.cs
file- we get the
PhbkPhoneViewExtForLkUpConf
-section fromappsettings.json
-file - using
PhbkPhoneViewExtForLkUpConf
-section we configure second instance of the MassTransit Service Bus-
builder.Services.AddMassTransit<IBusLpPhbkPhone>
-code declares the second copy of the Service Bus. -
x.AddRequestClient<IPhbkPhoneViewExtForLkUpMsg>();
-code registers second producer for the second copy of the Service Bus. -
configurator.ConfigureEndpoints(context);
- method call is NOT used.
-
- we get the
Click to show the code
#region MassTransit config
...
configuration.GetSection(PhbkPhoneViewExtForLkUpConf.ConfName).Bind(phbkPhoneViewExtForLkUpConf);
builder.Services.AddMassTransit<IBusLpPhbkPhone>(x => {
x.AddRequestClient<IPhbkPhoneViewExtForLkUpMsg>();
x.UsingRabbitMq((context, configurator) => {
configurator.Host(phbkPhoneViewExtForLkUpConf.HostName, phbkPhoneViewExtForLkUpConf.VirtualHostName, h => {
h.Username(phbkPhoneViewExtForLkUpConf.Username);
h.Password(phbkPhoneViewExtForLkUpConf.Password);
if (phbkPhoneViewExtForLkUpConf.ClusterIpAddresses != null)
{
if (phbkPhoneViewExtForLkUpConf.ClusterIpAddresses.Length > 0)
{
h.UseCluster((configureCluster) => {
for (int i = 0; i < phbkPhoneViewExtForLkUpConf.ClusterIpAddresses.Length; i++)
{
configureCluster.Node(phbkPhoneViewExtForLkUpConf.ClusterIpAddresses[i]);
}
});
}
}
// h.PublisherConfirmation = true;
// h.ConfigureBatchPublish(configure => { });
});
configurator.ConfigureEndpoints(context);
//
// Quorum Queue settings
//
// configurator.SetQuorumQueue(3);
//
});
});
#endregion