Bus : How Basic Routing Config Works

BasicCRUD Insert Query with Bridge

Now let us see how the bus works. Let us go back to our solution, the first thing that we need to observe here is our bus configuration right now by default. We are giving the service bus configuration and soon we will be ready with the mass transit and the bus, you can choose during your application creation. If we see here, we have the perch gamma service Quest breach that is the core bus instance that is available to you and we have assumed bus configuration learning, bus configuration on-premise and bus configuration. By default you have the learning bus configuration available with you so you can configure your own stuff as per the guidelines. Then the next important step is the endpoint, so each endpoint as it's unique name now my web API endpoint as an end point dot web API, so the q's get generated in the same name and then we have the Handler API. Here we have the Handler, so what happens is when in the API you post a message, the command is created and this put’s in the bus. How will we identify where to go? So that setting happens here as destination endpoint, I am giving what I'm saying in the bus route configuration. Here we have got one command created and all the code is generated, So when you generate your first hyrlas, because all our models for the messages are available only in the demo dot messages, so we can pick up any command now and configure the route.

private void ConfigureBusServices(IServiceCollection services)
        {
            List<BusRouteConfig> routes = new List<BusRouteConfig>();

            //TODO: Set the default destination address
            string defaultDestinationEndPoint = "ECommerceDemo-EndPoint-Handlers";

            //TODO: Uncomment this line of code and Configure your route
            routes.Add(new BusRouteConfig(typeof(AddCustomerCommand).Assembly, defaultDestinationEndPoint));
        }

We just need the assembly for convenience, we will take the command and then using namespace. So the assembly that the command belongs and any messages from this assembly will be routed to the Handler endpoint, which the endpoint is running all the handlers. Same thing for our Handler, We don't do anything because there is no routing happening. It is not mixed but only receiving the command by default and it is not publishing any command from there, if you want to publish any command you gave more importance then you can configure here also.

private static void ConfigureBusServices(IServiceCollection services, HostBuilderContext hostContext)
        {
            List<BusRouteConfig> routes = new List<BusRouteConfig>();

            //TODO: Set the default destination address
            string defaultDestinationEndPoint = "ECommerceDemo-EndPoint-Handlers";

            //TODO: Uncomment this line of code and Configure your route
            //NOT REQUIRED FOR HANDLER IN OUR CASE
            //routes.Add(new BusRouteConfig(typeof(OneOfYourCommand).Assembly, defaultDestinationEndPoint));
        }

Now we have the subscriber. So what we are telling in the subscriber is to listen to The Handler endpoint, so what happens is any endless subscribers will be raising the events. So whenever the Handler is raising an event, the subscriber will listen to that event by default.

private static void ConfigureBusServices(IServiceCollection services, HostBuilderContext hostContext)
        {
            List<BusRouteConfig> routes = new List<BusRouteConfig>();

            //TODO: Set the default destination address
            string defaultDestinationEndPoint = "ECommerceDemo-EndPoint-Handlers";

            //TODO: Uncomment this line of code and Configure your route
            routes.Add(new BusRouteConfig(typeof(CustomerAdded).Assembly, defaultDestinationEndPoint));
        }

So that is where we are telling, your destination end point is the Handler, same concept is a forwarding thing and now it is also a subscriber here, and we can change the route. For convenience now we won’t take a command. Let's take some events instead. They are all the same customer added because ultimately assembly is only by customer event.

Last updated