private void SendMessage(Message res) { var next = Model.NextPublishSeqNo; Model.BasicPublish(_myExchange.Name, res.RoutingKey, Props, res.Payload); if (MySettings.UseConfirms) _unacked.TryAdd(next, res); }
private void OnMessageNotEnqueuedHandler(Message message) { var copy = MessageNotEnqueuedHandler; //see http://stackoverflow.com/questions/786383/c-sharp-events-and-thread-safety //this behavior allow thread safety and allow to expose event publicly if (copy != null) try { copy(message); } catch (Exception e) { OnEventHandlerFailure(e); } }
private void HandleClosedConnection(Message res, RabbitMQ.Client.Exceptions.AlreadyClosedException e) { if (MySettings.RequeueMessageAfterFailure) _internalQueue.Enqueue(res); switch (e.ShutdownReason.ReplyCode) { case RabbitMQ.Client.Framing.v0_9_1.Constants.AccessRefused: OnACLFailure(e); break; default: Start(MySettings.MaxConnectionRetry); break; } }
private void HandleGeneralException(Message res) { if (MySettings.RequeueMessageAfterFailure) _internalQueue.Enqueue(res); //No need to offer any event handler since reconnection will probably fail at the first time and the standard handlers will be called Start(MySettings.MaxConnectionRetry); }
/// <summary> /// Add message that will be sent asynchronously. This method is thread-safe /// </summary> /// <param name="routingKey">routing key used to route the message. If not needed just put "toto"</param> /// <param name="message">the message you want to send</param> /// <returns>false if the message was droppped instead of added to the queue</returns> public bool Publish(string routingKey, byte[] message) { var _message = new Message { RoutingKey = routingKey, Payload = message }; if (_internalQueue.Count >= MySettings.MaxMessageWaitingToBeSent) { OnMessageNotEnqueuedHandler(_message); return false; } _internalQueue.Enqueue(_message); lock (_token) { Monitor.Pulse(_token); } return true; }