Esempio n. 1
0
        protected virtual void WriteConnectionInfo(ConnectionInfo command, BinaryWriter dataOut)
        {
            // lets force a receipt for the Connect Frame.

            StompFrame frame = new StompFrame("CONNECT");

            frame.SetProperty("client-id", command.ClientId);
            frame.SetProperty("login", command.UserName);
            frame.SetProperty("passcode", command.Password);
            frame.SetProperty("request-id", command.CommandId);
            frame.SetProperty("host", command.Host);
            frame.SetProperty("accept-version", "1.0,1.1");

            if (command.MaxInactivityDuration != 0)
            {
                frame.SetProperty("heart-beat", command.WriteCheckInterval + "," + command.ReadCheckInterval);
            }

            if (Tracer.IsDebugEnabled)
            {
                Tracer.Debug("StompWireFormat - Writing " + frame.ToString());
            }

            frame.ToStream(dataOut);
        }
Esempio n. 2
0
        protected virtual void WriteKeepAliveInfo(KeepAliveInfo command, BinaryWriter dataOut)
        {
            StompFrame frame = new StompFrame(StompFrame.KEEPALIVE);

            if (Tracer.IsDebugEnabled)
            {
                Tracer.Debug("StompWireFormat - Writing " + frame.ToString());
            }

            frame.ToStream(dataOut);
        }
Esempio n. 3
0
        protected virtual void WriteShutdownInfo(ShutdownInfo command, BinaryWriter dataOut)
        {
            System.Diagnostics.Debug.Assert(!command.ResponseRequired);

            StompFrame frame = new StompFrame("DISCONNECT");

            if (Tracer.IsDebugEnabled)
            {
                Tracer.Debug("StompWireFormat - Writing " + frame.ToString());
            }

            frame.ToStream(dataOut);
        }
Esempio n. 4
0
        protected virtual void WriteRemoveInfo(RemoveInfo command, BinaryWriter dataOut)
        {
            StompFrame frame = new StompFrame("UNSUBSCRIBE");
            object     id    = command.ObjectId;

            if (id is ConsumerId)
            {
                ConsumerId consumerId = id as ConsumerId;
                if (command.ResponseRequired)
                {
                    frame.SetProperty("receipt", command.CommandId);
                }
                frame.SetProperty("id", consumerId.ToString());

                if (Tracer.IsDebugEnabled)
                {
                    Tracer.Debug("StompWireFormat - Writing " + frame.ToString());
                }

                frame.ToStream(dataOut);
            }
        }
Esempio n. 5
0
        protected virtual void WriteMessageAck(MessageAck command, BinaryWriter dataOut)
        {
            StompFrame frame = new StompFrame("ACK");

            if (command.ResponseRequired)
            {
                frame.SetProperty("receipt", "ignore:" + command.CommandId);
            }

            frame.SetProperty("message-id", command.LastMessageId.ToString());

            if (command.TransactionId != null)
            {
                frame.SetProperty("transaction", command.TransactionId.ToString());
            }

            if (Tracer.IsDebugEnabled)
            {
                Tracer.Debug("StompWireFormat - Writing " + frame.ToString());
            }

            frame.ToStream(dataOut);
        }
Esempio n. 6
0
        protected virtual void WriteTransactionInfo(TransactionInfo command, BinaryWriter dataOut)
        {
            string          type            = "BEGIN";
            TransactionType transactionType = (TransactionType)command.Type;

            switch (transactionType)
            {
            case TransactionType.Commit:
                command.ResponseRequired = true;
                type = "COMMIT";
                break;

            case TransactionType.Rollback:
                command.ResponseRequired = true;
                type = "ABORT";
                break;
            }

            Tracer.Debug("StompWireFormat - For transaction type: " + transactionType +
                         " we are using command type: " + type);

            StompFrame frame = new StompFrame(type);

            if (command.ResponseRequired)
            {
                frame.SetProperty("receipt", command.CommandId);
            }

            frame.SetProperty("transaction", command.TransactionId.ToString());

            if (Tracer.IsDebugEnabled)
            {
                Tracer.Debug("StompWireFormat - Writing " + frame.ToString());
            }

            frame.ToStream(dataOut);
        }
Esempio n. 7
0
        protected virtual void WriteConsumerInfo(ConsumerInfo command, BinaryWriter dataOut)
        {
            StompFrame frame = new StompFrame("SUBSCRIBE");

            if (command.ResponseRequired)
            {
                frame.SetProperty("receipt", command.CommandId);
            }

            frame.SetProperty("destination", Destination.ConvertToStompString(command.Destination));
            frame.SetProperty("id", command.ConsumerId.ToString());
            frame.SetProperty("durable-subscriber-name", command.SubscriptionName);
            frame.SetProperty("selector", command.Selector);
            frame.SetProperty("ack", StompHelper.ToStomp(command.AckMode));

            if (command.NoLocal)
            {
                frame.SetProperty("no-local", command.NoLocal.ToString());
            }

            // ActiveMQ extensions to STOMP

            if (command.Transformation != null)
            {
                frame.SetProperty("transformation", command.Transformation);
            }
            else
            {
                frame.SetProperty("transformation", "jms-xml");
            }

            frame.SetProperty("activemq.dispatchAsync", command.DispatchAsync);

            if (command.Exclusive)
            {
                frame.SetProperty("activemq.exclusive", command.Exclusive);
            }

            if (command.SubscriptionName != null)
            {
                frame.SetProperty("activemq.subscriptionName", command.SubscriptionName);
                // For an older 4.0 broker we need to set this header so they get the
                // subscription as well..
                frame.SetProperty("activemq.subcriptionName", command.SubscriptionName);
            }

            frame.SetProperty("activemq.maximumPendingMessageLimit", command.MaximumPendingMessageLimit);
            frame.SetProperty("activemq.prefetchSize", command.PrefetchSize);
            frame.SetProperty("activemq.priority", command.Priority);

            if (command.Retroactive)
            {
                frame.SetProperty("activemq.retroactive", command.Retroactive);
            }

            if (Tracer.IsDebugEnabled)
            {
                Tracer.Debug("StompWireFormat - Writing " + frame.ToString());
            }

            frame.ToStream(dataOut);
        }
