| | 1 | | using RabbitMQ.Client; |
| | 2 | | using Saunter.AsyncApiSchema.v2; |
| | 3 | | using Saunter.Utils; |
| | 4 | |
|
| | 5 | | namespace Gateway.Apis.Amqp.RegistrationExtensions; |
| | 6 | |
|
| | 7 | | public static class AsyncApiConsumerFactoryBag |
| | 8 | | { |
| 0 | 9 | | private static readonly Queue<Action<IModel, IServiceProvider>> DocumentationActions = new(); |
| | 10 | |
|
| | 11 | | public static void AddQueueConsumer<TMessage>(VersionState versionState) |
| | 12 | | { |
| 0 | 13 | | string queueName = $"{versionState.Version:'v'VVV}/{typeof(TMessage).Name}"; |
| 0 | 14 | | DocumentationActions.Enqueue( |
| 0 | 15 | | (model, sp) => |
| 0 | 16 | | { |
| 0 | 17 | | QueueConsumerFactory.CreateQueueConsumer<TMessage>(sp, model, queueName); |
| 0 | 18 | | } |
| 0 | 19 | | ); |
| 0 | 20 | | AsyncApiDocumentationGenerationBag.AddDocumentation(x => |
| 0 | 21 | | { |
| 0 | 22 | | x.AsyncApi.Channels.AddOrAppend( |
| 0 | 23 | | queueName, |
| 0 | 24 | | new Saunter.AsyncApiSchema.v2.ChannelItem() |
| 0 | 25 | | { |
| 0 | 26 | | Subscribe = new Saunter.AsyncApiSchema.v2.Operation() { }, |
| 0 | 27 | | Publish = new Operation() { Message = new Message() } |
| 0 | 28 | | } |
| 0 | 29 | | ); |
| 0 | 30 | | }); |
| 0 | 31 | | } |
| | 32 | |
|
| | 33 | | public static void CreateConsumers(IModel model, IServiceProvider serviceProvider) |
| | 34 | | { |
| 0 | 35 | | while (DocumentationActions.Count > 0) |
| | 36 | | { |
| 0 | 37 | | var consumerFactory = DocumentationActions.Dequeue(); |
| 0 | 38 | | consumerFactory(model, serviceProvider); |
| | 39 | | } |
| 0 | 40 | | } |
| | 41 | | } |