Exemple #1
0
        protected virtual void WriteConnectionInfo(ConnectionInfo command, BinaryWriter dataOut)
        {
            // lets force a receipt for the Connect Frame.
            var frame = new StompFrame("CONNECT", _encodeHeaders);

            frame.SetProperty(PropertyKeys.ClientId, command.ClientId);
            if (command.UserName.IsNotEmpty())
            {
                frame.SetProperty(PropertyKeys.Login, command.UserName);
            }
            if (command.Password.IsNotEmpty())
            {
                frame.SetProperty(PropertyKeys.Passcode, command.Password);
            }

            if (SetHostHeader)
            {
                frame.SetProperty(PropertyKeys.Host, HostHeaderOverride ?? command.Host);
            }

            frame.SetProperty(PropertyKeys.AcceptVersion, "1.0,1.1");

            if (MaxInactivityDuration != 0)
            {
                frame.SetProperty(PropertyKeys.HartBeat, WriteCheckInterval + "," + ReadCheckInterval);
            }

            _connectedResponseId = command.CommandId;

            frame.ToStream(dataOut);
        }
Exemple #2
0
        protected virtual void WriteTransactionInfo(TransactionInfo command, BinaryWriter dataOut)
        {
            String type;

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

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

            case TransactionType.Begin:
                type = "BEGIN";
                break;

            default:
                throw new ArgumentOutOfRangeException();
            }

            var frame = new StompFrame(type, _encodeHeaders);

            if (command.ResponseRequired)
            {
                frame.SetProperty(PropertyKeys.Receipt, command.CommandId);
            }

            frame.SetProperty(PropertyKeys.Transaction, command.TransactionId.ToString());

            frame.ToStream(dataOut);
        }
Exemple #3
0
        protected virtual void WriteConnectionInfo(ConnectionInfo command, BinaryWriter dataOut)
        {
            // lets force a receipt for the Connect Frame.
            var frame = new StompFrame("CONNECT", _encodeHeaders);

            frame.SetProperty("client-id", command.ClientId);
            if (command.UserName.IsNotEmpty())
            {
                frame.SetProperty("login", command.UserName);
            }
            if (command.Password.IsNotEmpty())
            {
                frame.SetProperty("passcode", command.Password);
            }
            frame.SetProperty("host", command.Host);
            frame.SetProperty("accept-version", "1.0,1.1");

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

            _connectedResponseId = command.CommandId;

            frame.ToStream(dataOut);
        }
Exemple #4
0
        protected virtual void WriteShutdownInfo(ShutdownInfo command, BinaryWriter dataOut)
        {
            Debug.Assert(!command.ResponseRequired);

            var frame = new StompFrame("DISCONNECT", _encodeHeaders);

            frame.ToStream(dataOut);
        }
Exemple #5
0
        protected virtual void WriteConsumerInfo(ConsumerInfo command, BinaryWriter dataOut)
        {
            var frame = new StompFrame("SUBSCRIBE", _encodeHeaders);

            if (command.ResponseRequired)
            {
                frame.SetProperty(PropertyKeys.Receipt, command.CommandId);
            }

            frame.SetProperty(PropertyKeys.Destination, command.Destination?.ConvertToStompString());
            frame.SetProperty(PropertyKeys.Id, command.ConsumerId.ToString());
            frame.SetProperty(PropertyKeys.DurableSubscriberName, command.SubscriptionName);
            frame.SetProperty(PropertyKeys.Selector, command.Selector);
            frame.SetProperty(PropertyKeys.Ack, StompHelper.ToStomp(command.AckMode));

            if (command.NoLocal)
            {
                frame.SetProperty(PropertyKeys.NoLocal, command.NoLocal.ToString());
            }

            // ActiveMQ extensions to STOMP
            frame.SetProperty(PropertyKeys.Transformation, command.Transformation ?? "jms-xml");

            frame.SetProperty(PropertyKeys.ActivemqDispatchAsync, command.DispatchAsync);

            if (command.Exclusive)
            {
                frame.SetProperty(PropertyKeys.ActivemqExclusive, command.Exclusive);
            }

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

            frame.SetProperty(PropertyKeys.ActivemqMaximumPendingMessageLimit, command.MaximumPendingMessageLimit);
            frame.SetProperty(PropertyKeys.ActivemqPrefetchSize, command.PrefetchSize);
            frame.SetProperty(PropertyKeys.ActivemqPriority, command.Priority);

            if (command.Retroactive)
            {
                frame.SetProperty(PropertyKeys.ActivemqRetroactive, command.Retroactive);
            }

            frame.ToStream(dataOut);
        }
