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); }
protected virtual void WriteRemoveInfo(RemoveInfo command, BinaryWriter dataOut) { var frame = new StompFrame("UNSUBSCRIBE", _encodeHeaders); Object id = command.ObjectId; if (!(id is ConsumerId)) { return; } var consumerId = id as ConsumerId; if (command.ResponseRequired) { frame.SetProperty(PropertyKeys.Receipt, command.CommandId); } frame.SetProperty(PropertyKeys.Id, consumerId.ToString()); frame.ToStream(dataOut); }
protected virtual ICommand CreateCommand(StompFrame frame) { var command = frame.Command; switch (command) { case "RECEIPT": { var text = frame.RemoveProperty(PropertyKeys.ReceiptId); if (text != null) { var answer = new Response(); if (text.StartsWith("ignore:", StringComparison.Ordinal)) { text = text.Substring("ignore:".Length); } answer.CorrelationId = Int32.Parse(text); return(answer); } } break; case "CONNECTED": return(ReadConnected(frame)); case "ERROR": { var text = frame.RemoveProperty(PropertyKeys.ReceiptId); if (text?.StartsWith("ignore:", StringComparison.Ordinal) == true) { return new Response { CorrelationId = Int32.Parse(text.Substring("ignore:".Length)) } } ; var answer = new ExceptionResponse(); if (text != null) { answer.CorrelationId = Int32.Parse(text); } var error = new BrokerError { Message = frame.RemoveProperty(PropertyKeys.Message) }; answer.Exception = error; return(answer); } case "KEEPALIVE": return(new KeepAliveInfo()); case "MESSAGE": return(ReadMessage(frame)); } if (Tracer.IsErrorEnabled) { Tracer.Error("Unknown command: " + frame.Command + " headers: " + frame.Properties); } return(null); }
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); }
protected virtual void WriteKeepAliveInfo(KeepAliveInfo command, BinaryWriter dataOut) { var frame = new StompFrame(StompFrame.Keepalive, _encodeHeaders); frame.ToStream(dataOut); }
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); }
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); }