Ejemplo n.º 1
0
        public static T TypedDeserialize <T>(this IRabbitSerializer source, byte[] data, IBasicProperties properties)
        {
            properties.Type.AssertNotNullOrEmpty("The message property 'Type' must have a qualified type name");

            var expectedType = Type.GetType(properties.Type);

            return((T)source.Deserialize(data, expectedType, properties));
        }
Ejemplo n.º 2
0
 public RpcResponder(IModel model,
                     IRabbitSerializer serializer,
                     Func <MessageEnvelope, IMessageAck, MessageEnvelope> onRespond,
                     bool shouldSerializeExceptions)
 {
     _model      = model;
     _serializer = serializer;
     _onRespond  = onRespond;
     _shouldSerializeExceptions = shouldSerializeExceptions;
 }
Ejemplo n.º 3
0
		public RpcResponder(IModel model, 
							IRabbitSerializer serializer,
							Func<MessageEnvelope, IMessageAck, MessageEnvelope> onRespond,
							bool shouldSerializeExceptions)
		{
			_model = model;
			_serializer	= serializer;
			_onRespond = onRespond;
			_shouldSerializeExceptions = shouldSerializeExceptions;
		}
Ejemplo n.º 4
0
		public RabbitChannel(IModel	model, IRabbitSerializer defaultSerializer)
		{
			_model = model;
			_defaultSerializer = defaultSerializer;
			_defaultExchange = new RabbitExchange(_model, _defaultSerializer, 
				name: string.Empty,	canDestroy:	false, 
				options: new ExchangeOptions());

			_model.BasicReturn += ModelOnBasicReturn;
		}
Ejemplo n.º 5
0
        public RabbitChannel(IModel model, IRabbitSerializer defaultSerializer)
        {
            _model             = model;
            _defaultSerializer = defaultSerializer;
            _defaultExchange   = new RabbitExchange(_model, _defaultSerializer,
                                                    name: string.Empty, canDestroy:     false,
                                                    options: new ExchangeOptions());

            _model.BasicReturn += ModelOnBasicReturn;
        }
Ejemplo n.º 6
0
        public RabbitExchange(IModel model, IRabbitSerializer serializer,
                              string name, bool canDestroy, ExchangeOptions options)
        {
            this.Name = name;

            _model             = model;
            _defaultSerializer = serializer;
            _canDestroy        = canDestroy;
            _options           = options;
            _isDefaultExchange = name == string.Empty;

            _rpcHelper = new RpcHelper(_model, this.Name, serializer);
        }
Ejemplo n.º 7
0
		public RabbitQueue(IModel model, 
						   IRabbitSerializer serializer,
						   QueueDeclareOk result, 
						   QueueOptions queueOptions)
		{
			_model = model;
			_defaultSerializer = serializer ?? queueOptions.Serializer;
			_queueOptions = queueOptions;

			this.Name = result.QueueName;
			this.ConsumerCount = result.ConsumerCount;
			this.MessageCount = result.MessageCount;
		}
Ejemplo n.º 8
0
        public RabbitQueue(IModel model,
                           IRabbitSerializer serializer,
                           QueueDeclareOk result,
                           QueueOptions queueOptions)
        {
            _model             = model;
            _defaultSerializer = serializer ?? queueOptions.Serializer;
            _queueOptions      = queueOptions;

            this.Name          = result.QueueName;
            this.ConsumerCount = result.ConsumerCount;
            this.MessageCount  = result.MessageCount;
        }
Ejemplo n.º 9
0
        public RpcHelper(IModel model, string exchange, IRabbitSerializer serializer)
        {
            _model      = model;
            _exchange   = exchange;
            _serializer = serializer;

            _routing2RetQueue = new Dictionary <string, string>(StringComparer.Ordinal);
            _waits            = new ConcurrentDictionary <string, AutoResetEvent>(StringComparer.Ordinal);
            _replyData        = new ConcurrentDictionary <string, MessageEnvelope>(StringComparer.Ordinal);

            this.ConsumerCancelled += (sender, args) =>
            {
                LogAdapter.LogDebug("RpcHelper", "Consumer cancelled: " + args.ConsumerTag);
            };
        }
Ejemplo n.º 10
0
        public static byte[] TypedSerialize <T>(this IRabbitSerializer source, T instance, IBasicProperties properties)
        {
            if (properties.Type == null)
            {
                var msgType = instance.GetType();

                if (Castle.Core.ProxyServices.IsDynamicProxy(instance.GetType()))
                {
                    throw new Exception("Serialization of a proxy type will be really bad for your sanity");
                }

                var fullname = msgType.AssemblyQualifiedName;
                var sndComma = fullname.IndexOf("Version=", msgType.FullName.Length, StringComparison.Ordinal);

                properties.Type = fullname.Substring(0, sndComma - 2);;
            }

            return(source.Serialize(instance, properties));
        }