039 New Version of Web Api service for PhbkDivisionView - chempkovsky/CS82ANGULAR GitHub Wiki

Notes

  • Everything is ready to create a new version of the Web Api service for PhbkDivisionView.
    • According to the requirements 033 Lookup resource should be updated automatically in async mode. Thus, the new version of the PhbkDivisionView Web Api service additionally needs to send data to the Service Bus.

Steps required to accomplish the task

  • please repeat all the steps of the article 030 until fourth page of the Wizard.

Fourth page of the Wizard

  • On the Fourth page of the Wizard we choose DefaultWebApiServiceWithMassTransit.Core.cs.t4 T4-template to generate the code. Click Next-button.

Fifth page of the Wizard

  • repeat the steps described in the article

The PhbkDivisionViewWebApiController.cs will be recreated in the Controllers-folder of the PhBkWebApp.csproj-project

Open PhbkDivisionViewWebApiController file

  • Open PhbkDivisionViewWebApiController.cs-file.
    • At the beginning of the file you will find instructions for setting up communication with the bus.
      • including clusters
      • including Quorum Queues
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.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);
        //
    });
});
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
*/
...
  • add, update, delete methods of the Web Api service make a await pe.Publish<IPhbkDivisionViewExtForLkUpMsg>(new...) call before return.

RabbitMq notes

  • By default MassTransit automatically creates Exchange, Queue and Binding. So the only thing you have to worry about is different C# interface names for different queues. It means that we have distinct Queues for distinct Lookup recourses. You should be aware that sometimes it is better to use the same queue for different Lookup recourses. Please read the article, to clarify the issue.
⚠️ **GitHub.com Fallback** ⚠️