protected virtual void WriteMessage(ActiveMQMessage command, StompFrameStream ss) { ss.WriteCommand(command, "SEND"); ss.WriteHeader("destination", StompHelper.ToStomp(command.Destination)); if (command.ReplyTo != null) { ss.WriteHeader("reply-to", StompHelper.ToStomp(command.ReplyTo)); } if (command.CorrelationId != null) { ss.WriteHeader("correlation-id", command.CorrelationId); } if (command.Expiration != 0) { ss.WriteHeader("expires", command.Expiration); } if (command.Priority != 4) { ss.WriteHeader("priority", command.Priority); } if (command.Type != null) { ss.WriteHeader("type", command.Type); } if (command.TransactionId != null) { ss.WriteHeader("transaction", StompHelper.ToStomp(command.TransactionId)); } ss.WriteHeader("persistent", command.Persistent); // lets force the content to be marshalled command.BeforeMarshall(null); if (command is ActiveMQTextMessage) { ActiveMQTextMessage textMessage = command as ActiveMQTextMessage; ss.Content = encoding.GetBytes(textMessage.Text); } else { ss.Content = command.Content; if (null != command.Content) { ss.ContentLength = command.Content.Length; } else { ss.ContentLength = 0; } } IPrimitiveMap map = command.Properties; foreach (string key in map.Keys) { ss.WriteHeader(key, map[key]); } ss.Flush(); }
protected virtual void WriteTransactionInfo(TransactionInfo command, StompFrameStream ss) { TransactionId id = command.TransactionId; if (id is LocalTransactionId) { string type = "BEGIN"; TransactionType transactionType = (TransactionType)command.Type; switch (transactionType) { case TransactionType.CommitOnePhase: command.ResponseRequired = true; type = "COMMIT"; break; case TransactionType.Rollback: command.ResponseRequired = true; type = "ABORT"; break; } Tracer.Debug(">>> For transaction type: " + transactionType + " we are using command type: " + type); ss.WriteCommand(command, type); ss.WriteHeader("transaction", StompHelper.ToStomp(id)); ss.Flush(); } }
protected virtual void WriteConsumerInfo(ConsumerInfo command, StompFrameStream ss) { ss.WriteCommand(command, "SUBSCRIBE"); ss.WriteHeader("destination", StompHelper.ToStomp(command.Destination)); ss.WriteHeader("id", StompHelper.ToStomp(command.ConsumerId)); ss.WriteHeader("durable-subscriber-name", command.SubscriptionName); ss.WriteHeader("selector", command.Selector); if (command.NoLocal) { ss.WriteHeader("no-local", command.NoLocal); } ss.WriteHeader("ack", "client"); // ActiveMQ extensions to STOMP ss.WriteHeader("activemq.dispatchAsync", command.DispatchAsync); if (command.Exclusive) { ss.WriteHeader("activemq.exclusive", command.Exclusive); } ss.WriteHeader("activemq.maximumPendingMessageLimit", command.MaximumPendingMessageLimit); ss.WriteHeader("activemq.prefetchSize", command.PrefetchSize); ss.WriteHeader("activemq.priority", command.Priority); if (command.Retroactive) { ss.WriteHeader("activemq.retroactive", command.Retroactive); } consumers[command.ConsumerId] = command.ConsumerId; ss.Flush(); }
protected virtual void WriteMessageAck(MessageAck command, StompFrameStream ss) { ss.WriteCommand(command, "ACK", true); // TODO handle bulk ACKs? ss.WriteHeader("message-id", StompHelper.ToStomp(command.LastMessageId)); if (command.TransactionId != null) { ss.WriteHeader("transaction", StompHelper.ToStomp(command.TransactionId)); } ss.Flush(); }
public void Marshal(Object o, BinaryWriter binaryWriter) { Tracer.Debug(">>>> " + o); StompFrameStream ds = new StompFrameStream(binaryWriter, encoding); if (o is ConnectionInfo) { WriteConnectionInfo((ConnectionInfo)o, ds); } else if (o is ActiveMQMessage) { WriteMessage((ActiveMQMessage)o, ds); } else if (o is ConsumerInfo) { WriteConsumerInfo((ConsumerInfo)o, ds); } else if (o is MessageAck) { WriteMessageAck((MessageAck)o, ds); } else if (o is TransactionInfo) { WriteTransactionInfo((TransactionInfo)o, ds); } else if (o is ShutdownInfo) { WriteShutdownInfo((ShutdownInfo)o, ds); } else if (o is RemoveInfo) { WriteRemoveInfo((RemoveInfo)o, ds); } else if (o is Command) { Command command = o as Command; if (command.ResponseRequired) { Response response = new Response(); response.CorrelationId = command.CommandId; SendCommand(response); Tracer.Debug("#### Autorespond to command: " + o.GetType()); } } else { Tracer.Debug("#### Ignored command: " + o.GetType()); } }
protected virtual void WriteConnectionInfo(ConnectionInfo command, StompFrameStream ss) { // lets force a receipt command.ResponseRequired = true; ss.WriteCommand(command, "CONNECT"); ss.WriteHeader("client-id", command.ClientId); ss.WriteHeader("login", command.UserName); ss.WriteHeader("passcode", command.Password); if (command.ResponseRequired) { ss.WriteHeader("request-id", command.CommandId); } ss.Flush(); }
protected virtual void WriteRemoveInfo(RemoveInfo command, StompFrameStream ss) { object id = command.ObjectId; if (id is ConsumerId) { ConsumerId consumerId = id as ConsumerId; ss.WriteCommand(command, "UNSUBSCRIBE"); ss.WriteHeader("id", StompHelper.ToStomp(consumerId)); ss.Flush(); consumers.Remove(consumerId); } else if (id is SessionId) { // When a session is removed, it needs to remove it's consumers too. // Find all the consumer that were part of the session. SessionId sessionId = (SessionId)id; ArrayList matches = new ArrayList(); foreach (DictionaryEntry entry in consumers) { ConsumerId t = (ConsumerId)entry.Key; if (sessionId.ConnectionId == t.ConnectionId && sessionId.Value == t.SessionId) { matches.Add(t); } } bool unsubscribedConsumer = false; // Un-subscribe them. foreach (ConsumerId consumerId in matches) { ss.WriteCommand(command, "UNSUBSCRIBE"); ss.WriteHeader("id", StompHelper.ToStomp(consumerId)); ss.Flush(); consumers.Remove(consumerId); unsubscribedConsumer = true; } if (!unsubscribedConsumer && command.ResponseRequired) { ss.WriteCommand(command, "UNSUBSCRIBE", true); ss.WriteHeader("id", sessionId); ss.Flush(); } } else if (id is ProducerId) { if (command.ResponseRequired) { ss.WriteCommand(command, "UNSUBSCRIBE", true); ss.WriteHeader("id", id); ss.Flush(); } } else if (id is ConnectionId) { if (command.ResponseRequired) { ss.WriteCommand(command, "UNSUBSCRIBE", true); ss.WriteHeader("id", id); ss.Flush(); } } }
protected virtual void WriteShutdownInfo(ShutdownInfo command, StompFrameStream ss) { ss.WriteCommand(command, "DISCONNECT"); System.Diagnostics.Debug.Assert(!command.ResponseRequired); ss.Flush(); }