-
Notifications
You must be signed in to change notification settings - Fork 84
Description
Hey, I'll try to keep it short, so bear with me. I'm having the following scenario: I want to publish something to a subject as soon as the remote side has subscribed to the topic. This code demonstrates what I'm trying to achieve:
// this is on router side
var topic = realm.TopicContainer.CreateTopicByUri(topicUri, false);
topic.SubscriptionAdded += (sender, args) =>
{
realm.TopicContainer.Publish(WampObjectFormatter.Value, new PublishOptions(), topicUrl), new object[]{...});
}
However, after investigating why the object is not being received on subscriber side it turns out it is impossible to do this in the event listener due to the following implementation in WampRawTopic:
public void Subscribe(ISubscribeRequest<TMessage> request, SubscribeOptions options)
{
RemoteWampTopicSubscriber subscriber = new RemoteWampTopicSubscriber(this.SubscriptionId, (IWampSubscriber) request.Client);
WampRawTopic<TMessage>.RemoteObserver remoteObserver = this.mSubscriberBook.Subscribe(request.Client);
if (!remoteObserver.IsOpen)
this.RaiseSubscriptionAdding(subscriber, options);
request.Subscribed(this.SubscriptionId);
if (remoteObserver.IsOpen)
return;
this.RaiseSubscriptionAdded(subscriber, options); // <--- this is where the code above is executed
remoteObserver.Open(); <-- this is where the observer is opened
}
So, accoring to this method (also WampRawTopic) any published message is discarded unless the remote observer has been opened:
public void Message(WampMessage<object> message)
{
if (!this.IsOpen)
return; // <-- this is what's happening in my case
this.mClient.Message(message);
}
In conclusion seems to be impossible to publish messages when the subscription has been opened. Is there any recommended way of doing this? I'm thinking about delaying the execution with a deferred Task but that feels really dirty and not very good in terms of perfomance. Do you have any suggestions how this could be solved?
Thank in advance!