Subscribe a user sometimes does not work for JS sample codes.

Oct 1, 2012 at 5:55 PM

Hi, I was using JS sample codes to test chat app in local machine (I installed PServiceBus 2.0.0). The problem I noticed was that not every time when I called the method "registerUser()" the user can be successfully subscribed. The details for subscribing a user is as follows:

var path = String.format("{0}:5672;userID=guest;password=guest;queue={1}chatQueue", endpoint, userName);
var subscriber = ESB.Subscriber.New(userName)
.SubscribeTo(ESB.Topic.Select(topicName).NotEqual("UserName", userName))
.AddTransport("Rabbit", ESB.TransportType.RabbitMQ,
{ Format: ESB.TransportFormat.Json, Path: path });
subscriber.Save();
As a result, the user can send message but it can not receive message. My questions are:
1. How can I know if a user subscription method call is successful, for example, if using Chrome;
2. If the subscription failed, is there any make-up way to fix it during the runtime?
Thanks for your help.

Coordinator
Oct 1, 2012 at 7:23 PM
I have resolved the problem already in version 2.0.1. The issue is the time it takes to register the subscriber object on the server side. With the 2.0.0 version, the REST api that the JS api calls does not wait for the subscriber to exists before proceeding to listen for message therefore it fails to receive anything on the client side because the on message received method is called immediately. A temporary fix for it now, is to call the onMessage receive in a setTimeout that waits for like 1 sec or more. So that when the OnMessage Received is called it will have a subscriber object to use when listening for new message.

Your subscription is not failing as stated above, it is just a timing issue for the on message receive to pull the correct subscriber information from the server side. If subscription were to fail, you will receive exception in js such as Topic is invalid, Subscriber does not exist, Subscriber already exists, and e.t.c

Again, the problem as been resolved in 2.0.1 which will be released at the end of this month.


Oct 1, 2012 at 7:30 PM

Thanks, that is exactly as what you described. Ling

From: rpgmaker [email removed]
Sent: Monday, October 01, 2012 2:23 PM
To: Shen, Ling (SCR US)
Subject: Re: Subscribe a user sometimes does not work for JS sample codes. [pServiceBus:397562]

From: rpgmaker

I have resolved the problem already in version 2.0.1. The issue is the time it takes to register the subscriber object on the server side. With the 2.0.0 version, the REST api that the JS api calls does not wait for the subscriber to exists before proceeding to listen for message therefore it fails to receive anything on the client side because the on message received method is called immediately. A temporary fix for it now, is to call the onMessage receive in a setTimeout that waits for like 1 sec or more. So that when the OnMessage Received is called it will have a subscriber object to use when listening for new message.

Your subscription is not failing as stated above, it is just a timing issue for the on message receive to pull the correct subscriber information from the server side. If subscription were to fail, you will receive exception in js such as Topic is invalid, Subscriber does not exist, Subscriber already exists, and e.t.c


Again, the problem as been resolved in 2.0.1 which will be released at the end of this month.

This message and any attachments are solely for the use of intended recipients. The information contained herein may include trade secrets, protected health or personal information, privileged or otherwise confidential information. Unauthorized review, forwarding, printing, copying, distributing, or using such information is strictly prohibited and may be unlawful. If you are not an intended recipient, you are hereby notified that you received this email in error, and that any review, dissemination, distribution or copying of this email and any attachment is strictly prohibited. If you have received this email in error, please contact the sender and delete the message and any attachment from your system. Thank you for your cooperation