Not able to subscribe after publishing message either from cmd or from .publish()
See original GitHub issueI’m trying to implement pub/sub mechanism but I’m getting error whenever I publish message either from command line or through node package.
My client creation code looks like
async setRedisClient(): Promise<void> {
let redisOpts: RedisClientOptions = this.cloudConfig.getRedisCredentials();
this.pubClient = createClient(redisOpts);
await this.pubClient.connect();
this.subClient = this.pubClient.duplicate();
await this.subClient.connect();
}
getPubClient() {
return this.pubClient;
}
getSubClient() {
return this.subClient;
}
my redis config
return {
socket: {
host: "localhost"
port: 6379,
tls: false
},
legacyMode: true,
password: "1234"
}
And my subscription code looks like:
async listenRemoteSockets() {
logger.info("Subscriber to remote socket updates");
try {
// doing this to capture message after 10 seconds.
setTimeout(async () => {
await this.redisManager.getPubClient().publish('monitor', 'test from app 22');
}, 10000);
await this.redisManager.getSubClient().subscribe('monitor', (err, count) => {
if (err) {
logger.error(`>>>>>>>>>>>>> Error occured ${err}`);
}
logger.info(`>>>>>>>>>>>>>> Subscribed to ${count}`)
});
this.redisManager.getSubClient().on('message', (channel, message) => {
logger.info(`>>>>>>>>>>>>> Got message from ${channel} => ${message}`)
})
} catch (error) {
logger.error(`Error occured >>>>>>>>>>>>>>> ${error}`)
}
}
Following error is thrown once I publish from either command or through .publish()
Error: Got an unexpected reply from Redis
at Object.onReply (app.js:2:2830344)
at exports.default.write (app.js:2:2823283)
at RedisCommandsQueue.onReplyChunk (app.js:2:2835206)
at RedisSocket.<anonymous> (app.js:2:2870390)
at RedisSocket.emit (node:events:527:28)
at Socket.<anonymous> (app.js:2:2889095)
at Socket.emit (node:events:527:28)
at addChunk (node:internal/streams/readable:324:12)
at readableAddChunk (node:internal/streams/readable:297:9)
at Readable.push (node:internal/streams/readable:234:10)
Environment:
- Node.js Version: v18.3.0
- Redis Server Version: Redis server v=7.0.5 sha=00000000:0 malloc=libc bits=64 build=bc49a85e754011b0
- Node Redis Version: redis@4.3.1
- Platform: Mac OS 12.6.1
Issue Analytics
- State:
- Created 10 months ago
- Comments:5
Top Results From Across the Web
Publish messages to topics | Cloud Pub/Sub - Google Cloud
This document provides information about publishing messages. A publisher application creates and sends messages to a topic. Pub/Sub offers at-least-once ...
Read more >MQTT Publish and Subscribe Beginners Guide
In MQTT the process of sending messages is called publishing, and to receive messages an MQTT client must subscribe to an MQTT topic....
Read more >Howto subscribe to a message? How does auto/manual ...
When you do not auto-subscribe, you have to explicitly subscribe yourself in code. Start by specifying the IWantCustomInitialization interface on your ...
Read more >rospy.Publisher.publish() should wait for the ... - GitHub
Publisher.publish() should wait for the publisher to be registered with the master, then publish the message. A wait_until_ready(timeout) method ...
Read more >Amazon SNS message publishing - AWS Documentation
Publish messages to Amazon SNS topics, log message delivery status, and create a ... whether the subscribed endpoint is interested in the published...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Looks like PubSub is not working well with
legacyMode
on, I’ll debug it later today@omkarrepal yea turn off legacy mode in the subscriber client
edit: or use
.v4.subscribe
on the legacy client