예제 #1
0
 /// <summary>
 /// Subscribe the specified topic and invokes messageHandler when message arrives.
 /// </summary>
 /// <param name='topic'>
 /// Topic.
 /// </param>
 /// <param name="options">
 /// Options.
 /// </param>
 /// <param name='messageHandler'>
 /// Message handler.
 /// Argument is: message
 /// </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<string> messageHandler)
 {
     return Subscribe(topic, options, (sid, msg, reply) => messageHandler(msg));
 }
예제 #2
0
 public Subscription(int id, string topic, Options options, Action<int, string, string> handler)
 {
     Id = id;
     Topic = topic;
     Options = options;
     Handler = handler;
 }
예제 #3
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;
 }