0

After successfully developing an application with multiple ServiceStack services, we are moving to other testing environments, lots of them due to us running a SAAS model (aka multi-tenant). I'd like to reuse some of the base infrastructure services, primarily Redis and RabbitMQ across a few of these environments.

We're using the IAppSetting interface to pull our configuration from multiple sources into one cohesive settings object at run-time, which is then filtered tier. Since tier drives the configuration per environment it made sense to use Tier to prefix any RabbitMQ messages queues, and prefix any generated cache keys that will be used by Redis, thus providing collision protection per environment.

Below is an example:

RabbitMQ => "Some MQ method here" => "mq:qa1.Outbound.inq"

Redis => "Some Redis method here" => "urn:qa1.somePoco:123"

Here is an example configuration and the various enviroments

<appSettings>
    <add key="Tier" value="qa1" />
    <!--<add key="Tier" value="dev" />-->
    <!--<add key="Tier" value="tst" />-->
    <!--<add key="Tier" value="stg" />-->
    <!--<add key="Tier" value="prod" />-->
</appSettings>

Thank you, Stephen

1 Answer 1

2

Some examples on how to modify Queue Names are in MqNameTests, e.g:

QueueNames.SetQueuePrefix("site1.");

Will add a prefix on QueueNames, e.g:

site1.mq:TestPrefix.inq

Otherwise you can use QueueNames.ResolveQueueNameFn to have complete control over the MQ name, e.g:

QueueNames.ResolveQueueNameFn = (typeName, suffix) =>
    "SITE.{0}{1}".Fmt(typeName, suffix.ToUpper());


QueueNames<TestFilter>.In.Print(); // SITE.TestFilter.INQ

Note the same configuration also needs to applied on the client so the same MQ names gets used.

Configuring ServiceStack with AppSettings

ServiceStack is a code-first framework which means all configuration is done in code, but has a rich and versatile configuration model where you can get the behavior your after by reading App Settings in AppHost.Configure():

QueueNames.SetQueuePrefix(AppSettings.Get("Tier","dev"));

Where if Tier doesn't exist in your Web.config (e.g. in Unit Tests) it will use dev otherwise will use the value in your appSettings:

<appSettings>
    <add key="Tier" value="qa1" />
</appSettings>
5
  • @Stephen also uses the same Queue Name strategy.
    – mythz
    Dec 21, 2014 at 0:32
  • Just to confirm, even if we're just using Redis for Cache and Session this is the correct way? Dec 21, 2014 at 0:36
  • @Stephen It's ok as this only changes MQ Queue names so only affects Redis MQ not the Redis Cache Client.
    – mythz
    Dec 21, 2014 at 0:42
  • Changed my question to clarify the usage of our RabbitMQ message broker and Redis distributed cache. Both are being used simultaneously, but have different roles. Dec 21, 2014 at 17:57
  • @Stephen There's no global namespace prefix that applies to all keys in Redis. If you want to use the same redis instance you can specify to use a different database, e.g. ?db=2 on the connection string.
    – mythz
    Dec 21, 2014 at 18:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.