public void MessageIdMarshallingWorks() { ProducerId id = new ProducerId(); id.ConnectionId = "cheese"; id.SessionId = 2; id.Value = 3; MessageId mid = new MessageId(); mid.ProducerId = id; mid.BrokerSequenceId = 5; mid.ProducerSequenceId = 6; string text = StompHelper.ToStomp(mid); Assert.AreEqual("cheese:2:3:6", text, "MessageId as stomp"); MessageId mid2 = StompHelper.ToMessageId("abc:5:6:7:8"); Assert.AreEqual(8, mid2.ProducerSequenceId, "extracting mid2.ProducerSequenceId"); ProducerId another = mid2.ProducerId; Assert.AreEqual(7, another.Value, "extracting another.Value"); Assert.AreEqual(6, another.SessionId, "extracting another.SessionId"); Assert.AreEqual("abc:5", another.ConnectionId, "extracting another.ConnectionId"); }
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)); }
public void DestinationMarshallingWorks() { Assert.AreEqual("/queue/FOO.BAR", StompHelper.ToStomp(new ActiveMQQueue("FOO.BAR")), "queue"); Assert.AreEqual("/topic/FOO.BAR", StompHelper.ToStomp(new ActiveMQTopic("FOO.BAR")), "topic"); Assert.AreEqual("/temp-queue/FOO.BAR", StompHelper.ToStomp(new ActiveMQTempQueue("FOO.BAR")), "temporary queue"); Assert.AreEqual("/temp-topic/FOO.BAR", StompHelper.ToStomp(new ActiveMQTempTopic("FOO.BAR")), "temporary topic"); Assert.AreEqual(new ActiveMQQueue("FOO.BAR"), StompHelper.ToDestination("/queue/FOO.BAR"), "queue from Stomp"); Assert.AreEqual(new ActiveMQTopic("FOO.BAR"), StompHelper.ToDestination("/topic/FOO.BAR"), "topic from Stomp"); Assert.AreEqual(new ActiveMQTempQueue("FOO.BAR"), StompHelper.ToDestination("/temp-queue/FOO.BAR"), "temporary queue from Stomp"); Assert.AreEqual(new ActiveMQTempTopic("FOO.BAR"), StompHelper.ToDestination("/temp-topic/FOO.BAR"), "temporary topic from Stomp"); }
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); }
public void ConsumerIdMarshallingWorks() { ConsumerId id = new ConsumerId(); id.ConnectionId = "cheese"; id.SessionId = 2; id.Value = 3; string text = StompHelper.ToStomp(id); Assert.AreEqual("cheese:2:3", text, "ConsumerId as stomp"); ConsumerId another = StompHelper.ToConsumerId("abc:5:6"); Assert.AreEqual("abc", another.ConnectionId, "extracting consumerId.ConnectionId"); Assert.AreEqual(5, another.SessionId, "extracting consumerId.SessionId"); Assert.AreEqual(6, another.Value, "extracting consumerId.Value"); }