简体   繁体   中英

Azure Service Bus Single Service having Multiple Topic and Subscriber

I have an Micro-Service which is a Consumer/Subscriber service, that receives messages from other 2 Services. So, I want this Micro-Service to Subscribe from the other 2 micro-services that have different Topic and Subscription. The constructing/Initializing the service/Azure Service Bus Properties is as below:

services.AddServiceBusNotifications(Configuration, "Communication");
 services.AddServiceBusNotifications(Configuration, "SSO");

And the code for Subscribing to this 2 services is as below:

var eventBus = applicationBuilder.ApplicationServices.GetRequiredService<IEventBus>(); 

eventBus.Subscribe<MeetinginviteCreatedEvent, MeetinginviteCreatedEventHandler>();

eventBus.Subscribe<NewUserCreatedEvent, NewUserCreatedEventHandler>(); 

So, both the above 2 lines are taking the settings(Topic/Subscription) from the same topic & Subscriber, but I want to take the Topic and Subscription for 2 different Microservices. How Can I use the Same Subscriber for Multiple Topic and Subscription(Different Microservices).

I have followed the code from the URL: https://github.com/pmchlk/service-bus-messaging

There is a lot going in the code that you've shared since you have a wrapper around the Azure Service Bus SDK but if my understanding of it is correct, one way to solve your issue is to simply forward messages from the individual subscriptions into another topic/subscription and use that in your service.

This would be simpler if it works like I expect it to, based on my understanding of your code.

The other options would be to either change your Dependency Injection code to register transient Event Bus objects instead of a singleton or update your Event Bus class to handle multiple subscriptions. Both of these would require quite a few changes in your custom implementation.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM