Do I have to consume the message separately with SQS? Publishing my message with SNS and consuming with SQS feels weird to me.
This is the pubsub implementation
export const awsSNSPlugin = fp(async server => {
const snsService = new SNS({ apiVersion: '2010-03-31' });
const publish: AWSPubSub['publish'] = async params => {
try {
const response = await snsService.publish(params).promise();
server.log.info(`Message ${params.Message} sent to the topic ${params.TopicArn}`);
server.log.info(response);
} catch (err: any) {
server.log.error(err, err.stack);
}
};
const subscribe: AWSPubSub['subscribe'] = async (params, callback) => {
try {
const response = await snsService.subscribe(params).promise();
server.log.info(`this is subscribe response: ${JSON.stringify(response)}`);
} catch (err: any) {
server.log.error(err, err.stack);
}
};
server.decorate('pubSub', {
publish,
subscribe,
});
});
I will call the method publish to publish a message like "test message", which will output "Message test message sent to the topic testTopic" on successful publish. I expect the subscriber to then respond with "this is subscribe response: test message" , but it doesn't. It only fires when the subscriber is first initialized on server start with this message:
this is subscribe response: {"ResponseMetadata":{"RequestId":"e4e6b056-f388-5f3d-8a8b-eb884551eaa1"},
"SubscriptionArn":"arn:aws:sns:us-east-1:111111111111111:profileCreated:12hello34-3hi4-1234-hello-12b12bff1212"}
I can see that SNS topic is publishing to the SQS because the number of message goes up in the SQS management console. However, the SNS subscription function is not consuming the messages. It outputs the console log (the callback function) when the server is booted up, but it does not respond to any of the published messages.