Multiple subscriptions per connection ?

1,227 views
Skip to first unread message

Steve Ardagh-Walter

unread,
Sep 19, 2013, 6:24:48 AM9/19/13
to openrail...@googlegroups.com
Hi all

I'm subscribing to several real-time feeds (TD, train movements & VSTP) and as I mentioned a few weeks ago occaisionally get 'ACK received with no message' errors.   I've been connecting once then adding two subscriptions by overwriting the clientId as follows :


$consumer = new Stomp("tcp://datafeeds.networkrail.co.uk:61618");
$consumer->setReadTimeout(100);
       $consumer->clientId = "lxtestmvt";

$consumer->connect("uname", "pw");
if (!$consumer->subscribe("/topic/TRAIN_MVT_EF_TOC")){
echo "subscribe 1 failed \n";
}
$consumer->clientId = "lxtesttd";   
        if (!$consumer->subscribe("/topic/TD_WTV_SIG_AREA")) {
echo "subscribe 2 failed \n";
}

Should I in fact be setting up several stomp objects & connections to handle the additional subscriptions (ie keep 1 connection per subscription) or are multiple subs per connection OK ?

Thanks

Steve

Peter Hicks

unread,
Sep 20, 2013, 10:40:29 AM9/20/13
to openrail...@googlegroups.com
Hi Steve

On 19/09/13 11:24, Steve Ardagh-Walter wrote:
> Should I in fact be setting up several stomp objects & connections to
> handle the additional subscriptions (ie keep 1 connection per
> subscription) or are multiple subs per connection OK ?
One connection and two subscriptions can work really well - it depends
how many separate processes you have polling data (e.g. a VSTP poller,
and a separate TD poller) and whether they're best handled in one daemon
or several with some kind of persistence/store shared between them.


P

Message has been deleted

Steve Ardagh-Walter

unread,
Sep 22, 2013, 10:58:32 AM9/22/13
to openrail...@googlegroups.com
Hi all

I've been trying the following - but (maybe because serialization doesn't work with this type of resource ?) am not getting any joy.  Can anyone advise on what's wrong and how to fix it please ?

Connection + Subscription 1 script : 
require_once("./Stomp/Stomp.php");  //  PHP stomp client

$consumer = new Stomp("tcp://datafeeds.networkrail.co.uk:61618");
$consumer->setReadTimeout(100);

$consumer->connect("uname", "pw");

$storstomp = serialize($consumer);
file_put_contents('./stompconsumer', $storstomp, LOCK_EX);

$consumer->clientId = "lxtesttd"; 

if (!$consumer->subscribe("/topic/TD_WTV_SIG_AREA")) {
echo "subscribe 2 failed \n";
}
 (continue processing TD feed - works fine)

============

Subscription 2 script :
require_once("./Stomp/Stomp.php");  

sleep(3);

$consumer = new Stomp("tcp://datafeeds.networkrail.co.uk:61618");
$consenc = readfile('./stompconsumer');

$consumer = unserialize($consenc);   // assign serialized session to stomp object

$consumer->clientId = "lxtestmvt";
if (!$consumer->subscribe("/topic/TRAIN_MVT_EF_TOC")){
echo "subscribe 1 failed \n";
}

This second script throws an error  Call to undefined method stdClass::subscribe() at the critical point ...

Any suggestions gratefully received 

Thanks

Steve

Peter Hicks

unread,
Sep 22, 2013, 12:49:01 PM9/22/13
to openrail...@googlegroups.com
On 22/09/13 15:58, Steve Ardagh-Walter wrote:
> I've been trying the following - but (maybe because serialization
> doesn't work with this type of resource ?) am not getting any joy.
> Can anyone advise on what's wrong and how to fix it please ?
I am no PHP expert (well, not any more) - but I don't think you can dump
a serialized object out in to a file and read it back again.

Have you tried using just one script that does
$consumer->subscribe("/topic/TD_WTV_SIG_AREA") and
$consumer->subscribe("/topic/TRAIN_MVT_EF_TOC"), then prints out the
full messages that are received?

Certainly on an early version of the Ruby subscriber I built for
OpenTrainTimes, the topic name comes through in the header of each
message, making it simple to process.


Peter

Alex Bilbie

unread,
Sep 22, 2013, 1:56:28 PM9/22/13
to openrail...@googlegroups.com


> On 22 Sep 2013, at 17:49, Peter Hicks <peter...@poggs.co.uk> wrote:
>
> I am no PHP expert (well, not any more) - but I don't think you can dump a serialized object out in to a file and read it back again

All serialised variables in PHP are cast as strings so you can freely write them to a file, database, console etc and then then unserialise them to their original type

Steve Ardagh-Walter

unread,
Sep 23, 2013, 8:33:09 AM9/23/13
to Alex Bilbie, openrail...@googlegroups.com
@Alex - I've been trying to unserialise the stomp object after I've connected, but it seems that live connections can't be resurrected this way (or if they can, can you tell me how please ?)

@Peter / @ All - I started with a single script handling 2+ subscriptions, which is the simplest structure, but keep getting  the 'ACK received without a message to acknowledge' error from the ActiveMQ server.    This error only happens when there is > 1 subscription running.   So have been looking at separate sessions sharing a single connection - as above this isn't playing.   Do you have any suggestions ?

Thanks

Steve



--
You received this message because you are subscribed to a topic in the Google Groups "A gathering place for the Open Rail Data community" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/openraildata-talk/4elWW-pNuwo/unsubscribe.
To unsubscribe from this group and all of its topics, send an email to openraildata-t...@googlegroups.com.
To post to this group, send an email to openrail...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Reply all
Reply to author
Forward
0 new messages