Exemple #1
0
        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));
        }
Exemple #2
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 #3
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 #4
0
        protected virtual ICommand ReadMessage(StompFrame frame)
        {
            Message message;

            frame.RemoveProperty("transformation");

            if (frame.HasProperty("content-length"))
            {
                message = new BytesMessage {
                    Content = frame.Content
                }
            }
            ;
            else
            {
                message = new TextMessage(Encoding.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");

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

            message.Type             = frame.RemoveProperty("type");
            message.Destination      = Destination.ConvertToDestination(frame.RemoveProperty("destination"));
            message.ReplyTo          = Destination.ConvertToDestination(frame.RemoveProperty("reply-to"));
            message.TargetConsumerId = new ConsumerId(frame.RemoveProperty("subscription"));
            message.CorrelationId    = frame.RemoveProperty("correlation-id");
            message.MessageId        = new MessageId(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)
            {
                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;
            }

            var dispatch = new MessageDispatch
            {
                Message           = message,
                ConsumerId        = message.TargetConsumerId,
                Destination       = message.Destination,
                RedeliveryCounter = message.RedeliveryCounter
            };

            return(dispatch);
        }