public void Should_mark_success() { const int sequenceNumber = 34456; channel.Stub(x => x.NextPublishSeqNo).Return(sequenceNumber); var success = false; var failure = false; Action successCallback = () => success = true; Action failureCallback = () => failure = true; publisherConfirms.RegisterCallbacks(channel, successCallback, failureCallback); var args = new BasicAckEventArgs { DeliveryTag = sequenceNumber, Multiple = false }; publisherConfirms.SuccessfulPublish(channel, args); success.ShouldBeTrue(); failure.ShouldBeFalse(); }
protected void Publish(string exchange, string routingKey, ITopology topology, MessageProperties properties, byte[] messageBody, Action <IPublishConfiguration> configure) { if (disposed) { throw new Exception("PublishChannel is already disposed"); } if (!_rabbitMessageBus.PersistentConnection.IsConnected) { throw new Exception("Publish failed. No rabbit server connected."); } try { var configuration = new AdvancedPublishConfiguration(); if (configure != null) { configure(configuration); } if (_publisherConfirms != null) { //if (configuration.SuccessCallback == null || configuration.FailureCallback == null) //{ // throw new Exception("When pulisher confirms are on, you must supply success and failure callbacks in the publish configuration"); //} _publisherConfirms.RegisterCallbacks(_channel, configuration.SuccessCallback != null ? configuration.SuccessCallback : () => { }, configuration.FailureCallback != null ? configuration.FailureCallback : () => { }); } var defaultProperties = _channel.CreateBasicProperties(); properties.CopyTo(defaultProperties); if (topology != null) { topology.Visit(new TopologyBuilder(_channel)); } _channel.BasicPublish( exchange, // exchange routingKey, // routingKey defaultProperties, // basicProperties messageBody); // body _rabbitMessageBus.Logger.Debug(string.Format("Published to exchange: '{0}', routing key: '{1}', correlationId: '{2}'", exchange, routingKey, defaultProperties.CorrelationId)); } catch (OperationInterruptedException exception) { throw new Exception(string.Format("Publish Failed: '{0}'", exception.Message)); } catch (IOException exception) { throw new Exception(string.Format("Publish Failed: '{0}'", exception.Message)); } }
public virtual void Publish(IExchange exchange, string routingKey, MessageProperties properties, byte[] messageBody, Action <IAdvancedPublishConfiguration> configure) { Preconditions.CheckNotNull(exchange, "exchange"); Preconditions.CheckNotNull(routingKey, "routingKey"); Preconditions.CheckNotNull(properties, "properties"); Preconditions.CheckNotNull(messageBody, "messageBody"); Preconditions.CheckNotNull(configure, "configure"); if (disposed) { throw new EasyNetQException("PublishChannel is already disposed"); } if (!advancedBus.Connection.IsConnected) { throw new EasyNetQException("Publish failed. No rabbit server connected."); } try { var configuration = new AdvancedPublishConfiguration(); configure(configuration); if (publisherConfirms != null) { if (configuration.SuccessCallback == null || configuration.FailureCallback == null) { throw new EasyNetQException("When pulisher confirms are on, you must supply success and failure callbacks in the publish configuration"); } publisherConfirms.RegisterCallbacks(channel, configuration.SuccessCallback, configuration.FailureCallback); } var defaultProperties = channel.CreateBasicProperties(); properties.CopyTo(defaultProperties); exchange.Visit(new TopologyBuilder(channel)); channel.BasicPublish( exchange.Name, // exchange routingKey, // routingKey defaultProperties, // basicProperties messageBody); // body advancedBus.Logger.DebugWrite("Published to exchange: '{0}', routing key: '{1}', correlationId: '{2}'", exchange.Name, routingKey, defaultProperties.CorrelationId); } catch (OperationInterruptedException exception) { throw new EasyNetQException("Publish Failed: '{0}'", exception.Message); } catch (System.IO.IOException exception) { throw new EasyNetQException("Publish Failed: '{0}'", exception.Message); } }