In this article, we will build a basic real-time messaging application in a distributed architecture. We will use Abp Framework for infrastructure and tiered startup template, SignalR for real-time server-client communication and RabbitMQ as the distributed event bus.

When Web & API tiers are separated, it is impossible to directly send a server-to-client message from the HTTP API. This is also true for a microservice architected application. We suggest using the distributed event bus to deliver the message from API application to the web application, then to the client.

Diagram1.png

Above, you can see the data-flow that we will implement in this article. This diagram represents how data will flow in our application when Client 1 sends a message to Client 2. It is explained in 5 steps:

  1. Client 1 sends a message data to Web Application via a REST call.
  2. Web Application redirects the message data to Http Api.
  3. The message data is processed in Http Api and Http Api publishes an event that holds the data that will be sent to Client 2.
  4. Web application, that is subscribed to that event, receives it.
  5. Web Application sends the message to Client 2.

For this example flow, we could send a message from Client 1 to Client 2 directly on the SignalR Hub. However, what we are trying here to demonstrate is sending a real-time message from the Http Api to a specific user who is connected to the web application.

Implementation

Startup template and the initial run

Abp Framework offers startup templates to get into the business faster. We can download a new tiered startup template using Abp CLI:

abp new SignalRTieredDemo --tiered

After the download is finished, we run *.DbMigrator project to c