The code to select the queue is hard coupled with the type of message.
We can use a list of Scopes (aka Model name) where we can define the consumer and subscriber queue names
-return (typeof(TMessage) == typeof(IntegrationMessage)
- ? _settings.Consumer?.IntegrationQueue
- : _settings.Consumer?.DomainQueue)
- ?? throw new ArgumentException("please configure the queues on the appsettings");
+var scope = typeof(IntegrationMessage).Name.ToString();
+var queueSettings = _settings.Queues.FirstOrDefault(q => q.Scope == scope);
+return queueSettings?.Consumer
+ ?? throw new ArgumentException("please configure the queues on the appsettings");
For this, we need to change the AppSettings.json file
"RabbitMQ": {
- "Publisher": {
- "IntegrationExchange": "api.public.exchange"
- }
+ "Queues": [
+ {
+ "Scope": "IntegrationMessage",
+ "Publisher": "api.public.exchange"
+ }
+ ]
}
What do you think?
The code to select the queue is hard coupled with the type of message.
We can use a list of Scopes (aka Model name) where we can define the consumer and subscriber queue names
For this, we need to change the AppSettings.json file
"RabbitMQ": { - "Publisher": { - "IntegrationExchange": "api.public.exchange" - } + "Queues": [ + { + "Scope": "IntegrationMessage", + "Publisher": "api.public.exchange" + } + ] }What do you think?