Hi, <@U01JVDKASAC>. I'm working on with the sst Qu...
# sst
l
Hi, @Frank. I'm working on with the sst Queue construct to create a "service bus" to decouple my microservices. Whenever the Rotations microservice marks a performance as complete (when a singer has just finished singing), a message is placed on a queue so that the PerformanceHistory microservice can add the performance to its event log. Since PerformanceHistory is the only microservice that is interested in this queue, the following solution for my
ServiceBusStack
should work just fine:
Copy code
import * as cdk from '@aws-cdk/core';
import * as sst from '@serverless-stack/resources';

export class ServiceBusStack extends sst.Stack {
  constructor(scope: cdk.Construct, id: string, props?: cdk.StackProps) {
    super(scope, id, props);

    const performancesQueue = new sst.Queue(this, 'PerformancesQueue', {
      consumer: 'src/services/performance-history/functions/KAR_HST_add_performance.handler',
    });
  }
}
Then, in the
RotationsStack
, I'll just reference the queue to give Rotations permissions so that it can add the messages. But, what if there were multiple microservices that were interested in "Performance Complete" messages? It seems I'd want a
consumers
property on
sst.Queue
, not just
consumer
. Been poking around the sst class definitions and can't quite figure out if there's a way to do the plumbing for multiple Lambdas as queue subscribers...
t
You probably want to look into EventBridge
It's meant more to serve as the event backbone for your entire system and can have different rules on who to notify about what messages. SQS is simpler and more for creating a backlog of messages that need to be processed
f
Yeah, each Queue can only has 1 consumer.
You can trigger a Topic, and have multiple Queues subscribe to it.
This is actually a common pattern I’ve seen.
l
Oh, I think I see what I overlooked. So EventBridge is more suited to a multi-consumer scenario.
f
Here’s an example of setting up Queues subscribed to a Topic - https://docs.serverless-stack.com/constructs/Topic#configuring-queue-subscribers