forked from robinrodricks/FluentStorage
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathQueuesFactory.cs
50 lines (46 loc) · 1.75 KB
/
QueuesFactory.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
using System;
using FluentStorage.ConnectionString;
using FluentStorage.Messaging;
using FluentStorage.Azure.Queues;
namespace FluentStorage {
public static class QueuesFactory {
/// <summary>
/// Register Azure module.
/// </summary>
public static IModulesFactory UseAzureQueues(this IModulesFactory factory) {
return factory.Use(new Module());
}
/// <summary>
/// Creates an instance of a publisher to Azure Storage Queues
/// </summary>
/// <param name="factory">Factory reference</param>
/// <param name="accountName">Account name. Must not be <see langword="null"/> or empty.</param>
/// <param name="storageKey">Storage key. Must not be <see langword="null"/> or empty.</param>
/// <param name="serviceUri">Alternative service uri. Pass <see langword="null"/> for default.</param>
/// <returns>Generic message publisher interface</returns>
public static IMessenger AzureStorageQueue(this IMessagingFactory factory,
string accountName,
string storageKey,
Uri serviceUri = null) {
if (serviceUri == null)
return new AzureStorageQueueMessenger(accountName, storageKey);
return new AzureStorageQueueMessenger(accountName, storageKey, serviceUri);
}
/// <summary>
///
/// </summary>
/// <param name="factory"></param>
/// <param name="accountName"></param>
/// <param name="accountKey"></param>
/// <returns></returns>
public static StorageConnectionString ForAzureStorageQueuesWithSharedKey(
this IConnectionStringFactory factory,
string accountName,
string accountKey) {
var cs = new StorageConnectionString(KnownPrefix.AzureQueueStorage);
cs.Parameters[KnownParameter.AccountName] = accountName;
cs.Parameters[KnownParameter.KeyOrPassword] = accountKey;
return cs;
}
}
}