Exemple #6
0
        protected virtual void WriteConsumerInfo(ConsumerInfo command, BinaryWriter dataOut)
        {
            var frame = new StompFrame("SUBSCRIBE", _encodeHeaders);

            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
            frame.SetProperty("transformation", command.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);
            }

            frame.ToStream(dataOut);
        }
Exemple #7
0
        protected virtual void WriteRemoveInfo(RemoveInfo command, BinaryWriter dataOut)
        {
            var    frame = new StompFrame("UNSUBSCRIBE", _encodeHeaders);
            Object id    = command.ObjectId;

            if (id is not ConsumerId consumerId)
            {
                return;
            }
            if (command.ResponseRequired)
            {
                frame.SetProperty(PropertyKeys.Receipt, command.CommandId);
            }
            frame.SetProperty(PropertyKeys.Id, consumerId.ToString());

            frame.ToStream(dataOut);
        }
Exemple #8
0
        protected virtual void WriteMessageAck(MessageAck command, BinaryWriter dataOut)
        {
            var frame = new StompFrame("ACK", _encodeHeaders);

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

            frame.SetProperty(PropertyKeys.MessageId, command.LastMessageId.ToString());
            frame.SetProperty(PropertyKeys.Subscription, command.ConsumerId.ToString());

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

            frame.ToStream(dataOut);
        }
Exemple #9
0
        protected virtual void WriteMessage(BytesMessage command, BinaryWriter dataOut)
        {
            var frame = new StompFrame("SEND", _encodeHeaders);

            if (command.ResponseRequired)
            {
                frame.SetProperty(PropertyKeys.Receipt, command.CommandId);
            }

            frame.SetProperty(PropertyKeys.Destination, command.Destination.ConvertToStompString());

            if (command.ReplyTo != null)
            {
                frame.SetProperty(PropertyKeys.ReplyTo, command.ReplyTo.ConvertToStompString());
            }
            if (command.CorrelationId != null)
            {
                frame.SetProperty(PropertyKeys.CorrelationId, command.CorrelationId);
            }
            if (command.Expiration != 0)
            {
                frame.SetProperty(PropertyKeys.Expires, command.Expiration);
            }
            if (command.Timestamp != 0)
            {
                frame.SetProperty(PropertyKeys.TimeStamp, command.Timestamp);
            }
            if (command.Priority != 4)
            {
                frame.SetProperty(PropertyKeys.Priority, command.Priority);
            }
            if (command.Type != null)
            {
                frame.SetProperty(PropertyKeys.Type, command.Type);
            }
            if (command.TransactionId != null)
            {
                frame.SetProperty(PropertyKeys.Transaction, command.TransactionId.ToString());
            }

            frame.SetProperty(PropertyKeys.Persistent,
                              command.Persistent.ToString()
                              .ToLower());
            frame.SetProperty(PropertyKeys.NmsxDeliveryMode,
                              command.Persistent.ToString()
                              .ToLower());

            if (command.StompGroupId != null)
            {
                frame.SetProperty(PropertyKeys.JmsxGroupId, command.StompGroupId);
                frame.SetProperty(PropertyKeys.NmsxGroupId, command.StompGroupId);
                frame.SetProperty(PropertyKeys.JmsxGroupSeq, command.StompGroupSeq);
                frame.SetProperty(PropertyKeys.NmsxGroupSeq, command.StompGroupSeq);
            }

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

            if (command.Content?.Length > 0 && StompNetConfiguration.AddContentLengthHeader)
            {
                frame.SetProperty(PropertyKeys.ContentLength, command.Content.Length);
            }

            frame.SetProperty(PropertyKeys.Transformation, "jms-byte");

            // Marshal all properties to the Frame.
            var map = command.Headers;

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

            frame.ToStream(dataOut);
        }
Exemple #10
0
        protected virtual void WriteKeepAliveInfo(KeepAliveInfo command, BinaryWriter dataOut)
        {
            var frame = new StompFrame(StompFrame.Keepalive, _encodeHeaders);

            frame.ToStream(dataOut);
        }
Exemple #11
0
        protected virtual void WriteMessage(Message command, BinaryWriter dataOut)
        {
            var frame = new StompFrame("SEND", _encodeHeaders);

            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.StompGroupId != null)
            {
                frame.SetProperty("JMSXGroupID", command.StompGroupId);
                frame.SetProperty("NMSXGroupID", command.StompGroupId);
                frame.SetProperty("JMSXGroupSeq", command.StompGroupSeq);
                frame.SetProperty("NMSXGroupSeq", command.StompGroupSeq);
            }

            // 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");
            }

            // Marshal all properties to the Frame.
            var map = command.Headers;

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

            frame.ToStream(dataOut);
        }