mqtt-connection icon indicating copy to clipboard operation
mqtt-connection copied to clipboard

subscribed client doesn't receive the message from broker

Open nick1008 opened this issue 6 years ago • 2 comments

node version: 8.11.0 working on windows 7.

The client is successfully subscribed.

The broker receives the publish from client A but doesn't forward it to client B

`server.on('connection', function (stream) { let conn = mqttConn(stream)

// conn connected
conn.on('connect', function (packet) {
	console.log(conn.options);
  	// acknowledge the connect packet
  	conn.connack({ returnCode: 0 });
	})

conn.on('publish', function (packet) {
	times++;
	packet2send = packet;
	console.log(packet);
	conn.pubrec({ messageId: packet.messageId });
	conn.on('pubrel', function (packet) {
		console.log(packet);
		conn.pubcomp({ messageId: packet.messageId });
		stream.setTimeout(10000)
		stream.on('timeout', function () {
	  		conn.publish({
				retain: false,
				qos: 2,
				dup: false,
				length: 14,
				topic: 'hello',
				payload: 'world',
				messageId: 1
			});
	  		conn.on('pubrec', function (packet) {
				console.log('aa' + packet);
	  			conn.pubrel({ messageId: packet.messageId });
				console.log(packet);
				conn.on('pubcomp', function (packet) {
					console.log('aa' + packet);
					console.log(packet);
				});
			})
		});
	})
})

// conn subscribed
conn.on('subscribe', function (packet) {
	console.log(packet);
// send a suback with messageId and granted QoS level
	conn.suback({ granted: [packet.qos], messageId: messageId })
})

// timeout idle streams after 5 minutes
//stream.setTimeout(1000 * 60 * 5)

// connection error handling
conn.on('close', function (packet) { conn.destroy() 
	console.log('close ' + packet);})
conn.on('error', function (packet) { conn.destroy() 
	console.log('error ' + packet);})
conn.on('disconnect', function (packet) { conn.destroy() 
	console.log('disconnect' + packet);})

})`

nick1008 avatar Jan 16 '19 10:01 nick1008

mqtt-connection does not deal with topic matching and packet forwarding, for that you can use aedes . You can use mqtt-connection to built custom broker, but it is on itself is not a broker.

nuharaf avatar Jan 16 '19 12:01 nuharaf

Yes. thank you very much for the reply!! I just figured that out 1 hour before you answer and used aedes. works fine. So balanced shame with a bit of confidence.. :P

nick1008 avatar Jan 16 '19 13:01 nick1008