Skip to content

Commit 32e3248

Browse files
Add ASB snippets for entity settings and sub rule customization.
1 parent 4eeda79 commit 32e3248

File tree

7 files changed

+150
-1
lines changed

7 files changed

+150
-1
lines changed

Snippets/ASBS/ASBS_3.2/Usage.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,47 @@ string HashName(string input)
101101
};
102102
transport.RetryPolicyOptions = azureAsbRetryOptions;
103103
#endregion
104+
105+
#region azure-service-bus-entitymaximumsize
106+
transport.EntityMaximumSize = 5;
107+
#endregion
108+
109+
#region azure-service-bus-enablepartitioning
110+
transport.EnablePartitioning = true;
111+
#endregion
112+
113+
#region azure-service-bus-subscriptionnameconvention
114+
string HashSubName(string input)
115+
{
116+
var inputBytes = Encoding.Default.GetBytes(input);
117+
// use MD5 hash to get a 16-byte hash of the string
118+
using (var provider = new MD5CryptoServiceProvider())
119+
{
120+
var hashBytes = provider.ComputeHash(inputBytes);
121+
return new Guid(hashBytes).ToString();
122+
}
123+
}
124+
125+
const int MaxEntityNameLength = 50;
126+
127+
transport.SubscriptionNamingConvention = n => n.Length > MaxEntityNameLength ? HashSubName(n) : n;
128+
#endregion
129+
130+
#region azure-service-bus-subscriptionrulenameconvention
131+
string HashRuleSubName(string input)
132+
{
133+
var inputBytes = Encoding.Default.GetBytes(input);
134+
// use MD5 hash to get a 16-byte hash of the string
135+
using (var provider = new MD5CryptoServiceProvider())
136+
{
137+
var hashBytes = provider.ComputeHash(inputBytes);
138+
return new Guid(hashBytes).ToString();
139+
}
140+
}
141+
142+
const int MaxSubRuleNameLength = 50;
143+
144+
transport.SubscriptionRuleNamingConvention = n => n.FullName.Length > MaxSubRuleNameLength ? HashRuleSubName(n.FullName) : n.FullName;
145+
#endregion
104146
}
105147
}

Snippets/ASBS/ASBS_3/Usage.cs

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,5 +101,47 @@ string HashName(string input)
101101
};
102102
transport.RetryPolicyOptions = azureAsbRetryOptions;
103103
#endregion
104+
105+
#region azure-service-bus-entitymaximumsize
106+
transport.EntityMaximumSize = 5;
107+
#endregion
108+
109+
#region azure-service-bus-enablepartitioning
110+
transport.EnablePartitioning = true;
111+
#endregion
112+
113+
#region azure-service-bus-subscriptionnameconvention
114+
string HashSubName(string input)
115+
{
116+
var inputBytes = Encoding.Default.GetBytes(input);
117+
// use MD5 hash to get a 16-byte hash of the string
118+
using (var provider = new MD5CryptoServiceProvider())
119+
{
120+
var hashBytes = provider.ComputeHash(inputBytes);
121+
return new Guid(hashBytes).ToString();
122+
}
123+
}
124+
125+
const int MaxEntityNameLength = 50;
126+
127+
transport.SubscriptionNamingConvention = n => n.Length > MaxEntityNameLength ? HashSubName(n) : n;
128+
#endregion
129+
130+
#region azure-service-bus-subscriptionrulenameconvention
131+
string HashRuleSubName(string input)
132+
{
133+
var inputBytes = Encoding.Default.GetBytes(input);
134+
// use MD5 hash to get a 16-byte hash of the string
135+
using (var provider = new MD5CryptoServiceProvider())
136+
{
137+
var hashBytes = provider.ComputeHash(inputBytes);
138+
return new Guid(hashBytes).ToString();
139+
}
140+
}
141+
142+
const int MaxSubRuleNameLength = 50;
143+
144+
transport.SubscriptionRuleNamingConvention = n => n.FullName.Length > MaxSubRuleNameLength ? HashRuleSubName(n.FullName) : n.FullName;
145+
#endregion
104146
}
105147
}

