Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9274303
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T16:19:22+00:00 2026-06-18T16:19:22+00:00

I need some help about my node.js+socket.io implementation. This service expose a server that

  • 0

I need some help about my node.js+socket.io implementation.

This service expose a server that connects to an ActiveMQ broker over the STOMP protocol, using the stomp-js node.js module to receive events; that then are displayed in a web front end through websockets using socket.io.

So, everything was fine until I started use the Filters feature of ActiveMQ, but this was not the failure point because of my and my team researching, we found the way to ensure the implementation was fine, the problem comes with the connections: So here’s the thing, I receive the filters to subscribe, I successfully subscribe to but when I receive a new set of filters is when comes the duplicated, triplicated and more and more messages depending the number of times that I subscribe-unsubscribe to.

So making some debug, I cannot see what’s the problem but I’m almost sure that is some bad implementation of the callbacks or the program flow, I’ll attach my code to read your comments about it.

Thanks a lot!

var sys = require('util');
var stomp = require('stomp');
var io = require('socket.io').listen(3000);

var socket = io.sockets.on('connection', function (socket) {

var stomp_args = {
    port: 61616,
    host: 'IP.ADDRESS',
    debug: true,
    };

var headers;
var client = new stomp.Stomp(stomp_args);
var setFilters = false; 

socket.on('filtros', function (message) {

    console.log('DEBUG: Getting filters');

    if(setFilters){
            client.unsubscribe(headers);
        }
    else{
            client.connect();
        }

    var selector = '';
    headers = '';

    for(var attributename in message){
        console.log(attributename+" : " + message[attributename]);
        if(message[attributename] != ''){
            selector += ' ' + attributename + '=\'' + message[attributename] + '\' AND ';
        }
    }

    selector = selector.substring(0, selector.length - 4)
    console.log('DEBUG: Selector String: ' + selector);

    headers = {
        destination: '/topic/virtualtopic',
        ack: 'client',
        selector: selector
    };

    if(setFilters)
        client.subscribe(headers);

    client.on('connected', function() {
        client.subscribe(headers);
        console.log('DEBUG: Client Connected');
        setFilters = true;
    });
});
var bufferMessage;
client.on('message', function(message) {
    console.log("Got message: " + message.headers['message-id']);
    var jsonMessage = JSON.parse(message.body);
    if(bufferMessage === jsonMessage){
        console.log('DEBUG: recibo un mensaje repetido');
        return 0;
        }
    else{
        console.log('DEBUG: Cool');
        socket.emit('eventoCajero', jsonMessage);
        }           
    client.ack(message.headers['message-id']);
    bufferMessage = jsonMessage;
});

socket.on('disconnect', function(){
        console.log('DEBUG: Client disconnected');
        if(setFilters){
            console.log('DEBUG: Consumer disconnected');
            client.disconnect();
            }
        });
client.on('error', function(error_frame) {
    console.log(error_frame.body);
});

});

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-18T16:19:23+00:00Added an answer on June 18, 2026 at 4:19 pm

    Looking in the Socket.IO documentation, I’ve found that this is a known issue (I think critical known issue) and they have not fixed it yet. So, to correct this is necessary to reconnect to the socket in the client side to avoid duplicate messages, using:

    socket.socket.reconnect();
    

    function to force reconnection explicitly.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I need some help about MVVM pattern. I created a ViewModel that expose data
I need some help about sorting a multiple array. This is what I got:
hello friends i need some help about updating xml node in wp7. my xml
I need some help on this problem. It is about ASP.NET MVC3. I have
I need some help about optimisation. I am trying to improve this open-source game
I need some help! I have no doubt this is a dumb problem that
Need some help about this one. I have a Telerik:RadGridView control and define the
I need some help about WCF and authorization. Currently I have a client which
I need some help about RegExp in AS3. I have a simple pattern :
I need some help with PHP Class. I have limited knowledge about how it

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.