コード例 #1
0
ファイル: StompWireFormat.cs プロジェクト: DaveSenn/Stomp.Net
    protected virtual ICommand ReadConnected(StompFrame frame)
    {
        _remoteWireFormatInfo = new();

        if (frame.HasProperty(PropertyKeys.Version))
        {
            _remoteWireFormatInfo.Version = Single.Parse(frame.RemoveProperty(PropertyKeys.Version), CultureInfo.InvariantCulture);
            if (_remoteWireFormatInfo.Version > 1.0f)
            {
                _encodeHeaders = true;
            }

            if (frame.HasProperty(PropertyKeys.Session))
            {
                _remoteWireFormatInfo.Session = frame.RemoveProperty(PropertyKeys.Session);
            }

            if (frame.HasProperty(PropertyKeys.HartBeat))
            {
                var hearBeats = frame.RemoveProperty(PropertyKeys.HartBeat)
                                .Split(",".ToCharArray());
                if (hearBeats.Length != 2)
                {
                    throw new IoException("Malformed heartbeat property in Connected Frame.");
                }

                _remoteWireFormatInfo.WriteCheckInterval = Int32.Parse(hearBeats[0]
                                                                       .Trim());
                _remoteWireFormatInfo.ReadCheckInterval = Int32.Parse(hearBeats[1]
                                                                      .Trim());
            }
        }
        else
        {
            _remoteWireFormatInfo.ReadCheckInterval  = 0;
            _remoteWireFormatInfo.WriteCheckInterval = 0;
            _remoteWireFormatInfo.Version            = 1.0f;
        }

        if (_connectedResponseId != -1)
        {
            var answer = new Response {
                CorrelationId = _connectedResponseId
            };
            SendCommand(answer);
            _connectedResponseId = -1;
        }
        else
        {
            throw new IoException("Received Connected Frame without a set Response Id for it.");
        }

        return(_remoteWireFormatInfo);
    }
コード例 #2
0
ファイル: StompWireFormat.cs プロジェクト: DaveSenn/Stomp.Net
    protected virtual ICommand CreateCommand(StompFrame frame)
    {
        var command = frame.Command;

        switch (command)
        {
        case "RECEIPT":
        {
            var text = frame.RemoveProperty(PropertyKeys.ReceiptId);
            if (text != null)
            {
                var answer = new Response();
                if (text.StartsWith("ignore:", StringComparison.Ordinal))
                {
                    text = text.Substring("ignore:".Length);
                }

                answer.CorrelationId = Int32.Parse(text);
                return(answer);
            }
        }
        break;

        case "CONNECTED":
            return(ReadConnected(frame));

        case "ERROR":
        {
            var text = frame.RemoveProperty(PropertyKeys.ReceiptId);

            if (text?.StartsWith("ignore:", StringComparison.Ordinal) == true)
            {
                return new Response {
                           CorrelationId = Int32.Parse(text.Substring("ignore:".Length))
                }
            }
            ;

            var answer = new ExceptionResponse();
            if (text != null)
            {
                answer.CorrelationId = Int32.Parse(text);
            }

            var error = new BrokerError {
                Message = frame.RemoveProperty(PropertyKeys.Message)
            };
            answer.Exception = error;
            return(answer);
        }

        case "KEEPALIVE":
            return(new KeepAliveInfo());

        case "MESSAGE":
            return(ReadMessage(frame));
        }

        if (Tracer.IsErrorEnabled)
        {
            Tracer.Error("Unknown command: " + frame.Command + " headers: " + frame.Properties);
        }

        return(null);
    }
コード例 #3
0
ファイル: StompWireFormat.cs プロジェクト: DaveSenn/Stomp.Net
    protected virtual ICommand ReadMessage(StompFrame frame)
    {
        frame.RemoveProperty(PropertyKeys.Transformation);

        var message = new BytesMessage {
            Content = frame.Content
        };

        // Remove any receipt header we might have attached if the outbound command was
        // sent with response required set to true
        frame.RemoveProperty(PropertyKeys.Receipt);

        // Clear any attached content length headers as they aren't needed anymore and can
        // clutter the Message Properties.
        frame.RemoveProperty(PropertyKeys.ContentLength);

        message.Type             = frame.RemoveProperty(PropertyKeys.Type);
        message.Destination      = Destination.ConvertToDestination(frame.RemoveProperty(PropertyKeys.Destination), SkipDestinationNameFormatting);
        message.ReplyTo          = Destination.ConvertToDestination(frame.RemoveProperty(PropertyKeys.ReplyTo), SkipDestinationNameFormatting);
        message.TargetConsumerId = new(frame.RemoveProperty(PropertyKeys.Subscription));
        message.CorrelationId    = frame.RemoveProperty(PropertyKeys.CorrelationId);
        message.MessageId        = new(frame.RemoveProperty(PropertyKeys.MessageId));
        message.Persistent       = StompHelper.ToBool(frame.RemoveProperty(PropertyKeys.Persistent), false);

        // If it came from NMS.Stomp we added this header to ensure its reported on the
        // receiver side.
        if (frame.HasProperty(PropertyKeys.NmsxDeliveryMode))
        {
            message.Persistent = StompHelper.ToBool(frame.RemoveProperty(PropertyKeys.NmsxDeliveryMode), false);
        }

        if (frame.HasProperty(PropertyKeys.Priority))
        {
            message.Priority = Byte.Parse(frame.RemoveProperty(PropertyKeys.Priority));
        }

        if (frame.HasProperty(PropertyKeys.TimeStamp))
        {
            message.Timestamp = Int64.Parse(frame.RemoveProperty(PropertyKeys.TimeStamp));
        }

        if (frame.HasProperty(PropertyKeys.Expires))
        {
            message.Expiration = Int64.Parse(frame.RemoveProperty(PropertyKeys.Expires));
        }

        if (frame.RemoveProperty(PropertyKeys.Redelivered) != null)
        {
            message.RedeliveryCounter = 1;
        }

        // now lets add the generic headers
        foreach (var key in frame.Properties.Keys)
        {
            var value = frame.Properties[key];
            message.Headers[key] = value;
        }

        return(new MessageDispatch(message.TargetConsumerId, message.Destination, message, message.RedeliveryCounter));
    }