How to send data in chunk as response

44 views
Skip to first unread message

SANMOY PAUL

unread,
Aug 2, 2016, 7:21:32 AM8/2/16
to actionHero.js
I am using redis pubsub.I am publishing the message on a channel and subsribint it on an api call but I am unable to send the data in the client-side as event-stream.

Evan Tahler

unread,
Aug 2, 2016, 12:46:11 PM8/2/16
to actionHero.js
This is a great use case for the chat room features of ActionHero.  
  • Create a private room just between the client and the server.  Use connection.id for a unique and private ID
  • Every time you get a message from Redis, sent it to the client with connection.send

SANMOY PAUL

unread,
Aug 3, 2016, 2:49:37 AM8/3/16
to actionHero.js
I have created the chat room using api.chatRoom.add("channel:"+apiKey+":"+jobId, next);


and on receiving the message from redis I have used data.connection.sendMessage(message).How to receive the message in client side


SANMOY PAUL

unread,
Aug 3, 2016, 4:26:53 AM8/3/16
to actionHero.js


Moreover my client side is hosted on a differrent machine and on play-framework


Evan Tahler

unread,
Aug 3, 2016, 7:56:36 AM8/3/16
to actionHero.js
How are you establishing the the web socket connection to action hero without using the included client js libraries?  
Join us in our slack room @ slack.actionherojs.com to talk to the team there... it seems like this will require more of a conversation. 

SANMOY PAUL

unread,
Aug 9, 2016, 1:34:46 AM8/9/16
to actionHero.js
This is my action

exports.streamRedisPubSub= {
name: 'streamRedisPubSub',
description: 'It uses the PUBSUB mechanism of Redis',
inputs: {
id: {required: true},
apiKey: {required: true}
},
run: function(api, data, next){
var apiKey = data.params.apiKey
var jobId = data.params.id;
api.chatRoom.add("channel:"+apiKey+":"+jobId, next);
api.taskController.streaming(data,jobId,apiKey, function(error, success){
if(error)
next(error);
else {
//data.response.success = success;
//data.connection.sendMessage(success);
next(null,success);
}
});
}


streaming : function(data,jobId, apiKey, next) {
console.log("In streaming......"+apiKey+":"+jobId);
subscriber.subscribe("channel:"+apiKey+":"+jobId);
data.connection.rawConnection.responseHeaders.push(['Connection', 'keep-alive']);
data.connection.rawConnection.responseHeaders.push(['Transfer-Encoding', 'chunked']);
data.connection.rawConnection.responseHeaders.splice(0,1);
data.connection.rawConnection.responseHeaders.push(['Content-Type', 'text/event-stream']);
subscriber.on("message", function(channel, message) {
console.log("Message on channel '" + channel + "' arrived!");
console.log(message);
*******here the required message is coming but I am unable to send it as a event/stream response in the client side*************
api.chatRoom.broadcast(data.connection, channel, message, next)
//data.connection.sendMessage(message);
//next(null,message);
});


I have already published the mesasge using publisher.publish("channel:"+apiKey+":"+jobId,JSON.stringify(payload));

payload contains the message

Evan Tahler

unread,
Aug 9, 2016, 11:11:51 AM8/9/16
to actionHero.js
This conversation has been moved to GitHub here -> https://github.com/evantahler/actionhero/issues/399#issuecomment-238472833
Reply all
Reply to author
Forward
0 new messages