Snippets/ASBS/ASBS_4/Usage.cs

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,5 +99,43 @@ string HashName(string input)
9999
};
100100
transport.RetryPolicyOptions = azureAsbRetryOptions;
101101
#endregion
102+
103+
#region azure-service-bus-entitymaximumsize
104+
transport.EntityMaximumSize = 5;
105+
#endregion
106+
107+
#region azure-service-bus-enablepartitioning
108+
transport.EnablePartitioning = true;
109+
#endregion
110+
111+
#region azure-service-bus-subscriptionnameconvention
112+
string HashSubName(string input)
113+
{
114+
var inputBytes = Encoding.Default.GetBytes(input);
115+
// use MD5 hash to get a 16-byte hash of the string
116+
var hashBytes = MD5.HashData(inputBytes);
117+
118+
return new Guid(hashBytes).ToString();
119+
}
120+
121+
const int MaxEntityNameLength = 50;
122+
123+
transport.SubscriptionNamingConvention = n => n.Length > MaxEntityNameLength ? HashSubName(n) : n;
124+
#endregion
125+
126+
#region azure-service-bus-subscriptionrulenameconvention
127+
string HashRuleSubName(string input)
128+
{
129+
var inputBytes = Encoding.Default.GetBytes(input);
130+
// use MD5 hash to get a 16-byte hash of the string
131+
var hashBytes = MD5.HashData(inputBytes);
132+
133+
return new Guid(hashBytes).ToString();
134+
}
135+
136+
const int MaxSubRuleNameLength = 50;
137+
138+
transport.SubscriptionRuleNamingConvention = n => n.FullName.Length > MaxSubRuleNameLength ? HashRuleSubName(n.FullName) : n.FullName;
139+
#endregion
102140
}
103141
}

Snippets/ASBS/ASBS_5/Usage.cs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,15 @@ class Usage
130130
};
131131
transport.RetryPolicyOptions = azureAsbRetryOptions;
132132
#endregion
133+
134+
#region azure-service-bus-entitymaximumsize
135+
transport.EntityMaximumSize = 5;
136+
#endregion
137+
138+
#region azure-service-bus-enablepartitioning
139+
transport.EnablePartitioning = true;
140+
#endregion
141+
133142
}
134143

135144
class MyEvent;

Snippets/ASBS/ASBS_6/Usage.cs

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,14 @@ class Usage
130130
};
131131
transport.RetryPolicyOptions = azureAsbRetryOptions;
132132
#endregion
133+
134+
#region azure-service-bus-entitymaximumsize
135+
transport.EntityMaximumSize = 5;
136+
#endregion
137+
138+
#region azure-service-bus-enablepartitioning
139+
transport.EnablePartitioning = true;
140+
#endregion
133141
}
134142

135143
class MyEvent;
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,9 @@
11
### Settings
22

33
* `EntityMaximumSize`: The maximum entity size in GB. The value must correspond to a valid value for the namespace type. Defaults to 5. See [the Microsoft documentation on quotas and limits](https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-quotas) for valid values.
4-
* `EnablePartitioning`: Partitioned entities offer higher availability, reliability, and throughput over conventional non-partitioned queues and topics. For more information about partitioned entities [see the Microsoft documentation on partitioned messaging entities](https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-partitioning).
4+
5+
snippet: azure-service-bus-entitymaximumsize
6+
7+
* `EnablePartitioning`: Partitioned entities offer higher availability, reliability, and throughput over conventional non-partitioned queues and topics. For more information about partitioned entities [see the Microsoft documentation on partitioned messaging entities](https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-partitioning).
8+
9+
snippet: azure-service-bus-enablepartitioning
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,7 @@
11
* `SubscriptionNamingConvention(Func<string, string>)`: By default subscription names are derived from the endpoint name. This callback allows for a replacement name for the subscription. Subscription names must adhere to the limits outlined in [the Microsoft documentation on subscription creation](https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-quotas).
2+
3+
snippet: azure-service-bus-subscriptionnameconvention
4+
25
* `SubscriptionRuleNamingConvention(Func<Type, string>)`: By default rule names are derived from the message type's full name. This callback allows for a replacement name for the rule. Rule names must adhere to the limits outlined in [Service Bus quotas](https://docs.microsoft.com/en-us/azure/service-bus-messaging/service-bus-quotas).
6+
7+
snippet: azure-service-bus-subscriptionrulenameconvention

0 commit comments

Comments
 (0)