Ejemplo n.º 1
0
		private MessageAck CreateAcker(MessageEnvelope newMsg)
		{
			var msgAcker = new MessageAck(() => { lock(_model) _model.BasicAck(newMsg.DeliveryTag, false); },
				(requeue) => { lock(_model) _model.BasicNack(newMsg.DeliveryTag, false, requeue); });
			
			return msgAcker;
		}
Ejemplo n.º 2
0
		private void InternalPublish(MessageEnvelope envelope)
		{
			foreach(var consumer in _consumers)
			{
				consumer.OnNext(envelope);
			}
		}
Ejemplo n.º 3
0
		// kind of copy constructor
		public MessageEnvelope(MessageEnvelope source)
			: this(source.Properties, source.Body)
		{
			this.ConsumerTag = source.ConsumerTag;
			this.ExchangeName = source.ExchangeName;
			this.RoutingKey = source.RoutingKey;
			this.DeliveryTag = source.DeliveryTag;
			this.IsRedelivery = source.IsRedelivery;
		}
		private void PublishToConsumers(BasicDeliverEventArgs args)
		{
			var envelope = new MessageEnvelope(args.BasicProperties, args.Body)
			{
				ConsumerTag = args.ConsumerTag,
				DeliveryTag = args.DeliveryTag,
				ExchangeName = args.Exchange,
				IsRedelivery = args.Redelivered,
				RoutingKey = args.RoutingKey
			};

			foreach(var consumer in _consumers)
			{
				consumer.OnNext(envelope);
			}
		}
Ejemplo n.º 5
0
		public override void HandleBasicDeliver(string consumerTag,
			ulong deliveryTag, bool redelivered,
			string exchange, string routingKey,
			IBasicProperties properties,
			byte[] body)
		{
			var envelope = new MessageEnvelope(properties, body)
			{
				ConsumerTag = consumerTag,
				DeliveryTag = deliveryTag,
				ExchangeName = exchange,
				IsRedelivery = redelivered,
				RoutingKey = routingKey
			};

			InternalPublish(envelope);
		}
Ejemplo n.º 6
0
		public void	OnNext(MessageEnvelope newMsg)
		{
			var incomingMsgProperties = newMsg.Properties;
			var replyQueue = incomingMsgProperties.ReplyTo;
			var correlationId = incomingMsgProperties.CorrelationId;

			IBasicProperties replyProperties = null;

			byte[] replyData = new byte[0];

			var msgAcker = CreateAcker(newMsg);

			try
			{
				var response = _onRespond(newMsg, msgAcker);
				response = response ?? new MessageEnvelope(new BasicProperties(), new byte[0]);
				replyData = response.Body;

				replyProperties = response.Properties ?? new BasicProperties();
			}
			catch(Exception e)
			{
				replyProperties = replyProperties ?? new BasicProperties();

				if (LogAdapter.LogEnabled) LogAdapter.LogError("Rpc", "OnNext error", e);

				// Empty data
				if (_shouldSerializeExceptions)
					replyData = _serializer.Serialize(new ErrorResponse() { Exception = e }, replyProperties);

				ErrorResponse.FlagHeaders(replyProperties);
			}

			// which call is which
			replyProperties.CorrelationId = correlationId;

			// Rabbit client will explode if this is not true
			(replyProperties is RabbitMQ.Client.Impl.BasicProperties)
				.AssertIsTrue("expected BasicProperties implementation of IBasicProperties");

			lock (_model)
			{
				_model.BasicPublish("", replyQueue, replyProperties, replyData);
			}
		}
Ejemplo n.º 7
0
 public void OnNext(MessageEnvelope message)
 {
     _action(message);
 }
Ejemplo n.º 8
0
		private	void ModelOnBasicReturn(object sender, BasicReturnEventArgs	args)
		{
			if (LogAdapter.LogEnabled)
			{
				LogAdapter.LogDebug("RabbitChannel", 
					"Message dropped. Message sent to exchange " + args.Exchange + " with routing key "	+ args.RoutingKey, 
					null);
			}

			var	ev = this.MessageUnrouted;
			if (ev == null)	return;

			var	envelope = new MessageEnvelope(args.BasicProperties, args.Body);
			var	eventArgs =	new	MessageUnroutedEventArgs()
			{
				MessageEnvelope	= envelope,
				Exchange = args.Exchange,
				ReplyCode =	args.ReplyCode,
				ReplyText =	args.ReplyText,
				RoutingKey = args.RoutingKey
			};
				
			ev(eventArgs);
		}
 public MessageEnvelope(MessageEnvelope copy, T message) : base(copy)
 {
     this.Message = message;
 }
Ejemplo n.º 10
0
 public void OnNext(MessageEnvelope message)
 {
     _action(message);
 }