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

subscribed client doesn't receive the message from broker #22

Open
nick1008 opened this issue Jan 16, 2019 · 2 comments
Open

subscribed client doesn't receive the message from broker #22

nick1008 opened this issue Jan 16, 2019 · 2 comments

Comments

@nick1008
Copy link

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);})

})`

@nuharaf
Copy link

nuharaf commented Jan 16, 2019

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.

@nick1008
Copy link
Author

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

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