2
2
using System . Security . Cryptography ;
3
3
using System . Text ;
4
4
using Azure . Identity ;
5
+ using Azure . Messaging . ServiceBus ;
5
6
using NServiceBus ;
6
7
7
8
class Usage
@@ -77,5 +78,70 @@ string HashName(string input)
77
78
transport . SubscriptionRuleNamingConvention = n => n . FullName . Length > MaxEntityName ? HashName ( n . FullName ) : n . FullName ;
78
79
79
80
#endregion
81
+
82
+ #region azure-service-bus-usewebsockets
83
+ transport . UseWebSockets = true ;
84
+ #endregion
85
+
86
+ #region azure-service-bus-websockets-proxy
87
+ transport . WebProxy = new System . Net . WebProxy ( "http://myproxy:8080" ) ;
88
+ #endregion
89
+
90
+ #region azure-service-bus-TimeToWaitBeforeTriggeringCircuitBreaker
91
+ transport . TimeToWaitBeforeTriggeringCircuitBreaker = TimeSpan . FromMinutes ( 2 ) ;
92
+ #endregion
93
+
94
+ #region azure-service-bus-RetryPolicyOptions
95
+ var azureAsbRetryOptions = new Azure . Messaging . ServiceBus . ServiceBusRetryOptions
96
+ {
97
+ Mode = Azure . Messaging . ServiceBus . ServiceBusRetryMode . Exponential ,
98
+ MaxRetries = 5 ,
99
+ Delay = TimeSpan . FromSeconds ( 0.8 ) ,
100
+ MaxDelay = TimeSpan . FromSeconds ( 15 )
101
+ } ;
102
+ transport . RetryPolicyOptions = azureAsbRetryOptions ;
103
+ #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
80
146
}
81
147
}
0 commit comments