Esempio n. 8
0
        protected virtual void WriteMessage(Message command, BinaryWriter dataOut)
        {
            StompFrame frame = new StompFrame("SEND");

            if (command.ResponseRequired)
            {
                frame.SetProperty("receipt", command.CommandId);
            }

            frame.SetProperty("destination", Destination.ConvertToStompString(command.Destination));

            if (command.ReplyTo != null)
            {
                frame.SetProperty("reply-to", Destination.ConvertToStompString(command.ReplyTo));
            }
            if (command.CorrelationId != null)
            {
                frame.SetProperty("correlation-id", command.CorrelationId);
            }
            if (command.Expiration != 0)
            {
                frame.SetProperty("expires", command.Expiration);
            }
            if (command.Timestamp != 0)
            {
                frame.SetProperty("timestamp", command.Timestamp);
            }
            if (command.Priority != 4)
            {
                frame.SetProperty("priority", command.Priority);
            }
            if (command.Type != null)
            {
                frame.SetProperty("type", command.Type);
            }
            if (command.TransactionId != null)
            {
                frame.SetProperty("transaction", command.TransactionId.ToString());
            }

            frame.SetProperty("persistent", command.Persistent.ToString().ToLower());
            frame.SetProperty("NMSXDeliveryMode", command.Persistent.ToString().ToLower());

            if (command.NMSXGroupID != null)
            {
                frame.SetProperty("JMSXGroupID", command.NMSXGroupID);
                frame.SetProperty("NMSXGroupID", command.NMSXGroupID);
                frame.SetProperty("JMSXGroupSeq", command.NMSXGroupSeq);
                frame.SetProperty("NMSXGroupSeq", command.NMSXGroupSeq);
            }

            // Perform any Content Marshaling.
            command.BeforeMarshall(this);

            // Store the Marshaled Content.
            frame.Content = command.Content;

            if (command is BytesMessage)
            {
                if (command.Content != null && command.Content.Length > 0)
                {
                    frame.SetProperty("content-length", command.Content.Length);
                }

                frame.SetProperty("transformation", "jms-byte");
            }
            else if (command is MapMessage)
            {
                frame.SetProperty("transformation", this.mapMarshaler.Name);
            }

            // Marshal all properties to the Frame.
            IPrimitiveMap map = command.Properties;

            foreach (string key in map.Keys)
            {
                frame.SetProperty(key, map[key]);
            }

            if (Tracer.IsDebugEnabled)
            {
                Tracer.Debug("StompWireFormat - Writing " + frame.ToString());
            }

            frame.ToStream(dataOut);
        }
Esempio n. 9
0
        protected virtual Object CreateCommand(StompFrame frame)
        {
            string command = frame.Command;

            if (Tracer.IsDebugEnabled)
            {
                Tracer.Debug("StompWireFormat - Received " + frame.ToString());
            }

            if (command == "RECEIPT")
            {
                string text = frame.RemoveProperty("receipt-id");
                if (text != null)
                {
                    Response answer = new Response();
                    if (text.StartsWith("ignore:"))
                    {
                        text = text.Substring("ignore:".Length);
                    }

                    answer.CorrelationId = Int32.Parse(text);
                    return(answer);
                }
            }
            else if (command == "CONNECTED")
            {
                return(ReadConnected(frame));
            }
            else if (command == "ERROR")
            {
                string text = frame.RemoveProperty("receipt-id");

                if (text != null && text.StartsWith("ignore:"))
                {
                    Response answer = new Response();
                    answer.CorrelationId = Int32.Parse(text.Substring("ignore:".Length));
                    return(answer);
                }
                else
                {
                    ExceptionResponse answer = new ExceptionResponse();
                    if (text != null)
                    {
                        answer.CorrelationId = Int32.Parse(text);
                    }

                    BrokerError error = new BrokerError();
                    error.Message    = frame.RemoveProperty("message");
                    answer.Exception = error;
                    return(answer);
                }
            }
            else if (command == "KEEPALIVE")
            {
                return(new KeepAliveInfo());
            }
            else if (command == "MESSAGE")
            {
                return(ReadMessage(frame));
            }

            Tracer.Error("Unknown command: " + frame.Command + " headers: " + frame.Properties);

            return(null);
        }