forked from ServiceStack/ServiceStack
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathQueueNames.cs
More file actions
100 lines (79 loc) · 3.02 KB
/
QueueNames.cs
File metadata and controls
100 lines (79 loc) · 3.02 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
92
93
94
95
96
97
98
99
100
using System;
using System.Text;
namespace ServiceStack.Messaging
{
/// <summary>
/// Util static generic class to create unique queue names for types
/// </summary>
/// <typeparam name="T"></typeparam>
public static class QueueNames<T>
{
static QueueNames()
{
Priority = QueueNames.ResolveQueueNameFn(typeof(T).Name, ".priorityq");
In = QueueNames.ResolveQueueNameFn(typeof(T).Name, ".inq");
Out = QueueNames.ResolveQueueNameFn(typeof(T).Name, ".outq");
Dlq = QueueNames.ResolveQueueNameFn(typeof(T).Name, ".dlq");
}
public static string Priority { get; private set; }
public static string In { get; private set; }
public static string Out { get; private set; }
public static string Dlq { get; private set; }
public static string[] AllQueueNames
{
get
{
return new[] {
In,
Priority,
Out,
Dlq,
};
}
}
}
/// <summary>
/// Util class to create unique queue names for runtime types
/// </summary>
public class QueueNames
{
public static string Exchange = "mx.servicestack";
public static string ExchangeDlq = "mx.servicestack.dlq";
public static string ExchangeTopic = "mx.servicestack.topic";
public static string MqPrefix = "mq:";
public static string QueuePrefix = "";
public static string TempMqPrefix = MqPrefix + "tmp:";
public static string TopicIn = MqPrefix + "topic:in";
public static string TopicOut = MqPrefix + "topic:out";
public static Func<string, string, string> ResolveQueueNameFn = ResolveQueueName;
public static string ResolveQueueName(string typeName, string queueSuffix)
{
return QueuePrefix + MqPrefix + typeName + queueSuffix;
}
public static bool IsTempQueue(string queueName)
{
return queueName != null
&& queueName.StartsWith(TempMqPrefix, StringComparison.OrdinalIgnoreCase);
}
public static void SetQueuePrefix(string prefix)
{
TopicIn = prefix + MqPrefix + "topic:in";
TopicOut = prefix + MqPrefix + "topic:out";
QueuePrefix = prefix;
TempMqPrefix = prefix + MqPrefix + "tmp:";
}
private readonly Type messageType;
public QueueNames(Type messageType)
{
this.messageType = messageType;
}
public string Priority => ResolveQueueNameFn(messageType.Name, ".priorityq");
public string In => ResolveQueueNameFn(messageType.Name, ".inq");
public string Out => ResolveQueueNameFn(messageType.Name, ".outq");
public string Dlq => ResolveQueueNameFn(messageType.Name, ".dlq");
public static string GetTempQueueName()
{
return TempMqPrefix + Guid.NewGuid().ToString("n");
}
}
}