-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathRabbitMqMessageAdapter.cs
More file actions
75 lines (70 loc) · 3.25 KB
/
RabbitMqMessageAdapter.cs
File metadata and controls
75 lines (70 loc) · 3.25 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
// =================================================================================================================================
// Copyright (c) RapidField LLC. Licensed under the MIT License. See LICENSE.txt in the project root for license information.
// =================================================================================================================================
using RapidField.SolidInstruments.Messaging.TransportPrimitives;
using RapidField.SolidInstruments.Serialization;
using System;
namespace RapidField.SolidInstruments.Messaging.RabbitMq
{
/// <summary>
/// Facilitates conversion of general-format messages to and from RabbitMQ messages.
/// </summary>
public sealed class RabbitMqMessageAdapter : MessageAdapter<PrimitiveMessage>
{
/// <summary>
/// Initializes a new instance of the <see cref="RabbitMqMessageAdapter" /> class.
/// </summary>
public RabbitMqMessageAdapter()
: base()
{
return;
}
/// <summary>
/// Initializes a new instance of the <see cref="RabbitMqMessageAdapter" /> class.
/// </summary>
/// <param name="messageSerializationFormat">
/// Gets the format that is used to serialize and deserialize messages. The default value is
/// <see cref="SerializationFormat.Binary" />.
/// </param>
/// <exception cref="ArgumentOutOfRangeException">
/// <paramref name="messageSerializationFormat" /> is equal to <see cref="SerializationFormat.Unspecified" />.
/// </exception>
public RabbitMqMessageAdapter(SerializationFormat messageSerializationFormat)
: base(messageSerializationFormat)
{
return;
}
/// <summary>
/// Converts the specified general-format message to an implementation-specific message.
/// </summary>
/// <typeparam name="TMessage">
/// The type of the message.
/// </typeparam>
/// <param name="message">
/// A general-format message to convert.
/// </param>
/// <param name="serializer">
/// A serializer that is used to serialize the message.
/// </param>
/// <returns>
/// The implementation-specific message.
/// </returns>
protected sealed override PrimitiveMessage ConvertForward<TMessage>(TMessage message, ISerializer<TMessage> serializer) => new PrimitiveMessage(message, new MessageLockToken(Guid.NewGuid(), message.Identifier), MessageSerializationFormat);
/// <summary>
/// Converts the specified implementation-specific message to a general-format message.
/// </summary>
/// <typeparam name="TMessage">
/// The type of the message.
/// </typeparam>
/// <param name="message">
/// An implementation-specific message to convert.
/// </param>
/// <param name="serializer">
/// A serializer that is used to serialize the message.
/// </param>
/// <returns>
/// The general-format message.
/// </returns>
protected sealed override TMessage ConvertReverse<TMessage>(PrimitiveMessage message, ISerializer<TMessage> serializer) => message.GetBody<TMessage>();
}
}