/// <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)); }
public Subscription(int id, string topic, Options options, Action<int, string, string> handler) { Id = id; Topic = topic; Options = options; Handler = handler; }
/// <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; }