Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I have continued to debug this problem, and have fixed numerous things on my platform to avoid this exception. Here is what I have done to solve the issue:</p> <p><strong>Executive summary:</strong></p> <p>People encountering this exception should check:</p> <ol> <li>That the PooledRedisClientsManager (IRedisClientsManager) is registed in a singleton scope</li> <li>That the RedisMqServer (IMessageService) is registered in a singleton scope</li> <li>That any utilized RedisClient returned from either of the above is properly disposed of, to ensure that the pooled clients are not left stale.</li> </ol> <p><strong>The solution to my problem:</strong></p> <p>First of all, this exception is thrown by the PooledRedisClient <a href="https://github.com/ServiceStack/ServiceStack.Redis/pull/35" rel="nofollow noreferrer">because it has no more pooled connections available</a>.</p> <p>I'm registering all the required Redis stuff in the StructureMap IoC container (not unity as in the author's case). Thanks to <a href="https://stackoverflow.com/questions/18497021/servicestack-redis-unable-to-connect-sport-50071">this post</a> I was reminded that the PooledRedisClientManager should be a singleton - I also decided to register the RedisMqServer as a singleton:</p> <pre class="lang-cs prettyprint-override"><code> ObjectFactory.Configure(x =&gt; { // register the message queue stuff as Singletons in this AppDomain x.For&lt;IRedisClientsManager&gt;() .Singleton() .Use(BuildRedisClientsManager); x.For&lt;IMessageService&gt;() .Singleton() .Use&lt;RedisMqServer&gt;() .Ctor&lt;IRedisClientsManager&gt;().Is(i =&gt; i.GetInstance&lt;IRedisClientsManager&gt;()) .Ctor&lt;int&gt;("retryCount").Is(2) .Ctor&lt;TimeSpan?&gt;().Is(TimeSpan.FromSeconds(5)); // Retrieve a new message factory from the singleton IMessageService x.For&lt;IMessageFactory&gt;() .Use(i =&gt; i.GetInstance&lt;IMessageService&gt;().MessageFactory); }); </code></pre> <p>My "BuildRedisClientManager" function looks like this:</p> <pre class="lang-cs prettyprint-override"><code>private static IRedisClientsManager BuildRedisClientsManager() { var appSettings = new AppSettings(); var redisClients = appSettings.Get("redis-servers", "redis.local:6379").Split(','); var redisFactory = new PooledRedisClientManager(redisClients); redisFactory.ConnectTimeout = 5; redisFactory.IdleTimeOutSecs = 30; redisFactory.PoolTimeout = 3; return redisFactory; } </code></pre> <p>Then, when it comes to producing messages it's very important that the utilized RedisClient is properly disposed of, otherwise we run into the dreaded "Timeout Expired" (thanks to <a href="https://stackoverflow.com/questions/10597223/redis-servicestack-pooled-connection-client/10599194#10599194">this post</a>). I have the following helper code to send a message to the queue:</p> <pre class="lang-cs prettyprint-override"><code>public static void PublishMessage&lt;T&gt;(T msg) { try { using (var producer = GetMessageProducer()) { producer.Publish&lt;T&gt;(msg); } } catch (Exception ex) { // TODO: Log or whatever... I'm not throwing to avoid showing users that we have a broken MQ } } private static IMessageQueueClient GetMessageProducer() { var producer = ObjectFactory.GetInstance&lt;IMessageService&gt;() as RedisMqServer; var client = producer.CreateMessageQueueClient(); return client; } </code></pre> <p>I hope this helps solve your issue too.</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload