public void Send() { var t = new RabbitMqTransport(new EndpointAddress(_address), _factory.CreateConnection(_rabbitAddress)); t.Send((s) => { var b = Encoding.UTF8.GetBytes("dru"); s.Write(b, 0, b.Length); }); }
public async Task Send(string destinationAddress, TransportMessage message, ITransactionContext context) { // publish to delay exchange if (message.Headers != null && message.Headers.ContainsKey(Rebus.Messages.Headers.DeferredUntil)) { var defferValue = message.Headers[Rebus.Messages.Headers.DeferredUntil]; var rountingKey = message.Headers[Rebus.Messages.Headers.Type]; var defferDate = DateTime.Parse(defferValue); var defferMilleseconds = (defferDate - DateTime.Now).TotalMilliseconds; defferMilleseconds = Math.Max(0, Math.Ceiling(defferMilleseconds)); try { var connection = CreateConnection(); using (var model = connection.CreateModel()) { var props = CreateBasicProperties(model, message.Headers); props.Headers.Add("x-delay", defferMilleseconds.ToString()); props.Headers.Remove(Rebus.Messages.Headers.DeferredUntil); var mandatory = message.Headers.ContainsKey(RabbitMqHeaders.Mandatory); model.BasicPublish( exchange: delayExchangeName, routingKey: rountingKey, mandatory: mandatory, basicProperties: props, body: message.Body ); } } catch (Exception exception) { throw new RebusApplicationException(exception, $"Excanche declaration for '{delayExchangeName}' failed"); } } else { await transport.Send(destinationAddress, message, context); } }