Publish message to topics and subscribe to other topics within the same service

60 views
Skip to first unread message

simon_ore

unread,
May 16, 2021, 3:04:24 PM5/16/21
to masstransit-discuss
Hi guys,
I am new to MassTransit and messaging so bear me any stupid question. 
I am using Masstransit with Azure service bus and .Net core web api. I am able to configure my bus to publish message to a topic, I am able able to configure masstransit to only receive message from subscriptions. But I am having issues if I am want to configure the Bus to publish message and listen to the subsciptions published by other topics
 here is my configuration, please help

        public static void ConfigureBus(this IServiceCollection services)
        {
            string connectstr = "Endpoint=sb://...";
            string pubtopic = "balance";
            string subtopic = "playmat";
            string subscription = "playmat.listener";

            var azureServiceBus = Bus.Factory.CreateUsingAzureServiceBus(busconfig =>
            {
                // I intend to use this for publish message
                busconfig.Message<Balance>(configTopology =>
                {
                    configTopology.SetEntityName(pubtopic);
                });
                busconfig.Host(connectstr);

                //consume subscriptions from other topics 
                busconfig.SubscriptionEndpoint(subscription, subtopic, configurator =>
                {
                    configurator.Consumer<TransferConsumer>();
                });
            });

            // Add MassTransit
            services.AddMassTransit(config =>
            {
                config.AddBus(provider => azureServiceBus);
            });

            services.AddSingleton<IHostedService, BusHostedService>();
            services.AddSingleton<IPublishEndpoint>(azureServiceBus);
            services.AddSingleton<IBus>(azureServiceBus);
        }

thanks 
Simon

Chris Patterson

unread,
May 17, 2021, 8:40:43 AM5/17/21
to masstrans...@googlegroups.com
I'd suggest you look at current examples, as creating the bus separately and then using AddBus is just wrong. Also, use the MassTransit.AspNetCore package which includes the MassTransitHostedService, and properly configures your container. 

Also, I'd suggest using one of the recommended support platforms: https://masstransit-project.com/learn/

Good luck.


--
You received this message because you are subscribed to the Google Groups "masstransit-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to masstransit-dis...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/masstransit-discuss/58a91be4-7452-4a1f-9265-f87da2e8378an%40googlegroups.com.

simon_ore

unread,
May 18, 2021, 9:32:16 AM5/18/21
to masstransit-discuss
Hi Chris,
Thanks for the help, the documentation is clear on this, I was rather looking into some outdated tutorials. I can see MassTransit is growing very fast, you guys are doing a great job, congratulations.
thanks
Reply all
Reply to author
Forward
0 new messages