Esempio n. 1
0
 public StompMessage Commit(string receiptId)
 {
     StompMessage msg = new StompMessage("COMMIT");
       msg["transaction"] = this.TransactionId;
       if (!string.IsNullOrEmpty(receiptId) && receiptId != "-1")
     msg["receipt"] = receiptId;
       else if (receiptId != "-1")
     msg["receipt"] = this._Client.GetNextReceiptId();
       this._Client.Execute(msg);
       return msg;
 }
 public string Serialize(StompMessage message)
 {
     StringBuilder stringBuilder = new StringBuilder();
       stringBuilder.Append(message.Command + (object) '\n');
       if (message.Transaction != null)
     message["transaction"] = message.Transaction.TransactionId;
       if (message.Headers != null)
       {
     foreach (KeyValuePair<string, string> keyValuePair in message.Headers)
       stringBuilder.Append(string.Concat(new object[4]
       {
     (object) keyValuePair.Key,
     (object) ':',
     (object) keyValuePair.Value,
     (object) '\n'
       }));
       }
       stringBuilder.Append('\n');
       stringBuilder.Append(message.Body);
       stringBuilder.Append(char.MinValue);
       return stringBuilder.ToString();
 }
 private void SendHeartbeat(object source, ElapsedEventArgs e)
 {
     StompMessage msg = new StompMessage();
       this.ExecuteWhenConnected((Action) (() => this.transport.Send(this.serializer.Serialize(msg))));
 }
 private void OnStompConnected(StompMessage obj)
 {
     this.IsConnected = true;
       if (obj.heartbeat != null && obj.heartbeat.Outgoing > 0)
       {
     string str = obj.Headers["heart-beat"];
     this.outTimer.Elapsed += new ElapsedEventHandler(this.SendHeartbeat);
     this.outTimer.Interval = (double) obj.heartbeat.Outgoing;
     this.outTimer.Enabled = true;
     this.outTimer.Start();
       }
       if (obj.heartbeat != null && obj.heartbeat.Incoming > 0)
       {
     string str = obj.Headers["heart-beat"];
     this.inTimer.Elapsed += new ElapsedEventHandler(this.ReceiveHeartbeatTimeout);
     this.inTimer.Interval = (double) obj.heartbeat.Incoming;
     this.inTimer.Enabled = true;
     this.inTimer.Start();
       }
       foreach (Action action in this._commandQueue)
     action();
       this._commandQueue.Clear();
       if (this.OnConnect == null)
     return;
       this.OnConnect(obj);
 }
 private void HandleMessage(StompMessage message)
 {
     if (message == null || message.Command == null || !this._messageConsumers.ContainsKey(message.Command))
     return;
       this._messageConsumers[message.Command](message);
 }
 public void Execute(StompMessage msg)
 {
     this.ExecuteWhenConnected((Action) (() => this.transport.Send(this.serializer.Serialize(msg))));
 }
 public StompMessage Disconnect(bool useReceipt)
 {
     StompMessage msg = new StompMessage("DISCONNECT");
       if (useReceipt)
     msg["receipt"] = "rcpt-dis";
       this.ExecuteWhenConnected((Action) (() =>
       {
     this.transport.Send(this.serializer.Serialize(msg));
     if (useReceipt)
       return;
     this.transport.Close();
     this.IsConnected = false;
       }));
       return msg;
 }
 public void Connect(string host, string login, string passcode, HeartbeatHeader heartbeatHeader)
 {
     StompMessage connectMessage = new StompMessage("CONNECT");
       connectMessage.Headers.Add("accept-version", "1.2");
       connectMessage.Headers.Add("host", host);
       if (heartbeatHeader != null)
     connectMessage.Headers.Add("heart-beat", heartbeatHeader.ToString());
       if (!string.IsNullOrEmpty(login) && !string.IsNullOrEmpty(passcode))
       {
     connectMessage.Headers.Add("login", login);
     connectMessage.Headers.Add("passcode", passcode);
       }
       this.transport.OnOpen += (Action) (() => this.transport.Send(this.serializer.Serialize(connectMessage)));
       this.transport.OnMessage += (Action<string>) (msg => this.HandleMessage(this.serializer.Deserialize(msg)));
       this.transport.Connect();
 }