title: Routing messages: Topic to serverless to multi-queue (maybe) to serverless to multi rest
body: <p>Sorry if this is long and/or open ended... there is just so many options in azure I'm struggling to choose which pieces to use where, so Im hoping someone can help point the way.</p>
  
  <p>I am trying to build something as described in the image below. I am kind of "routing" messages from a multi-tenant service bus topic (top of diagram) to tenant specific REST endpoints (bottom of diagram).</p>
  
  <p>The hardest part that I am facing for far is to have kind of a concept of a function with dynamic queue/event triggers that change over time, but I'm looking for advice on any parts of the solution.</p>
  
  <p><a href="https://i.stack.imgur.com/NzAoE.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/NzAoE.png" alt="enter image description here"></a></p>
  
  <p>I have 4 constraints to deal with:</p>
  
  <ol>
  <li>Those messages HAVE to eventually reach the corresponding rest endpoint</li>
  <li>Those REST endpoint nodes get added and removed dynamically, but I do know (via event grid message) when that happens.</li>
  <li>Those REST endpoint nodes can also be taken offline anytime, or for long periods of time (days), and all messages should eventually be delivered</li>
  </ol>
  
  <p>I have a mostly working solution for <strong>F1</strong>, but looking for better ideas, but really its <strong>F2</strong> that I am struggling with.</p>
  
  <p><strong>F1</strong>
  Currently what I have is:</p>
  
  <ul>
  <li>1 queue per tenant server, created/deleted based on event grid message</li>
  <li>An Azure Function that can return a queue name based on service bus message contents</li>
  <li>A logic app (WIP) that will take messages off the topic subscription, use the function to determine the destination queue name, add the webhook URI to the message properties, and forward the message to that queue.</li>
  </ul>
  
  <p>I think that F1 will eventually work correctly :D... but f2..</p>
  
  <p><strong>F2</strong></p>
  
  <p>This is the tricky part, now I have N queues, that come and go over time. I can't figure out how to listen to all the queues via 1 function, so im thinking of trying to maybe rollout 1 function again per queue. It would be responsible for pulling messages off the queue and sending to the REST webhook URI.</p>
  
  <p>But then when the rest endpoint is down it should pause, and not drain the queue, also not sure how to do this efficiently, maybe another logic app with polling?</p>
  
  <p>I'm thinking of maybe using event grid instead of queues, because I think they have more serverless support in general, but I'm not sure this will solve the problem either.</p>
  
  <p>Appreciate any thoughts</p>