-
Notifications
You must be signed in to change notification settings - Fork 2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Can't pass an existing SQS/SNS url to the adapter. #4
Comments
Hi! That's because the queue must start at the last offset of the SNS topic, so the node only receives the messages published after that (and not replay old messages). Calling process.on("SIGTERM", () => {
io.close();
}); Another solution would have been to reuse an existing queue, and discard old messages. |
There is still an issue with closing SQS queues. Example code: const closeServer = (io: Server) => {
io.close((e) => {
if (e) {
logger.error('Failed to close socket.io server', { error: serializeError(e) })
} else {
logger.debug('Socket.io server closed')
}
})
}
process.on('SIGTERM', () => closeServer(io)) // close server on SIGTERM
process.on('SIGINT', () => closeServer(io)) // close server on SIGINT When running locally (and connected to AWS), when I Ctrl+C (and hence send a SIGINT), I'm getting the message I'm assuming it's simply because the SIGINT will not wait for async functions (like deleting the queues) to close before exiting. Below are the DEBUG logs coming from the package (no mention of even trying to delete the queues):
|
@vanhumbeecka it seems that the |
I think it's worth a try, although I'm not entirely sure we get guarantees this function will run to the end (where it deletes the queues) before process termination happens. It might though. EDIT: Alternatively, what's missing here is being able to get the names (or better, ARNs) of those queues somehow, in order to manage these outside of this process. (e.g. we could store these names in a datastore to check if these are still being used in a different process or something similar). Something like this: const snsClient = new SNS()
const sqsClient = new SQS()
const adapter = createAdapter(snsClient, sqsClient, {
topicName: 'socketio',
queuePrefix: 'socketio',
})
const io = new Server(httpServer, {
adapter: adapter
})
const details = adapter.getDetails() // <-- generic adapter object which contains the queue names in case of SQS adapter EDIT 2: Changed my mind again 😅 : we could leverage the const adapter = createAdapter(snsClient, sqsClient, {
topicName: 'socketio',
queuePrefix: 'socketio',
queueTags: { Application: 'my-app', Version: '1.2.3' }
}) |
When initializing the adapter, it will create a new SQS every time.
That behavior would imply the creation of a new Queue every time a node/task within my scaling group is mounted ! So how can't use the same queue across my nodes for persistance & central brodcasting ( the main motivations behind using an adapter in socket.io )
( For Redis & MongoDb adapters, you can pass the url or table names to use )
The text was updated successfully, but these errors were encountered: