0

I have two web separate apps in azure, one to administer content, and the other for displaying this content.

Currently I'm sending http requests from the admin app to the public app to clear in-memory caches of various objects.

This works fine, but won't scale out to more than one instance.

So, I've begun to investigate Service Bus topics for a pub/sub model for communication.

I've had no trouble sending the message to the topic from the admin app, but I can't sort out how to consume these messages from the public app.

There are plenty of examples of doing this inside a worker role or a web job, but I can't find any examples of receiving messages from a web app.

Further, once I sort this out, I will need to handle separate subscriptions for each instance. My idea is to use the WEBSITE_INSTANCE_ID in the subscription. Has anyone done this, or are there better solutions for multiple instances?

Or, is there a better way to handle distributed cache clearing?

4
  • why admin app has to notify the public app to clear cache? can you do what garbage collector do? e.g clear cache when cache up to certain limit (could be size of the cache or timestamp of the object).
    – Xiaomin Wu
    Commented Jan 5, 2016 at 23:43
  • Wouldn't it be better to use something like redis, and share a common cache service between the sites? Commented Jan 5, 2016 at 23:55
  • @Brendan Green - I'd like to use local memory cache if possible - there's nothing faster.
    – ScottE
    Commented Jan 6, 2016 at 0:00
  • I haven't checked too deeply into this, would this be possible by: a) using the System.Runtime.Caching.MemoryCache for the cache, b) using a WebRole instead of a WebApp, c) running the Service Bus message pump from the WebRole "OnStart" entry point? Commented Jan 6, 2016 at 0:05

1 Answer 1

0

There is no real difference between receiving from a web app or a worker role; you just need to spin a background thread on startup that does the work. When the app instance on the machine spins down the background thread should also terminate.

if you're using .NET, the easiest way to do that is using the OnMessage API so you don't have to write your own loop. Create the subscription client in the app on startup and initialize OnMessage with a callback. When the app signals shutdown you close the client for a clean exit.

The idea of using the instance-id for the subscription name is a good one. What you can also do, if you want to give your web app instances the "manage" permission on the topic, is to create a volatile subscription that is named with some random identifier (Guid?).

Volatile subscriptions auto-delete when having been idle (i.e. they have not been pulled on, message flow is not required to keep them alive) and are enabled by the AutoDeleteOnIdle flag.

3
  • I have tried using the OnMessage api, triggered from the Application_Start event from the public facing app. It receives messages, but honestly, it seems to cause the admin app to hang - which doesn't make sense as they are in different assemblies. Have you found a full example of this api in a web application?
    – ScottE
    Commented Jan 6, 2016 at 12:48
  • You need to fire up a background thread from within Application_Start, then use the the OnMessage API within the new thread Commented Jan 6, 2016 at 13:36
  • @CraigSmitham - do you have an example of setting this up?
    – ScottE
    Commented Jan 15, 2016 at 14:55

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.