This repository has been archived by the owner on Oct 12, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 118
/
Copy pathAmqpMessageConverter.cs
697 lines (618 loc) · 28.2 KB
/
AmqpMessageConverter.cs
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
// Copyright (c) Microsoft. All rights reserved.
// Licensed under the MIT license. See LICENSE file in the project root for full license information.
namespace Microsoft.Azure.ServiceBus.Amqp
{
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Runtime.Serialization;
using Azure.Amqp;
using Azure.Amqp.Encoding;
using Azure.Amqp.Framing;
using Framing;
using Primitives;
using SBMessage = Message;
static class AmqpMessageConverter
{
const string EnqueuedTimeUtcName = "x-opt-enqueued-time";
const string ScheduledEnqueueTimeUtcName = "x-opt-scheduled-enqueue-time";
const string SequenceNumberName = "x-opt-sequence-number";
const string EnqueueSequenceNumberName = "x-opt-enqueue-sequence-number";
const string LockedUntilName = "x-opt-locked-until";
const string PublisherName = "x-opt-publisher";
const string PartitionKeyName = "x-opt-partition-key";
const string PartitionIdName = "x-opt-partition-id";
const string ViaPartitionKeyName = "x-opt-via-partition-key";
const string DeadLetterSourceName = "x-opt-deadletter-source";
const string TimeSpanName = AmqpConstants.Vendor + ":timespan";
const string UriName = AmqpConstants.Vendor + ":uri";
const string DateTimeOffsetName = AmqpConstants.Vendor + ":datetime-offset";
const int GuidSize = 16;
public static AmqpMessage BatchSBMessagesAsAmqpMessage(IEnumerable<SBMessage> sbMessages)
{
if (sbMessages == null)
{
throw Fx.Exception.ArgumentNull(nameof(sbMessages));
}
AmqpMessage amqpMessage;
AmqpMessage firstAmqpMessage = null;
SBMessage firstMessage = null;
List<Data> dataList = null;
var messageCount = 0;
foreach (var sbMessage in sbMessages)
{
messageCount++;
amqpMessage = AmqpMessageConverter.SBMessageToAmqpMessage(sbMessage);
if (firstAmqpMessage == null)
{
firstAmqpMessage = amqpMessage;
firstMessage = sbMessage;
continue;
}
if (dataList == null)
{
dataList = new List<Data> { ToData(firstAmqpMessage) };
}
dataList.Add(ToData(amqpMessage));
}
if (messageCount == 1 && firstAmqpMessage != null)
{
firstAmqpMessage.Batchable = true;
return firstAmqpMessage;
}
amqpMessage = AmqpMessage.Create(dataList);
amqpMessage.MessageFormat = AmqpConstants.AmqpBatchedMessageFormat;
if (firstMessage.MessageId != null)
{
amqpMessage.Properties.MessageId = firstMessage.MessageId;
}
if (firstMessage.SessionId != null)
{
amqpMessage.Properties.GroupId = firstMessage.SessionId;
}
if (firstMessage.PartitionKey != null)
{
amqpMessage.MessageAnnotations.Map[AmqpMessageConverter.PartitionKeyName] =
firstMessage.PartitionKey;
}
if (firstMessage.ViaPartitionKey != null)
{
amqpMessage.MessageAnnotations.Map[AmqpMessageConverter.ViaPartitionKeyName] =
firstMessage.ViaPartitionKey;
}
amqpMessage.Batchable = true;
return amqpMessage;
}
public static AmqpMessage SBMessageToAmqpMessage(SBMessage sbMessage)
{
var amqpMessage = sbMessage.Body == null ? AmqpMessage.Create() : AmqpMessage.Create(new Data { Value = new ArraySegment<byte>(sbMessage.Body) });
amqpMessage.Properties.MessageId = sbMessage.MessageId;
amqpMessage.Properties.CorrelationId = sbMessage.CorrelationId;
amqpMessage.Properties.ContentType = sbMessage.ContentType;
amqpMessage.Properties.Subject = sbMessage.Label;
amqpMessage.Properties.To = sbMessage.To;
amqpMessage.Properties.ReplyTo = sbMessage.ReplyTo;
amqpMessage.Properties.GroupId = sbMessage.SessionId;
amqpMessage.Properties.ReplyToGroupId = sbMessage.ReplyToSessionId;
if (sbMessage.TimeToLive != TimeSpan.MaxValue)
{
amqpMessage.Header.Ttl = (uint)sbMessage.TimeToLive.TotalMilliseconds;
amqpMessage.Properties.CreationTime = DateTime.UtcNow;
if (AmqpConstants.MaxAbsoluteExpiryTime - amqpMessage.Properties.CreationTime.Value > sbMessage.TimeToLive)
{
amqpMessage.Properties.AbsoluteExpiryTime = amqpMessage.Properties.CreationTime.Value + sbMessage.TimeToLive;
}
else
{
amqpMessage.Properties.AbsoluteExpiryTime = AmqpConstants.MaxAbsoluteExpiryTime;
}
}
if ((sbMessage.ScheduledEnqueueTimeUtc != null) && sbMessage.ScheduledEnqueueTimeUtc > DateTime.MinValue)
{
amqpMessage.MessageAnnotations.Map.Add(ScheduledEnqueueTimeUtcName, sbMessage.ScheduledEnqueueTimeUtc);
}
if (sbMessage.PartitionKey != null)
{
amqpMessage.MessageAnnotations.Map.Add(PartitionKeyName, sbMessage.PartitionKey);
}
if (sbMessage.ViaPartitionKey != null)
{
amqpMessage.MessageAnnotations.Map.Add(ViaPartitionKeyName, sbMessage.ViaPartitionKey);
}
if (sbMessage.UserProperties != null && sbMessage.UserProperties.Count > 0)
{
if (amqpMessage.ApplicationProperties == null)
{
amqpMessage.ApplicationProperties = new ApplicationProperties();
}
foreach (var pair in sbMessage.UserProperties)
{
if (TryGetAmqpObjectFromNetObject(pair.Value, MappingType.ApplicationProperty, out var amqpObject))
{
amqpMessage.ApplicationProperties.Map.Add(pair.Key, amqpObject);
}
else
{
throw new NotSupportedException(Resources.InvalidAmqpMessageProperty.FormatForUser(pair.Key.GetType()));
}
}
}
return amqpMessage;
}
public static SBMessage AmqpMessageToSBMessage(AmqpMessage amqpMessage, bool isPeeked = false)
{
if (amqpMessage == null)
{
throw Fx.Exception.ArgumentNull(nameof(amqpMessage));
}
SBMessage sbMessage;
if ((amqpMessage.BodyType & SectionFlag.AmqpValue) != 0
&& amqpMessage.ValueBody.Value != null)
{
sbMessage = new SBMessage();
if (TryGetNetObjectFromAmqpObject(amqpMessage.ValueBody.Value, MappingType.MessageBody, out var dotNetObject))
{
sbMessage.SystemProperties.BodyObject = dotNetObject;
}
else
{
sbMessage.SystemProperties.BodyObject = amqpMessage.ValueBody.Value;
}
}
else if ((amqpMessage.BodyType & SectionFlag.Data) != 0
&& amqpMessage.DataBody != null)
{
var dataSegments = new List<byte>();
foreach (var data in amqpMessage.DataBody)
{
if (data.Value is byte[] byteArrayValue)
{
dataSegments.AddRange(byteArrayValue);
}
else if (data.Value is ArraySegment<byte> arraySegmentValue)
{
byte[] byteArray;
if (arraySegmentValue.Count == arraySegmentValue.Array.Length)
{
byteArray = arraySegmentValue.Array;
}
else
{
byteArray = new byte[arraySegmentValue.Count];
Array.ConstrainedCopy(arraySegmentValue.Array, arraySegmentValue.Offset, byteArray, 0, arraySegmentValue.Count);
}
dataSegments.AddRange(byteArray);
}
}
sbMessage = new SBMessage(dataSegments.ToArray());
}
else
{
sbMessage = new SBMessage();
}
var sections = amqpMessage.Sections;
if ((sections & SectionFlag.Header) != 0)
{
if (amqpMessage.Header.Ttl != null)
{
sbMessage.TimeToLive = TimeSpan.FromMilliseconds(amqpMessage.Header.Ttl.Value);
}
if (amqpMessage.Header.DeliveryCount != null)
{
sbMessage.SystemProperties.DeliveryCount = isPeeked ? (int)(amqpMessage.Header.DeliveryCount.Value) : (int)(amqpMessage.Header.DeliveryCount.Value + 1);
}
}
if ((sections & SectionFlag.Properties) != 0)
{
if (amqpMessage.Properties.MessageId != null)
{
sbMessage.MessageId = amqpMessage.Properties.MessageId.ToString();
}
if (amqpMessage.Properties.CorrelationId != null)
{
sbMessage.CorrelationId = amqpMessage.Properties.CorrelationId.ToString();
}
if (amqpMessage.Properties.ContentType.Value != null)
{
sbMessage.ContentType = amqpMessage.Properties.ContentType.Value;
}
if (amqpMessage.Properties.Subject != null)
{
sbMessage.Label = amqpMessage.Properties.Subject;
}
if (amqpMessage.Properties.To != null)
{
sbMessage.To = amqpMessage.Properties.To.ToString();
}
if (amqpMessage.Properties.ReplyTo != null)
{
sbMessage.ReplyTo = amqpMessage.Properties.ReplyTo.ToString();
}
if (amqpMessage.Properties.GroupId != null)
{
sbMessage.SessionId = amqpMessage.Properties.GroupId;
}
if (amqpMessage.Properties.ReplyToGroupId != null)
{
sbMessage.ReplyToSessionId = amqpMessage.Properties.ReplyToGroupId;
}
}
// Do application properties before message annotations, because the application properties
// can be updated by entries from message annotation.
if ((sections & SectionFlag.ApplicationProperties) != 0)
{
foreach (var pair in amqpMessage.ApplicationProperties.Map)
{
if (TryGetNetObjectFromAmqpObject(pair.Value, MappingType.ApplicationProperty, out var netObject))
{
sbMessage.UserProperties[pair.Key.ToString()] = netObject;
}
}
}
if ((sections & SectionFlag.MessageAnnotations) != 0)
{
foreach (var pair in amqpMessage.MessageAnnotations.Map)
{
var key = pair.Key.ToString();
switch (key)
{
case EnqueuedTimeUtcName:
sbMessage.SystemProperties.EnqueuedTimeUtc = (DateTime)pair.Value;
break;
case ScheduledEnqueueTimeUtcName:
sbMessage.ScheduledEnqueueTimeUtc = (DateTime)pair.Value;
break;
case SequenceNumberName:
sbMessage.SystemProperties.SequenceNumber = (long)pair.Value;
break;
case EnqueueSequenceNumberName:
sbMessage.SystemProperties.EnqueuedSequenceNumber = (long)pair.Value;
break;
case LockedUntilName:
sbMessage.SystemProperties.LockedUntilUtc = (DateTime)pair.Value;
break;
case PartitionKeyName:
sbMessage.PartitionKey = (string)pair.Value;
break;
case PartitionIdName:
sbMessage.SystemProperties.PartitionId = (short)pair.Value;
break;
case ViaPartitionKeyName:
sbMessage.ViaPartitionKey = (string)pair.Value;
break;
case DeadLetterSourceName:
sbMessage.SystemProperties.DeadLetterSource = (string)pair.Value;
break;
default:
if (TryGetNetObjectFromAmqpObject(pair.Value, MappingType.ApplicationProperty, out var netObject))
{
sbMessage.UserProperties[key] = netObject;
}
break;
}
}
}
if (amqpMessage.DeliveryTag.Count == GuidSize)
{
var guidBuffer = new byte[GuidSize];
Buffer.BlockCopy(amqpMessage.DeliveryTag.Array, amqpMessage.DeliveryTag.Offset, guidBuffer, 0, GuidSize);
sbMessage.SystemProperties.LockTokenGuid = new Guid(guidBuffer);
}
amqpMessage.Dispose();
return sbMessage;
}
public static AmqpMap GetRuleDescriptionMap(RuleDescription description)
{
var ruleDescriptionMap = new AmqpMap();
switch (description.Filter)
{
case SqlFilter sqlFilter:
var filterMap = GetSqlFilterMap(sqlFilter);
ruleDescriptionMap[ManagementConstants.Properties.SqlFilter] = filterMap;
break;
case CorrelationFilter correlationFilter:
var correlationFilterMap = GetCorrelationFilterMap(correlationFilter);
ruleDescriptionMap[ManagementConstants.Properties.CorrelationFilter] = correlationFilterMap;
break;
default:
throw new NotSupportedException(
Resources.RuleFilterNotSupported.FormatForUser(
description.Filter.GetType(),
nameof(SqlFilter),
nameof(CorrelationFilter)));
}
var amqpAction = GetRuleActionMap(description.Action as SqlRuleAction);
ruleDescriptionMap[ManagementConstants.Properties.SqlRuleAction] = amqpAction;
ruleDescriptionMap[ManagementConstants.Properties.RuleName] = description.Name;
return ruleDescriptionMap;
}
public static RuleDescription GetRuleDescription(AmqpRuleDescriptionCodec amqpDescription)
{
var filter = GetFilter(amqpDescription.Filter);
var ruleAction = GetRuleAction(amqpDescription.Action);
var ruleDescription = new RuleDescription(amqpDescription.RuleName, filter)
{
Action = ruleAction
};
return ruleDescription;
}
public static Filter GetFilter(AmqpFilterCodec amqpFilter)
{
Filter filter;
switch (amqpFilter.DescriptorCode)
{
case AmqpSqlFilterCodec.Code:
var amqpSqlFilter = (AmqpSqlFilterCodec)amqpFilter;
filter = new SqlFilter(amqpSqlFilter.Expression);
break;
case AmqpTrueFilterCodec.Code:
filter = new TrueFilter();
break;
case AmqpFalseFilterCodec.Code:
filter = new FalseFilter();
break;
case AmqpCorrelationFilterCodec.Code:
var amqpCorrelationFilter = (AmqpCorrelationFilterCodec)amqpFilter;
var correlationFilter = new CorrelationFilter
{
CorrelationId = amqpCorrelationFilter.CorrelationId,
MessageId = amqpCorrelationFilter.MessageId,
To = amqpCorrelationFilter.To,
ReplyTo = amqpCorrelationFilter.ReplyTo,
Label = amqpCorrelationFilter.Label,
SessionId = amqpCorrelationFilter.SessionId,
ReplyToSessionId = amqpCorrelationFilter.ReplyToSessionId,
ContentType = amqpCorrelationFilter.ContentType
};
foreach (var property in amqpCorrelationFilter.Properties)
{
correlationFilter.Properties.Add(property.Key.Key.ToString(), property.Value);
}
filter = correlationFilter;
break;
default:
throw new NotSupportedException($"Unknown filter descriptor code: {amqpFilter.DescriptorCode}");
}
return filter;
}
static RuleAction GetRuleAction(AmqpRuleActionCodec amqpAction)
{
RuleAction action;
if (amqpAction.DescriptorCode == AmqpEmptyRuleActionCodec.Code)
{
action = null;
}
else if (amqpAction.DescriptorCode == AmqpSqlRuleActionCodec.Code)
{
var amqpSqlAction = (AmqpSqlRuleActionCodec)amqpAction;
var sqlAction = new SqlRuleAction(amqpSqlAction.SqlExpression);
action = sqlAction;
}
else
{
throw new NotSupportedException($"Unknown action descriptor code: {amqpAction.DescriptorCode}");
}
return action;
}
internal static bool TryGetAmqpObjectFromNetObject(object netObject, MappingType mappingType, out object amqpObject)
{
amqpObject = null;
if (netObject == null)
{
return true;
}
switch (SerializationUtilities.GetTypeId(netObject))
{
case PropertyValueType.Byte:
case PropertyValueType.SByte:
case PropertyValueType.Int16:
case PropertyValueType.Int32:
case PropertyValueType.Int64:
case PropertyValueType.UInt16:
case PropertyValueType.UInt32:
case PropertyValueType.UInt64:
case PropertyValueType.Single:
case PropertyValueType.Double:
case PropertyValueType.Boolean:
case PropertyValueType.Decimal:
case PropertyValueType.Char:
case PropertyValueType.Guid:
case PropertyValueType.DateTime:
case PropertyValueType.String:
amqpObject = netObject;
break;
case PropertyValueType.Stream:
if (mappingType == MappingType.ApplicationProperty)
{
amqpObject = StreamToBytes((Stream)netObject);
}
break;
case PropertyValueType.Uri:
amqpObject = new DescribedType((AmqpSymbol)UriName, ((Uri)netObject).AbsoluteUri);
break;
case PropertyValueType.DateTimeOffset:
amqpObject = new DescribedType((AmqpSymbol)DateTimeOffsetName, ((DateTimeOffset)netObject).UtcTicks);
break;
case PropertyValueType.TimeSpan:
amqpObject = new DescribedType((AmqpSymbol)TimeSpanName, ((TimeSpan)netObject).Ticks);
break;
case PropertyValueType.Unknown:
if (netObject is Stream netObjectAsStream)
{
if (mappingType == MappingType.ApplicationProperty)
{
amqpObject = StreamToBytes(netObjectAsStream);
}
}
else if (mappingType == MappingType.ApplicationProperty)
{
throw Fx.Exception.AsError(new SerializationException(Resources.FailedToSerializeUnsupportedType.FormatForUser(netObject.GetType().FullName)));
}
else if (netObject is byte[] netObjectAsByteArray)
{
amqpObject = new ArraySegment<byte>(netObjectAsByteArray);
}
else if (netObject is IList)
{
// Array is also an IList
amqpObject = netObject;
}
else if (netObject is IDictionary netObjectAsDictionary)
{
amqpObject = new AmqpMap(netObjectAsDictionary);
}
break;
}
return amqpObject != null;
}
static bool TryGetNetObjectFromAmqpObject(object amqpObject, MappingType mappingType, out object netObject)
{
netObject = null;
if (amqpObject == null)
{
return true;
}
switch (SerializationUtilities.GetTypeId(amqpObject))
{
case PropertyValueType.Byte:
case PropertyValueType.SByte:
case PropertyValueType.Int16:
case PropertyValueType.Int32:
case PropertyValueType.Int64:
case PropertyValueType.UInt16:
case PropertyValueType.UInt32:
case PropertyValueType.UInt64:
case PropertyValueType.Single:
case PropertyValueType.Double:
case PropertyValueType.Boolean:
case PropertyValueType.Decimal:
case PropertyValueType.Char:
case PropertyValueType.Guid:
case PropertyValueType.DateTime:
case PropertyValueType.String:
netObject = amqpObject;
break;
case PropertyValueType.Unknown:
if (amqpObject is AmqpSymbol amqpObjectAsAmqpSymbol)
{
netObject = (amqpObjectAsAmqpSymbol).Value;
}
else if (amqpObject is ArraySegment<byte> amqpObjectAsArraySegment)
{
ArraySegment<byte> binValue = amqpObjectAsArraySegment;
if (binValue.Count == binValue.Array.Length)
{
netObject = binValue.Array;
}
else
{
var buffer = new byte[binValue.Count];
Buffer.BlockCopy(binValue.Array, binValue.Offset, buffer, 0, binValue.Count);
netObject = buffer;
}
}
else if (amqpObject is DescribedType amqpObjectAsDescribedType)
{
if (amqpObjectAsDescribedType.Descriptor is AmqpSymbol)
{
var amqpSymbol = (AmqpSymbol)amqpObjectAsDescribedType.Descriptor;
if (amqpSymbol.Equals((AmqpSymbol)UriName))
{
netObject = new Uri((string)amqpObjectAsDescribedType.Value);
}
else if (amqpSymbol.Equals((AmqpSymbol)TimeSpanName))
{
netObject = new TimeSpan((long)amqpObjectAsDescribedType.Value);
}
else if (amqpSymbol.Equals((AmqpSymbol)DateTimeOffsetName))
{
netObject = new DateTimeOffset(new DateTime((long)amqpObjectAsDescribedType.Value, DateTimeKind.Utc));
}
}
}
else if (mappingType == MappingType.ApplicationProperty)
{
throw Fx.Exception.AsError(new SerializationException(Resources.FailedToSerializeUnsupportedType.FormatForUser(amqpObject.GetType().FullName)));
}
else if (amqpObject is AmqpMap map)
{
var dictionary = new Dictionary<string, object>();
foreach (var pair in map)
{
dictionary.Add(pair.Key.ToString(), pair.Value);
}
netObject = dictionary;
}
else
{
netObject = amqpObject;
}
break;
}
return netObject != null;
}
static ArraySegment<byte> StreamToBytes(Stream stream)
{
ArraySegment<byte> buffer;
if (stream == null || stream.Length < 1)
{
buffer = default;
}
else
{
using (var memoryStream = new MemoryStream(512))
{
stream.CopyTo(memoryStream, 512);
buffer = new ArraySegment<byte>(memoryStream.ToArray());
}
}
return buffer;
}
private static Data ToData(AmqpMessage message)
{
ArraySegment<byte>[] payload = message.GetPayload();
var buffer = new BufferListStream(payload);
ArraySegment<byte> value = buffer.ReadBytes((int)buffer.Length);
return new Data { Value = value };
}
static AmqpMap GetSqlFilterMap(SqlFilter sqlFilter)
{
var amqpFilterMap = new AmqpMap
{
[ManagementConstants.Properties.Expression] = sqlFilter.SqlExpression
};
return amqpFilterMap;
}
static AmqpMap GetCorrelationFilterMap(CorrelationFilter correlationFilter)
{
var correlationFilterMap = new AmqpMap
{
[ManagementConstants.Properties.CorrelationId] = correlationFilter.CorrelationId,
[ManagementConstants.Properties.MessageId] = correlationFilter.MessageId,
[ManagementConstants.Properties.To] = correlationFilter.To,
[ManagementConstants.Properties.ReplyTo] = correlationFilter.ReplyTo,
[ManagementConstants.Properties.Label] = correlationFilter.Label,
[ManagementConstants.Properties.SessionId] = correlationFilter.SessionId,
[ManagementConstants.Properties.ReplyToSessionId] = correlationFilter.ReplyToSessionId,
[ManagementConstants.Properties.ContentType] = correlationFilter.ContentType
};
var propertiesMap = new AmqpMap();
foreach (var property in correlationFilter.Properties)
{
propertiesMap[new MapKey(property.Key)] = property.Value;
}
correlationFilterMap[ManagementConstants.Properties.CorrelationFilterProperties] = propertiesMap;
return correlationFilterMap;
}
static AmqpMap GetRuleActionMap(SqlRuleAction sqlRuleAction)
{
AmqpMap ruleActionMap = null;
if (sqlRuleAction != null)
{
ruleActionMap = new AmqpMap { [ManagementConstants.Properties.Expression] = sqlRuleAction.SqlExpression };
}
return ruleActionMap;
}
}
}