Permalink
Browse files

Made OperationTimeout and MaximumMessageSize Configurable

  • Loading branch information...
1 parent 9805cfd commit c422ce0c360d43c9ac22a6c4d04a013964a04ebe @abnanda1 abnanda1 committed Dec 14, 2013
@@ -41,6 +41,10 @@ public ServiceBusConnection(ServiceBusScaleoutConfiguration configuration, Trace
_trace.TraceError("Invalid connection string '{0}': {1}", configuration.ConnectionString, ex.Message);
}
+ if (configuration.OperationTimeout != null)
+ {
+ _factory.GetSettings().OperationTimeout = configuration.OperationTimeout.Value;
+ }
_idleSubscriptionTimeout = configuration.IdleSubscriptionTimeout;
_configuration = configuration;
}
@@ -63,7 +67,7 @@ public ServiceBusConnection(ServiceBusScaleoutConfiguration configuration, Trace
_trace.TraceInformation("Subscribing to {0} topic(s) in the service bus...", topicNames.Count);
- var connectionContext = new ServiceBusConnectionContext(_configuration, _namespaceManager, topicNames, handler, errorHandler, openStream);
+ var connectionContext = new ServiceBusConnectionContext(_configuration, _namespaceManager, topicNames, _trace, handler, errorHandler, openStream);
for (var topicIndex = 0; topicIndex < topicNames.Count; ++topicIndex)
{
@@ -2,9 +2,11 @@
using System;
using System.Collections.Generic;
+using System.Diagnostics;
using System.Globalization;
using System.IO;
using System.Threading.Tasks;
+using Microsoft.AspNet.SignalR.Tracing;
using Microsoft.ServiceBus;
using Microsoft.ServiceBus.Messaging;
@@ -28,9 +30,12 @@ public class ServiceBusConnectionContext : IDisposable
public bool IsDisposed { get; private set; }
+ private TraceSource _trace;
+
public ServiceBusConnectionContext(ServiceBusScaleoutConfiguration configuration,
NamespaceManager namespaceManager,
IList<string> topicNames,
+ TraceSource traceSource,
Action<int, IEnumerable<BrokeredMessage>> handler,
Action<int, Exception> errorHandler,
Action<int> openStream)
@@ -46,6 +51,8 @@ public class ServiceBusConnectionContext : IDisposable
_subscriptions = new SubscriptionContext[topicNames.Count];
_topicClients = new TopicClient[topicNames.Count];
+ _trace = traceSource;
+
TopicNames = topicNames;
Handler = handler;
ErrorHandler = errorHandler;
@@ -67,6 +74,13 @@ public Task Publish(int topicIndex, Stream stream)
TimeToLive = _configuration.TimeToLive
};
+ long messageSize = message.Size / 1024;
+
+ if (messageSize > _configuration.MaximumMessageSize)
+ {
+ _trace.TraceError("Message size {0}KB exceeds the maximum size limit of 256KB : {1}", messageSize, message);
+ }
+
return _topicClients[topicIndex].SendAsync(message);
}
@@ -29,6 +29,8 @@ public ServiceBusScaleoutConfiguration(string connectionString, string topicPref
TopicPrefix = topicPrefix;
TopicCount = 1;
TimeToLive = TimeSpan.FromMinutes(1);
+ MaximumMessageSize = 256;
+ OperationTimeout = null;
}
/// <summary>
@@ -77,5 +79,16 @@ public int TopicCount
/// Specifies the time duration after which an idle subscription is deleted
/// </summary>
public TimeSpan IdleSubscriptionTimeout { get; set; }
+
+ /// <summary>
+ /// Sets the operation timeout for all Service Bus operations
+ /// </summary>
+ public TimeSpan? OperationTimeout { get; set; }
+
+ /// <summary>
+ /// Sets the maximum message size (in KB) that can be sent or received
+ /// Default value is set to 256KB which is the maximum recommended size for Service Bus operations
+ /// </summary>
+ public int MaximumMessageSize { get; set; }
}
}

0 comments on commit c422ce0

Please sign in to comment.