public void SendResponse(MessageContext context, HttpResponsePacket response) { if (disposed) { throw new ObjectDisposedException("Subscriber has been disposed"); } if (String.IsNullOrEmpty(context.ReplyToQueue)) { return; } if (conn == null) { //TODO: Log this -- it technically shouldn't happen. Also translate to a HTTP Unreachable because it means StartCallbackQueueConsumer didn't create a connection throw new ApplicationException("This is Bad"); } //TODO: Channel Pool this connection using (IModel channel = conn.CreateModel()) { BasicProperties basicProperties = new BasicProperties { CorrelationId = context.CorrelationId }; try { channel.BasicPublish(String.Empty, context.ReplyToQueue, basicProperties, response.Serialize()); } catch { //TODO: Log execption } } }
public void SendResponse(MessageContext context, HttpResponsePacket response) { if (disposed) { throw new ObjectDisposedException(GetType().FullName); } var dispatch = context.Dispatch as MessageDispatch; if (dispatch != null) { //Ack request if (Settings.AckBehavior != SubscriberAckBehavior.Automatic && dispatch.Consumer.Model.IsOpen) { dispatch.Consumer.Model.BasicAck(dispatch.Delivery.DeliveryTag, false); //NOTE: The call above takes place in different threads silmultaneously //In which case multiple threads will be using the same channel at the same time. //It's okay in this case, because transmissions within a channel are synchronized, as seen in: //https://github.com/rabbitmq/rabbitmq-dotnet-client/blob/f16c093f6409e11d9d77115038cb224eb39468ec/projects/client/RabbitMQ.Client/src/client/impl/ModelBase.cs#L459 //and //https://github.com/rabbitmq/rabbitmq-dotnet-client/blob/f16c093f6409e11d9d77115038cb224eb39468ec/projects/client/RabbitMQ.Client/src/client/impl/SessionBase.cs#L177 } } //Exit method if no replyToQueue was specified. if (String.IsNullOrEmpty(context.ReplyToQueue)) { return; } if (_subscriberPool.Connection == null) { //TODO: Log this -- it technically shouldn't happen. Also translate to a HTTP Unreachable because it means StartCallbackQueueConsumer didn't create a connection throw new InvalidOperationException("This is Bad"); } //Add/Update Subscriber-Id header response.Headers[Common.Shared.SUBSCRIBER_ID_HEADER] = subscriberIdHeader; //Send response var pooler = _subscriberPool; AmqpModelContainer model = null; try { model = pooler.GetModel(ChannelFlags.None); BasicProperties basicProperties = new BasicProperties { CorrelationId = context.CorrelationId }; model.Channel.BasicPublish(String.Empty, context.ReplyToQueue, basicProperties, response.Serialize()); } finally { if (model != null) { model.Close(); } } }