public void WithDefaultExchangeAndRoutingKey() { var address = new Address("direct:///routing-key"); Assert.AreEqual(ExchangeTypes.Direct, address.ExchangeType); Assert.AreEqual(string.Empty, address.ExchangeName); Assert.AreEqual("routing-key", address.RoutingKey); Assert.AreEqual("direct:///routing-key", address.ToString()); }
public void Parse() { var replyToUri = "direct://my-exchange/routing-key"; var address = new Address(replyToUri); Assert.AreEqual(address.ExchangeType, ExchangeTypes.Direct); Assert.AreEqual(address.ExchangeName, "my-exchange"); Assert.AreEqual(address.RoutingKey, "routing-key"); }
public void WithoutRoutingKey() { Address address = new Address("fanout://my-exchange"); Assert.AreEqual(ExchangeType.Fanout, address.ExchangeType); Assert.AreEqual("my-exchange", address.ExchangeName); Assert.AreEqual("", address.RoutingKey); Assert.AreEqual("fanout://my-exchange/", address.ToString()); }
/// <summary>Sends the given response message to the given destination.</summary> /// <param name="channel">The channel to operate on.</param> /// <param name="replyTo">The replyto property to determine where to send a response.</param> /// <param name="message">The outgoing message about to be sent.</param> protected virtual void SendResponse(IModel channel, Address replyTo, Message message) { this.PostProcessChannel(channel, message); try { Logger.Debug(m => m("Publishing response to exchange = [{0}], routingKey = [{1}]", replyTo.ExchangeName, replyTo.RoutingKey)); channel.BasicPublish( replyTo.ExchangeName, replyTo.RoutingKey, this.mandatoryPublish, this.immediatePublish, this.messagePropertiesConverter.FromMessageProperties(channel, message.MessageProperties, this.encoding), message.Body); } catch (Exception ex) { throw RabbitUtils.ConvertRabbitAccessException(ex); } }
/// <summary>Determine a response destination for the given message.</summary> /// <remarks><para>The default implementation first checks the Rabbit ReplyTo /// property of the supplied request; if that is not /// <code>null</code> /// it is returned; if it is /// <code>null</code> /// , then the configured<see cref="ResponseRoutingKey"/> default response routing key} /// is returned; if this too is /// <code>null</code> /// , then an<see cref="InvalidOperationException"/>is thrown.</para> /// </remarks> /// <param name="request">The original incoming message.</param> /// <returns>the response destination (never /// <code>null</code> /// )</returns> /// <exception cref="InvalidOperationException">if no destination can be determined.</exception> protected virtual Address GetReplyToAddress(Message request) { var replyTo = request.MessageProperties.ReplyToAddress; if (replyTo == null) { if (string.IsNullOrEmpty(this.responseExchange)) { throw new AmqpException("Cannot determine ReplyTo message property value: Request message does not contain reply-to property, and no default response Exchange was set."); } replyTo = new Address(null, this.responseExchange, this.responseRoutingKey); } return replyTo; }
public void UnstructuredWithRoutingKeyOnly() { var address = new Address("my-routing-key"); Assert.AreEqual("my-routing-key", address.RoutingKey); Assert.AreEqual("direct:///my-routing-key", address.ToString()); }
public void ToString() { var address = new Address(ExchangeTypes.Direct, "my-exchange", "routing-key"); var replyToUri = "direct://my-exchange/routing-key"; Assert.AreEqual(replyToUri, address.ToString()); }
/// <summary> /// Sends the given response message to the given destination. /// </summary> /// <param name="channel">The channel to operate on.</param> /// <param name="replyTo">The replyto property to determine where to send a response.</param> /// <param name="message">The outgoing message about to be sent.</param> protected virtual void SendResponse(IModel channel, Address replyTo, Message message) { this.PostProcessChannel(channel, message); try { this.logger.Debug("Publishing response to exchanage = [" + replyTo.ExchangeName + "], routingKey = [" + replyTo.RoutingKey + "]"); channel.BasicPublish(replyTo.ExchangeName, replyTo.RoutingKey, this.mandatoryPublish, this.immediatePublish, RabbitUtils.ExtractBasicProperties(channel, message, this.encoding), message.Body); } catch (Exception ex) { throw RabbitUtils.ConvertRabbitAccessException(ex); } }