public AmqpLink CreateLink(AmqpSession session, AmqpLinkSettings settings) { AmqpLink link; if (settings.Role.Value) { var receiver = new ReceivingAmqpLink(session, settings); receiver.RegisterMessageListener(m => { this.messages.Enqueue(m.Clone()); receiver.AcceptMessage(m, true, true); m.Dispose(); }); link = receiver; } else { var sender = new SendingAmqpLink(session, settings); sender.RegisterCreditListener((credit, drain, tx) => { AmqpMessage message = this.messages.Dequeue(); message.DeliveryAnnotations.Map["x-opt-sequence-number"] = 1; sender.SendMessageNoWait(message, EmptyBinary, NullBinary); }); sender.RegisterDispositionListener(d => { sender.DisposeDelivery(d, true, d.State); }); link = sender; } return(link); }