082 Service bus Consumer for PhbkPhoneView - chempkovsky/CS82ANGULAR GitHub Wiki

Notes

  • 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.
  • Since we have two database contexts, PhbkDbContext and LpPhnPhBkContext, the question is which one to use to run the wizard script.
    • PhbkDbContext must be used to generate Lookup resource Service bus Consumer.

Steps required to accomplish the task

  • We do not describe step by step instructions
    • please repeat the steps similar to those described in the article 043
  • LpPhBkControllers is the destination project
    • Consumers is the destination folder
  • PhbkPhoneView is a View to generate the class
  • 01025-.masstransit.consumer.cs- is a script type
    • masstransit.consumer.cs.t4 is a t4 script
  • phbk-phone-view.masstransit.consumer.cs- file will be created

Open generated file

  • open phbk-phone-view.masstransit.consumer.cs-file
Click to show the picture

project structure

  • We need to make modifications of the phbk-phone-view.masstransit.consumer.cs-file
Find and replace
  • replace the using PhBkContext.PhBk;-line with the using LpPhBkContext.PhBk;

  • replace the PhbkDbContext db-code with the code LpPhnPhBkContext db in the phbk-phone-view.masstransit.consumer.cs-file

  • replace the PhbkDbContext dbcontext-code with the code LpPhnPhBkContext dbcontext in the phbk-phone-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 generate phbk-phone-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, LprPhone01, ..., LprPhone04 tables must have a foreign key, which references PhbkPhoneView-table. In addition LprPhone04 must have a foreign key, which references PhbkEmployeeView-table... In short, find and replace-approach is optimal.

Configuring MassTransit for an Application

  • open phbk-phone-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
  • read the article Configuring MassTransit for an Application to view the setup instruction code.
⚠️ **GitHub.com Fallback** ⚠️