Browse Source

Revised part 07

pull/23128/head
Halil İbrahim Kalkan 11 months ago
parent
commit
668a4b5a32
  1. BIN
      docs/en/tutorials/modular-crm/images/abp-studio-imports-and-dependencies-v2.png
  2. BIN
      docs/en/tutorials/modular-crm/images/abp-studio-imports-and-dependencies.png
  3. BIN
      docs/en/tutorials/modular-crm/images/abp-studio-install-module-dialog-for-ordering-v2.png
  4. BIN
      docs/en/tutorials/modular-crm/images/abp-studio-install-module-dialog-for-ordering.png
  5. BIN
      docs/en/tutorials/modular-crm/images/visual-studio-order-event-handler-v2.png
  6. BIN
      docs/en/tutorials/modular-crm/images/visual-studio-order-event-handler.png
  7. 27
      docs/en/tutorials/modular-crm/part-07.md

BIN
docs/en/tutorials/modular-crm/images/abp-studio-imports-and-dependencies-v2.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 34 KiB

BIN
docs/en/tutorials/modular-crm/images/abp-studio-imports-and-dependencies.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 40 KiB

BIN
docs/en/tutorials/modular-crm/images/abp-studio-install-module-dialog-for-ordering-v2.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 57 KiB

BIN
docs/en/tutorials/modular-crm/images/abp-studio-install-module-dialog-for-ordering.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 78 KiB

BIN
docs/en/tutorials/modular-crm/images/visual-studio-order-event-handler-v2.png

Binary file not shown.

After

Width:  |  Height:  |  Size: 8.2 KiB

BIN
docs/en/tutorials/modular-crm/images/visual-studio-order-event-handler.png

Binary file not shown.

Before

Width:  |  Height:  |  Size: 30 KiB

27
docs/en/tutorials/modular-crm/part-07.md

@ -16,6 +16,8 @@
Another common approach to communicating between modules is messaging. By publishing and handling messages, a module can perform an operation when an event happens in another module.
## Understanding the Event Bus Types
ABP provides two types of event buses for loosely coupled communication:
* [Local Event Bus](../../framework/infrastructure/event-bus/local/index.md) is suitable for in-process messaging. Since in a modular monolith, both of publisher and subscriber are in the same process, they can communicate in-process, without needing an external message broker.
@ -51,30 +53,27 @@ public class OrderPlacedEto
}
````
`OrderPlacedEto` is very simple. It is a plain C# class used to transfer data related to the event (*ETO* is an acronym for *Event Transfer Object*, a suggested naming convention but not required). You can add more properties if needed, but for this tutorial, it is more than enough.
`OrderPlacedEto` is very simple. It is a plain C# class used to transfer data related to the event (*ETO* is an acronym for *Event Transfer Object*, a suggested naming convention by the ABP team, but not technically required). You can add more properties if needed, but for this tutorial, that is more than enough.
### Using the `IDistributedEventBus` Service
The `IDistributedEventBus` service publishes events to the event bus. Until this point, the Ordering module has no functionality to create new orders. Let's change that and place an order, for that purpose open the `ModularCrm.Ordering` module's .NET solution, and update the `OrderAppService` as follows:
The `IDistributedEventBus` service publishes events to the event bus. Open the `ModularCrm.Ordering` module's .NET solution, and update the `OrderAppService` as follows:
````csharp
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using ModularCrm.Ordering.Contracts.Enums;
using ModularCrm.Ordering.Events;
using ModularCrm.Ordering.Entities;
using ModularCrm.Products.Integration;
using Volo.Abp.Domain.Repositories;
using Volo.Abp.EventBus.Distributed;
using ModularCrm.Ordering.Contracts.Services;
namespace ModularCrm.Ordering.Services;
public class OrderAppService : OrderingAppService, IOrderAppService
{
private readonly IRepository<Order, Guid> _orderRepository;
private readonly IRepository<Order, Guid> _orderRepository;
private readonly IProductIntegrationService _productIntegrationService;
private readonly IDistributedEventBus _distributedEventBus;
@ -132,7 +131,7 @@ public class OrderAppService : OrderingAppService, IOrderAppService
}
````
The `OrderAppService.CreateAsync` method creates a new `Order` entity, saves it to the database and finally publishes an `OrderPlacedEto` event.
We've changed the `CreateAsync` method. Now it creates a new `Order` entity, saves it to the database and finally publishes an `OrderPlacedEto` event.
## Subscribing to an Event
@ -152,13 +151,13 @@ In the opening dialog, find and select the `ModularCrm.Ordering` module, check t
Once you click the OK button, the Ordering module is imported to the Catalog module, and an installation dialog is open:
![abp-studio-install-module-dialog-for-ordering](images/abp-studio-install-module-dialog-for-ordering.png)
![abp-studio-install-module-dialog-for-ordering](images/abp-studio-install-module-dialog-for-ordering-v2.png)
Here, select the `ModularCrm.Ordering.Contracts` package on the left side (because we want to add that package reference) and `ModularCrm.Catalog` package on the middle area (because we want to add the package reference to that project). Also, select the `ModularCrm.Ordering` package on the right side, and unselect all packages on the middle area (we don't need the implementation or any other packages). Then, click the OK button to finish the installation operation.
You can check the ABP Studio's *Solution Explorer* panel to see the module import and the project reference (dependency).
![abp-studio-imports-and-dependencies](images/abp-studio-imports-and-dependencies.png)
![abp-studio-imports-and-dependencies](images/abp-studio-imports-and-dependencies-v2.png)
### Handling the `OrderPlacedEto` Event
@ -166,7 +165,7 @@ Now, it is possible to use the `OrderPlacedEto` class inside the Catalog module
Open the Catalog module's .NET solution in your IDE, locate the `ModularCrm.Catalog` project, and create a new `Orders` folder and an `OrderEventHandler` class inside that folder. The final folder structure should be like this:
![visual-studio-order-event-handler](images/visual-studio-order-event-handler.png)
![visual-studio-order-event-handler](images/visual-studio-order-event-handler-v2.png)
Replace the `OrderEventHandler.cs` file's content with the following code block:
@ -214,7 +213,7 @@ public class OrderEventHandler :
We inject the product repository and update the stock count in the event handler method (`HandleEventAsync`). That's it.
### Testing the Order Creation
## Testing the Order Creation
To keep this tutorial more focused, we will not create a UI for creating an order. You can easily create a form to create an order on your user interface. In this section, we will test it just using the Swagger UI.
@ -233,7 +232,7 @@ Find the *Orders* API, click the *Try it out* button, enter a sample value the t
}
````
> **IMPORTANT:** Here, you should type a valid Product Id from the Products table of your database!
> **IMPORTANT:** Here, you should type a valid product Id from the *CatalogProducts* table of your database!
Once you press the *Execute* button, a new order is created. At that point, you can check the `/Orders` page to see if the new order is shown on the UI, and check the `/Products` page to see if the related product's stock count has decreased.
@ -242,3 +241,7 @@ Here are sample screenshots from the Products and Orders pages:
![products-orders-pages-crop](images/products-orders-pages-crop.png)
We placed a new order for Product C. As a result, Product C's stock count has decreased from 55 to 54 and a new line is added to the Orders page.
## Conclusion
In this part, we've used ABP's distributed event bus to perform loosely coupled messaging between the modules. In the [next part](part-08.md), we will execute a database query that includes product and order data as an alternative way of integrating modules' data.

Loading…
Cancel
Save