示例#1
0
		public Subscription RespondRaw(Func<MessageEnvelope, IMessageAck, MessageEnvelope> onRespond, 
									   ConsumerOptions options)
		{
			Argument.NotNull(onRespond, "onRespond");

			options = options ?? new ConsumerOptions();

			return InternalRespondRaw(onRespond, options, options.ShouldSerializeExceptions);
		}
示例#2
0
		public Subscription ConsumeRaw(Action<MessageEnvelope, IMessageAck> onReceived, 
									   ConsumerOptions options)
		{
			Argument.NotNull(onReceived, "onReceived");
			options = options ?? ConsumerOptions.Default;

			var consumer = CreateConsumer(options);

			consumer.Subscribe(new ActionAdapter(env =>
			{
				var msgAcker = new MessageAck(() => { lock(_model) _model.BasicAck(env.DeliveryTag, false); },
					(requeue) => { lock(_model) _model.BasicNack(env.DeliveryTag, false, requeue); });

				onReceived(env, msgAcker);
			}));

			lock(_model)
			{
				var consumerTag = _model.BasicConsume(this.Name, options.NoAck, consumer);

				return new Subscription(_model, consumerTag);
			}
		}
示例#3
0
		private Subscription InternalRespondRaw(Func<MessageEnvelope, IMessageAck, MessageEnvelope> onRespond, 
			ConsumerOptions options, 
			bool shouldSerializeExceptions)
		{
			options = options ?? ConsumerOptions.Default;
			var serializer = options.Serializer ?? _defaultSerializer;

			var consumer = CreateConsumer(options);

			consumer.Subscribe(new RpcResponder(_model, serializer, onRespond, shouldSerializeExceptions));

			lock (_model)
			{
				var consumerTag = _model.BasicConsume(this.Name, options.NoAck, consumer);

				return new Subscription(_model, consumerTag);
			}
		}
示例#4
0
		private IRabbitMessageProducer CreateConsumer(ConsumerOptions options)
		{
			if (options.ConsumerStrategy == ConsumerStrategy.Default)
			{
				return new StreamerConsumer(_model);
			}
			// else if (options.ConsumerStrategy == ConsumerStrategy.Queue)
			{
				return new SharedQueueConsumer(_model);
			}
		}