Not logged in. · Lost password · Register
Forum: MatriX and XmppDotNet RSS
Avatar
gireesh #1
Member since Nov 2015 · 5 posts
Group memberships: Members
Show profile · Link to this post
Subject: Intermittent failures in node creation
Hello,

We are using Matrix .NET library to publish events from a back end service.
Here is roughly what we try to do, sample working code attached.

  1. public void Test()
  2. {
  3.     Jid _pubSubJid = new Jid("somedomain.com");
  4.     XmppClient _xmppClient = new XmppClient();
  5.     _xmppClient.SetUsername("user2");
  6.     _xmppClient.Password = "pass123";
  7.     _xmppClient.SetXmppDomain("somedomain.com");
  8.     _xmppClient.Transport = Matrix.Net.Transport.Bosh;
  9.     _xmppClient.Uri = new Uri("http://someserver:5280/http-bind");
  10.     _xmppClient.OnLogin += new EventHandler<Matrix.EventArgs>((src, args) => { CreateNode(); });
  11.     _xmppClient.OnError += _xmppClient_OnError;
  12.  
  13.     try
  14.     {
  15.         _xmppClient.Open();
  16.     }
  17.     catch (Exception e)
  18.     {
  19.         throw e;
  20.     }
  21. }
  22.  
  23. public void CreateNode()
  24. {
  25.     // code for creating node
  26. }


Essentially we login and on the login call back we try to create a new node. What we find is if we attempt to create a node on call back it doesn't work. Essentially the Task returned by _pubSubManager.CreateNodeAsync(_pubSubJid, nodeName, nodeConfigurations) never seem to complete and so, our "ContinueWith" task never gets executed.

So, we made a minor change. Instead of attempting to create the node directly within the call back, we now try to create a new task from within the call back and introduce some delay before the createnode call.

  1. _xmppClient.OnLogin += new EventHandler<Matrix.EventArgs>((src, args)
  2.         =>
  3.         {
  4.             Console.WriteLine("OnLoginCallBack");
  5.             Task.Factory.StartNew(()
  6.             =>
  7.             {
  8.                 Thread.Sleep(1000);
  9.                 CreateNode("somenodetobecreated10");
  10.             });
  11.         });
         
This seems to work most of the time - but fails for about 10% of the attempts.

So, the questions are:

1. Is this the expected behaviour?
2. If so, how do I know when the xmppclient is ready for creation of nodes? How long do I need to wait? Are there any call back or messages to indicate that everything is now ready?
3. Is _xmppClient library thread safe? Can I use it from multiple threads without any side effects? e.g. If I try to create two different nodes from two different threads using the same XmppClient and PubsubManager, will it work fine?
4. Is this library suitable for use in an server environment where may different threads are attempting to process and publish events concurrently?

Appreciate your help,
Gireesh
The author has attached one file to this post:
TestMatrix.cs 4.6 kBytes
You have no permission to open this file.
This post was edited on 2015-11-17, 22:05 by Alex.
Avatar
Alex #2
Member since Feb 2003 · 4449 posts · Location: Germany
Group memberships: Administrators, Members
Show profile · Link to this post
The OnLogin event is the wrong event.
This event indicated only that the authentication succeeded. But the Xmpp Session is not ready at this event.

I suggest to wait until you get the 1st incoming Presence which you can check with the OnPresence event. The OnRosterEnd event works also fine in most cases.

Yes MatriX is thread safe and works fine in server environments.

Alex
Avatar
gireesh #3
Member since Nov 2015 · 5 posts
Group memberships: Members
Show profile · Link to this post
Thanks Alex, OnPresence event solved the issue
Close Smaller – Larger + Reply to this post:
Verification code: VeriCode Please enter the word from the image into the text field below. (Type the letters only, lower case is okay.)
Smileys: :-) ;-) :-D :-p :blush: :cool: :rolleyes: :huh: :-/ <_< :-( :'( :#: :scared: 8-( :nuts: :-O
Special characters: