public IAsyncResult BeginDischange(ArraySegment<byte> txnId, bool fail, TimeSpan timeout, AsyncCallback callback, object state) { AmqpTrace.Provider.AmqpLogOperationInformational(this, TraceOperation.Execute, "BeginDischange"); Discharge discharge = new Discharge() { TxnId = txnId, Fail = fail }; AmqpMessage message = Controller.CreateCommandMessage(discharge); return this.sendLink.BeginSendMessage(message, this.GetDeliveryTag(), AmqpConstants.NullBinary, timeout, callback, state); }
static void OnMessage(ListenerLink link, Message message, DeliveryState deliveryState, object state) { var thisPtr = (TxnManager)state; object body; try { body = Message.Decode(((BrokerMessage)message).Buffer).Body; } catch (Exception exception) { Trace.WriteLine(TraceLevel.Error, exception.Message); link.DisposeMessage( message, new Rejected() { Error = new Error() { Condition = ErrorCode.DecodeError, Description = "Cannot decode txn message" } }, true); return; } if (body is Declare) { int txnId = thisPtr.CreateTransaction(); var outcome = new Declared() { TxnId = BitConverter.GetBytes(txnId) }; link.DisposeMessage(message, outcome, true); } else if (body is Discharge) { Discharge discharge = (Discharge)body; int txnId = BitConverter.ToInt32(discharge.TxnId, 0); Transaction txn; if (thisPtr.transactions.TryGetValue(txnId, out txn)) { lock (thisPtr.transactions) { thisPtr.transactions.Remove(txnId); } txn.Discharge(discharge.Fail); link.DisposeMessage(message, new Accepted(), true); } else { link.DisposeMessage( message, new Rejected() { Error = new Error() { Condition = ErrorCode.NotFound, Description = "Transaction not found" } }, true); } } else { link.DisposeMessage( message, new Rejected() { Error = new Error() { Condition = ErrorCode.NotImplemented, Description = "Unsupported message body" } }, true); } }