|
| 1 | +// Copyright (c) The LEGO Group. All rights reserved. |
| 2 | + |
| 3 | +namespace LEGO.AsyncAPI.Bindings.AMQP |
| 4 | +{ |
| 5 | + using System; |
| 6 | + using System.Collections.Generic; |
| 7 | + using LEGO.AsyncAPI.Models; |
| 8 | + using LEGO.AsyncAPI.Readers; |
| 9 | + using LEGO.AsyncAPI.Readers.ParseNodes; |
| 10 | + using LEGO.AsyncAPI.Writers; |
| 11 | + |
| 12 | + /// <summary> |
| 13 | + /// Binding class for AMQP operations. |
| 14 | + /// </summary> |
| 15 | + public class AMQPOperationBinding : OperationBinding<AMQPOperationBinding> |
| 16 | + { |
| 17 | + /// <summary> |
| 18 | + /// TTL (Time-To-Live) for the message. It MUST be greater than or equal to zero. |
| 19 | + /// </summary> |
| 20 | + public uint? Expiration { get; set; } |
| 21 | + |
| 22 | + /// <summary> |
| 23 | + /// Identifies the user who has sent the message. |
| 24 | + /// </summary> |
| 25 | + public string UserId { get; set; } |
| 26 | + |
| 27 | + /// <summary> |
| 28 | + /// The routing keys the message should be routed to at the time of publishing. |
| 29 | + /// </summary> |
| 30 | + public List<string> Cc { get; set; } = new List<string>(); |
| 31 | + |
| 32 | + /// <summary> |
| 33 | + /// A priority for the message. |
| 34 | + /// </summary> |
| 35 | + public int? Priority { get; set; } |
| 36 | + |
| 37 | + /// <summary> |
| 38 | + /// Delivery mode of the message. Its value MUST be either 1 (transient) or 2 (persistent). |
| 39 | + /// </summary> |
| 40 | + public DeliveryMode? DeliveryMode { get; set; } |
| 41 | + |
| 42 | + /// <summary> |
| 43 | + /// Whether the message is mandatory or not. |
| 44 | + /// </summary> |
| 45 | + public bool? Mandatory { get; set; } |
| 46 | + |
| 47 | + /// <summary> |
| 48 | + /// Like cc but consumers will not receive this information. |
| 49 | + /// </summary> |
| 50 | + public List<string> Bcc { get; set; } = new List<string>(); |
| 51 | + |
| 52 | + /// <summary> |
| 53 | + /// Whether the message should include a timestamp or not. |
| 54 | + /// </summary> |
| 55 | + public bool? Timestamp { get; set; } |
| 56 | + |
| 57 | + /// <summary> |
| 58 | + /// Whether the consumer should ack the message or not. |
| 59 | + /// </summary> |
| 60 | + public bool? Ack { get; set; } |
| 61 | + |
| 62 | + public override string BindingKey => "amqp"; |
| 63 | + |
| 64 | + protected override FixedFieldMap<AMQPOperationBinding> FixedFieldMap => new() |
| 65 | + { |
| 66 | + { "bindingVersion", (a, n) => { a.BindingVersion = n.GetScalarValue(); } }, |
| 67 | + { "expiration", (a, n) => { a.Expiration = (uint?)n.GetIntegerValueOrDefault(); } }, |
| 68 | + { "userId", (a, n) => { a.UserId = n.GetScalarValueOrDefault(); } }, |
| 69 | + { "cc", (a, n) => { a.Cc = n.CreateSimpleList(s => s.GetScalarValue()); } }, |
| 70 | + { "priority", (a, n) => { a.Priority = n.GetIntegerValueOrDefault(); } }, |
| 71 | + { "deliveryMode", (a, n) => { a.DeliveryMode = (DeliveryMode?)n.GetIntegerValueOrDefault(); } }, |
| 72 | + { "mandatory", (a, n) => { a.Mandatory = n.GetBooleanValueOrDefault(); } }, |
| 73 | + { "bcc", (a, n) => { a.Bcc = n.CreateSimpleList(s => s.GetScalarValue()); } }, |
| 74 | + { "timestamp", (a, n) => { a.Timestamp = n.GetBooleanValueOrDefault(); } }, |
| 75 | + { "ack", (a, n) => { a.Ack = n.GetBooleanValueOrDefault(); } }, |
| 76 | + }; |
| 77 | + |
| 78 | + /// <summary> |
| 79 | + /// Serialize to AsyncAPI V2 document without using reference. |
| 80 | + /// </summary> |
| 81 | + public override void SerializeProperties(IAsyncApiWriter writer) |
| 82 | + { |
| 83 | + if (writer is null) |
| 84 | + { |
| 85 | + throw new ArgumentNullException(nameof(writer)); |
| 86 | + } |
| 87 | + |
| 88 | + writer.WriteStartObject(); |
| 89 | + writer.WriteOptionalProperty<int>("expiration", (int)this.Expiration); |
| 90 | + writer.WriteOptionalProperty("userId", this.UserId); |
| 91 | + writer.WriteOptionalCollection("cc", this.Cc, (w, s) => w.WriteValue(s)); |
| 92 | + writer.WriteOptionalProperty("priority", this.Priority); |
| 93 | + writer.WriteOptionalProperty("deliveryMode", (int?)this.DeliveryMode); |
| 94 | + writer.WriteOptionalProperty("mandatory", this.Mandatory); |
| 95 | + writer.WriteOptionalCollection("bcc", this.Bcc, (w, s) => w.WriteValue(s)); |
| 96 | + writer.WriteOptionalProperty("timestamp", this.Timestamp); |
| 97 | + writer.WriteOptionalProperty("ack", this.Ack); |
| 98 | + writer.WriteOptionalProperty(AsyncApiConstants.BindingVersion, this.BindingVersion); |
| 99 | + writer.WriteExtensions(this.Extensions); |
| 100 | + writer.WriteEndObject(); |
| 101 | + } |
| 102 | + } |
| 103 | +} |
0 commit comments