Skip to content
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

rxStomp using JavaScript promises #548

Open
mohamedinvite opened this issue Feb 9, 2024 · 2 comments
Open

rxStomp using JavaScript promises #548

mohamedinvite opened this issue Feb 9, 2024 · 2 comments

Comments

@mohamedinvite
Copy link

mohamedinvite commented Feb 9, 2024

I coded a way to subscribe to an MQ queue using rxStomp. I have no problems everything works well but I would like to optimize my treatment by making it responsive and using promises but I am not comfortable with this concept in node.js.

I would like to continue to receive messages and send them to the database. But I would like it to send in database is not blocking and that I continue to receive my MQ messages in the order of arrival.

Could someone - help me? Thanks in advance

This is my code actually

function rxSubscribeToTopic() {
    try {

        rxStomp.connected$.subscribe(() => {
            subscription = rxStomp
                .watch({destination: "/queue/test",'ack': 'client', 'activemq.prefetchSize': 1 })
                .subscribe(async (message) => {
                        let client = createMongoClient();
                        try {

                            await client.connect();

                            const database = client.db("stomp");
                            const collection = database.collection("stomp_message");
                            let messageJson = {
                                "message": message.body
                            }
                            await collection.insertOne(messageJson).then(value => console.log("Inserted" + value.insertedId)
                        )
                        } finally {
                            // Ensures that the client will close when you finish/error
                        }
                    }
                );
        })
    } catch (e) {
        log(e)
        rxStomp.stompErrors$.subscribe(value => value.body);
        activateStomp();
    }
@kum-deepak
Copy link
Member

I have not tested your code. However, it seems to be doing what you intend. Does it not work as you want it to?

I noticed some other issues with the code. It can be written much simpler. I am ignoring those. I guess that you have written just an outline code in your issue.

@mohamedinvite
Copy link
Author

Hello , Kum.

For more details what I want it's to make the function watch() reactive too.
actually this code works but i tested with little message.
Will it run with big treatment?

My code is a test code but I’m new to JS if you have advice on my code to optimize it will be happy to take them

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants