-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathAMQPChannelBinding.cs
More file actions
91 lines (78 loc) · 3.43 KB
/
Copy pathAMQPChannelBinding.cs
File metadata and controls
91 lines (78 loc) · 3.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
namespace ByteBard.AsyncAPI.Bindings.AMQP
{
using System;
using ByteBard.AsyncAPI.Models;
using ByteBard.AsyncAPI.Readers.ParseNodes;
using ByteBard.AsyncAPI.Writers;
/// <summary>
/// Binding class for AMQP channel settings.
/// </summary>
public class AMQPChannelBinding : ChannelBinding<AMQPChannelBinding>
{
/// <summary>
/// Defines what type of channel is it. Can be either queue or routingKey.
/// </summary>
public ChannelType Is { get; set; }
/// <summary>
/// When is=routingKey, this object defines the exchange properties.
/// </summary>
public Exchange Exchange { get; set; }
/// <summary>
/// When is=queue, this object defines the queue properties.
/// </summary>
public Queue Queue { get; set; }
public override string BindingKey => "amqp";
protected override FixedFieldMap<AMQPChannelBinding> FixedFieldMap => new()
{
{ "bindingVersion", (a, n) => { a.BindingVersion = n.GetScalarValue(); } },
{ "is", (a, n) => { a.Is = n.GetScalarValue().GetEnumFromDisplayName<ChannelType>(); } },
{ "exchange", (a, n) => { a.Exchange = n.ParseMap(ExchangeFixedFields); } },
{ "queue", (a, n) => { a.Queue = n.ParseMap(QueueFixedFields); } },
};
private static FixedFieldMap<Exchange> ExchangeFixedFields = new()
{
{ "name", (a, n) => { a.Name = n.GetScalarValue(); } },
{ "durable", (a, n) => { a.Durable = n.GetBooleanValue(); } },
{ "type", (a, n) => { a.Type = n.GetScalarValue().GetEnumFromDisplayName<ExchangeType>(); } },
{ "autoDelete", (a, n) => { a.AutoDelete = n.GetBooleanValue(); } },
{ "vhost", (a, n) => { a.Vhost = n.GetScalarValue(); } },
};
private static FixedFieldMap<Queue> QueueFixedFields = new()
{
{ "name", (a, n) => { a.Name = n.GetScalarValue(); } },
{ "durable", (a, n) => { a.Durable = n.GetBooleanValue(); } },
{ "exclusive", (a, n) => { a.Exclusive = n.GetBooleanValue(); } },
{ "autoDelete", (a, n) => { a.AutoDelete = n.GetBooleanValue(); } },
{ "vhost", (a, n) => { a.Vhost = n.GetScalarValue(); } },
};
public override void SerializeV2(IAsyncApiWriter writer)
{
this.SerializeV3(writer);
}
public override void SerializeV3(IAsyncApiWriter writer)
{
this.SerializeProperties(writer);
}
public override void SerializeProperties(IAsyncApiWriter writer)
{
if (writer is null)
{
throw new ArgumentNullException(nameof(writer));
}
writer.WriteStartObject();
writer.WriteRequiredProperty("is", this.Is.GetDisplayName());
switch (this.Is)
{
case ChannelType.RoutingKey:
writer.WriteOptionalObject("exchange", this.Exchange, (w, t) => t.Serialize(w));
break;
case ChannelType.Queue:
writer.WriteOptionalObject("queue", this.Queue, (w, t) => t.Serialize(w));
break;
}
writer.WriteOptionalProperty(AsyncApiConstants.BindingVersion, this.BindingVersion);
writer.WriteExtensions(this.Extensions);
writer.WriteEndObject();
}
}
}