Distribt
Distribt copied to clipboard
Add new MessageModels easily
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?
huummm for me it looks more confusing, at least the first draft, in the first implementation
"RabbitMQ": {
"Publisher": {
"IntegrationExchange": "api.public.exchange"
}
Just by looking at it, i know that the service where this is configured it is publishing integration messages to that queue (and if I am not mistaken, there can be multiple, comma separated ones)
while this:
"RabbitMQ": {
"Hostname" : "localhost",
"Consumer": {
"DomainQueue" : "order-domain-queue",
"IntegrationQueue": "order-queue"
}
}
will consume integration and domain messages from those queues.
I think the issue here is the terminology, not sure if you used RabbitMQ before but you cannot publish directly into a queue, so it goes to an exange and fromt there the message goes to other exanges or queues.
So the array for queues is not correct, at least on the publisher side, as there is no queue context on it.
then the "publisher" one you mentioned, needs to be changed to exange
but maybe something like
rabbitmq: {
publishers: [{
"scope" : "integration",
"exange" : "api.public.exange"
}],
consumers: [{
"scope" : "integration",
"queue" : "order-queue"
}]
}
as I agree that it looks more clear this way.