Beispiel #1
0
        public void Set_Content()
        {
            var houseDto      = GetHouseDto();
            var thriftMessage = new ThriftMessage <HouseDto>(houseDto);

            thriftMessage.Content.ShouldNotBe(null);
        }
Beispiel #2
0
        public ThriftMessage Send(ThriftMessage thriftMessage)
        {
            var message  = MessageMapper.Map(thriftMessage);
            var response = messageReceiver.Send(message);

            return(MessageMapper.Map(response).As <ThriftMessage>());
        }
Beispiel #3
0
        public void Set_Message()
        {
            var houseDto   = GetHouseDto();
            var bodyStream = ThriftSerializer.Serialize(houseDto);
            var message    = new Message(bodyStream);

            var thriftMessage = new ThriftMessage <HouseDto>(message);

            thriftMessage.BodyStream.ShouldNotBe(null);
        }
Beispiel #4
0
        /// <summary>
        ///     激活一个事务,并尝试处理该事务的响应消息流程
        /// </summary>
        /// <param name="identity">网络事务唯一标识</param>
        /// <param name="response">应答消息</param>
        public void Active(TransactionIdentity identity, ThriftMessage response)
        {
            ThriftMessageTransaction transaction;

            if (!_transactions.TryRemove(identity, out transaction))
            {
                return;
            }
            transaction.SetResponse(response);
        }
Beispiel #5
0
 private static void AssertProperties(ThriftMessage <HouseDto> thriftMessage,
                                      Dictionary <string, object> properties)
 {
     thriftMessage.Properties.Count.ShouldBe(properties.Count);
     foreach (var property in thriftMessage.Properties)
     {
         var key = property.Key;
         properties.ContainsKey(key).ShouldBe(true);
         var value = property.Value;
         value.ShouldBe(properties[key]);
     }
 }
Beispiel #6
0
        public void Set_Content_And_Properties()
        {
            var properties = new Dictionary <string, object>()
            {
                { "whatever", 1 }
            };
            string sessionId     = Guid.NewGuid().ToString();
            string label         = Guid.NewGuid().ToString();
            var    houseDto      = GetHouseDto();
            var    thriftMessage = new ThriftMessage <HouseDto>(houseDto, sessionId, label, properties);

            thriftMessage.SessionId.ShouldBe(sessionId);
            thriftMessage.Label.ShouldBe(label);
            AssertProperties(thriftMessage, properties);
        }
Beispiel #7
0
        public void Set_Message_And_Properties()
        {
            var houseDto   = GetHouseDto();
            var properties = new Dictionary <string, object>()
            {
                { "whatever", 1 }
            };
            string sessionId  = Guid.NewGuid().ToString();
            string label      = Guid.NewGuid().ToString();
            var    bodyStream = ThriftSerializer.Serialize(houseDto);
            var    message    = new Message(bodyStream, sessionId, label, properties);

            var thriftMessage = new ThriftMessage <HouseDto>(message);

            thriftMessage.Label.ShouldBe(label);
            thriftMessage.SessionId.ShouldBe(sessionId);
            thriftMessage.Label.ShouldBe(label);
            AssertProperties(thriftMessage, properties);
        }
        protected override IByteBuffer Encode(IChannelHandlerContext context, ThriftMessage message)
        {
            int frameSize = message.Buffer.ReadableBytes;

            if (message.Buffer.ReadableBytes > _maxFrameSize)
            {
                context.FireExceptionCaught(new TooLongFrameException(
                                                String.Format(
                                                    "Frame size exceeded on encode: frame was {0:d} bytes, maximum allowed is {1:d} bytes",
                                                    frameSize,
                                                    _maxFrameSize)));
                return(null);
            }

            switch (message.TransportType)
            {
            case ThriftTransportType.Unframed:
                return(message.Buffer);

            case ThriftTransportType.Framed:
                var buffer = Unpooled.Buffer(4 + message.Buffer.ReadableBytes, 4 + message.Buffer.ReadableBytes);
                buffer.WriteInt(message.Buffer.ReadableBytes);
                buffer.WriteBytes(message.Buffer, message.Buffer.ReadableBytes);
                return(buffer);

            //return Buffers.WrappedBuffer(context.Allocator, buffer, message.Buffer);

            case ThriftTransportType.Header:
                throw new NotSupportedException("Header transport is not supported");

            case ThriftTransportType.Http:
                throw new NotSupportedException("HTTP transport is not supported");

            default:
                throw new NotSupportedException("Unrecognized transport type");
            }
        }
 /// <summary>
 ///     激活一个事务,并尝试处理该事务的响应消息流程
 /// </summary>
 /// <param name="identity">网络事务唯一标识</param>
 /// <param name="response">应答消息</param>
 public void Active(TransactionIdentity identity, ThriftMessage response)
 {
     ThriftMessageTransaction transaction;
     if (!_transactions.TryRemove(identity, out transaction)) return;
     transaction.SetResponse(response);
 }