Exemplo n.º 1
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", StompHelper.ToStomp(command.TransactionId));
            frame.ToStream(dataOut);
        }
Exemplo n.º 2
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", StompHelper.ToStomp(command.Destination));
            frame.SetProperty("id", StompHelper.ToStomp(command.ConsumerId));
            frame.SetProperty("durable-subscriber-name", command.SubscriptionName);
            frame.SetProperty("selector", command.Selector);
            frame.SetProperty("ack", StompHelper.ToStomp(command.AckMode));

            Tracer.Debug("SUBSCRIBE : Outbound AckMode = " + frame.GetProperty("ack"));

            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-map-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);
        }
Exemplo n.º 3
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", StompHelper.ToStomp(consumerId));
                frame.ToStream(dataOut);
            }
        }
Exemplo n.º 4
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", StompHelper.ToStomp(command.LastMessageId));

            Tracer.Debug("ACK - Outbound MessageId = " + frame.GetProperty("message-id"));

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

            frame.ToStream(dataOut);
        }
Exemplo n.º 5
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", StompHelper.ToStomp(command.Destination));

            if (command.ReplyTo != null)
            {
                frame.SetProperty("reply-to", StompHelper.ToStomp(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", StompHelper.ToStomp(command.TransactionId));
            }

            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]);
            }

            frame.ToStream(dataOut);
        }
Exemplo n.º 6
0
        protected virtual Command ReadMessage(StompFrame frame)
        {
            Message message        = null;
            string  transformation = frame.RemoveProperty("transformation");

            if (frame.HasProperty("content-length"))
            {
                message         = new BytesMessage();
                message.Content = frame.Content;
            }
            else if (transformation == "jms-map-xml")
            {
                message = new MapMessage(this.mapMarshaler.Unmarshal(frame.Content) as PrimitiveMap);
            }
            else
            {
                message = new TextMessage(encoder.GetString(frame.Content, 0, frame.Content.Length));
            }

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

            message.Type             = frame.RemoveProperty("type");
            message.Destination      = StompHelper.ToDestination(frame.RemoveProperty("destination"));
            message.ReplyTo          = StompHelper.ToDestination(frame.RemoveProperty("reply-to"));
            message.TargetConsumerId = StompHelper.ToConsumerId(frame.RemoveProperty("subscription"));
            message.CorrelationId    = frame.RemoveProperty("correlation-id");

            Tracer.Debug("RECV - Inbound MessageId = " + frame.GetProperty("message-id"));

            message.MessageId  = StompHelper.ToMessageId(frame.RemoveProperty("message-id"));
            message.Persistent = StompHelper.ToBool(frame.RemoveProperty("persistent"), false);

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

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

            if (frame.HasProperty("timestamp"))
            {
                message.Timestamp = Int64.Parse(frame.RemoveProperty("timestamp"));
            }

            if (frame.HasProperty("expires"))
            {
                message.Expiration = Int64.Parse(frame.RemoveProperty("expires"));
            }

            if (frame.RemoveProperty("redelivered") != null)
            {
                // We aren't told how many times that the message was redelivered so if it
                // is tagged as redelivered we always set the counter to one.
                message.RedeliveryCounter = 1;
            }

            // now lets add the generic headers
            foreach (string key in frame.Properties.Keys)
            {
                Object value = frame.Properties[key];
                if (value != null)
                {
                    // lets coerce some standard header extensions
                    if (key == "JMSXGroupSeq" || key == "NMSXGroupSeq")
                    {
                        value = Int32.Parse(value.ToString());
                        message.Properties["NMSXGroupSeq"] = value;
                        continue;
                    }
                    else if (key == "JMSXGroupID" || key == "NMSXGroupID")
                    {
                        message.Properties["NMSXGroupID"] = value;
                        continue;
                    }
                }
                message.Properties[key] = value;
            }

            MessageDispatch dispatch = new MessageDispatch();

            dispatch.Message           = message;
            dispatch.ConsumerId        = message.TargetConsumerId;
            dispatch.Destination       = message.Destination;
            dispatch.RedeliveryCounter = message.RedeliveryCounter;

            return(dispatch);
        }