Esempio n. 1
0
 private void SendSubscribe(Connection conn, Subscription sub)
 {
     string queue = sub.Options.Queue;
     conn.Send("SUB " + sub.Topic + " " + queue + " " + sub.Id);
 }
Esempio n. 2
0
 /// <summary>
 /// Subscribe the specified topic and invokes messageHandler when message arrives.
 /// </summary>
 /// <param name='topic'>
 /// Topic.
 /// </param>
 /// <param name="options">
 /// Options.
 /// Current avialble options: queue
 /// </param>
 /// <param name='messageHandler'>
 /// Message handler.
 /// Three arguments are: subscriptionId, message, replyTopic
 /// replyTopic can be null if no reply is expected
 /// </param>
 /// <returns>
 /// Subscription Id
 /// </returns>
 /// <remarks>
 /// messageHandler may be invoked before this function returns as this is a multi-threading library
 /// </remarks>
 ///
 public int Subscribe(string topic, Options options, Action<int, string, string> messageHandler)
 {
     ThrowIfDisposed();
     var sub = new Subscription(Interlocked.Increment(ref _sidBase), topic, options, messageHandler);
     lock (_stateLock)
     {
         _subscriptions.Add(sub.Id, sub);
         if (_connection != null)
         {
             SendSubscribe(_connection, sub);
         }
     }
     return sub.Id;
 }