public static void BasicPublishFast(this IChannel source, string exchange, string routingKey, BasicProperties properties, byte[] buffer) { source.BasicPublishFast(exchange, routingKey, mandatory: false, properties: properties, buffer: new ArraySegment <byte>(buffer)); }
private void PublishSomeMessage(IChannel channel, CancellationTokenSource cancelToken) { Task.Factory.StartNew(() => { var msgIndex = 0; while (!cancelToken.IsCancellationRequested) { Thread.Sleep(1); var index = _rnd.Next(_queues.Count); string queue = null; try { queue = _queues.Keys.ElementAt(index); } catch (Exception) { continue; } // Sends channel.BasicPublishFast("", queue, false, BasicProperties.Empty, BitConverter.GetBytes(msgIndex++)); } }, TaskCreationOptions.LongRunning); }
private async void PublishModern(string queue, IChannel channel, int howManyCalls, bool isWarmUp) { if (!isWarmUp) { _startSync.Wait(); } var message = new MessageWithTick() { IsWarmUp = isWarmUp, SomeRandomContent = "Some content not too big or too short I think", }; var stream = new MemoryStream(); for (int i = 0; i < howManyCalls; i++) { message.SentAtInTicks = Stopwatch.GetTimestamp(); stream.Position = 0; ProtoBuf.Meta.RuntimeTypeModel.Default.Serialize(stream, message); var buffer = new byte[stream.Position]; stream.Position = 0; stream.Read(buffer, 0, (int)buffer.Length); channel.BasicPublishFast("", queue, false, BasicProperties.Empty, buffer); } if (!isWarmUp) { _completionSemaphore.Release(); } }
private Func <MessageDelivery, Task> BuildConsumerFn(IChannel channel) { return(delivery => { var data = new byte[1024]; var read = 0; while (read < delivery.bodySize) { read += delivery.stream.Read(data, read, delivery.bodySize - read); } var prop = channel.RentBasicProperties(); prop.CorrelationId = delivery.properties.CorrelationId; channel.BasicPublishFast("", delivery.properties.ReplyTo, false, prop, new ArraySegment <byte>(data, 0, read)); channel.BasicAck(delivery.deliveryTag, false); return Task.CompletedTask; }); }