public static void ProcessSingleDelivery(BasicDeliverEventArgs e) { Console.WriteLine("Delivery ========================================="); DebugUtil.DumpProperties(e, Console.Out, 0); Console.WriteLine("----------------------------------------"); if (e.BasicProperties.ContentType == MapMessageReader.MimeType) { IMapMessageReader r = new MapMessageReader(e.BasicProperties, e.Body); DebugUtil.DumpProperties(r.Body, Console.Out, 0); } else if (e.BasicProperties.ContentType == StreamMessageReader.MimeType) { IStreamMessageReader r = new StreamMessageReader(e.BasicProperties, e.Body); while (true) { try { object v = r.ReadObject(); Console.WriteLine("(" + v.GetType() + ") " + v); } catch (EndOfStreamException) { break; } } } else { // No special content-type. Already covered by the DumpProperties above. } Console.WriteLine("=================================================="); }
public static void OnCallbackException(object sender, CallbackExceptionEventArgs args) { Console.WriteLine("OnCallbackException =============================="); Console.WriteLine("Sender: " + sender); Console.WriteLine("Message: " + args.Exception.Message); Console.WriteLine("Detail:"); DebugUtil.DumpProperties(args.Detail, Console.Out, 2); Console.WriteLine("----------------------------------------"); }
public override void HandleCast(bool isRedelivered, IBasicProperties requestProperties, byte[] body) { Console.Out.WriteLine("AddServer received a {0} one-way message.", isRedelivered ? "redelivered" : "new"); DebugUtil.DumpProperties(requestProperties, Console.Out, 0); DebugUtil.DumpProperties(body, Console.Out, 0); }
protected virtual void LogMessage(BasicDeliverEventArgs eventArgs) { StringBuilder buffer = new StringBuilder(); buffer.AppendLine("Got a message from the queue -- "); using (StringWriter writer = new StringWriter(buffer)) { DebugUtil.DumpProperties(eventArgs, writer, 0); } _log.Debug(buffer.ToString()); }
void PrintLoop(QueueingBasicConsumer consumer, ParsedOptions opts) { while (!_stopping) { object tmp; if (!consumer.Queue.Dequeue(200, out tmp)) { continue; } var msg = (BasicDeliverEventArgs)tmp; if (opts.BasicProps) { DebugUtil.DumpProperties(msg.BasicProperties, Console.Out, 1); } string output, formatted, input = msg.Body.AsUtf8String(); if (opts.PrettyJSON) { if (!LevelFilter.ShouldPrint(input, LogLevel.FromString(opts.Level), out formatted)) { continue; } output = formatted; } else { output = input; } Console.WriteLine(output); if (opts.WriteToFile) { WriteToFile(output); } } }
public static int Main(string[] args) { if (args.Length < 2) { Console.Error.WriteLine("Usage: SingleGet <uri> <queuename>"); Console.Error.WriteLine("RabbitMQ .NET client version " + typeof(IModel).Assembly.GetName().Version); Console.Error.WriteLine("Parameters:"); Console.Error.WriteLine(" <uri> = \"amqp://*****:*****@host:port/vhost\""); return(2); } string serverAddress = args[0]; string queueName = args[1]; var connectionFactory = new ConnectionFactory { Uri = serverAddress }; IConnection conn = connectionFactory.CreateConnection(); conn.ConnectionShutdown += LogConnClose; using (IModel model = conn.CreateModel()) { conn.AutoClose = true; model.QueueDeclare(queueName, false, false, false, null); BasicGetResult result = model.BasicGet(queueName, false); if (result == null) { Console.WriteLine("No message available."); } else { model.BasicAck(result.DeliveryTag, false); Console.WriteLine("Message:"); DebugUtil.DumpProperties(result, Console.Out, 0); } return(0); } // conn will have been closed here by AutoClose above. }
public static void TestSecureConnectionToRabbitMq(string rabbitmqhostname) { try { var cf = RabbitMqConnectionFactory.GetConnectionFactory(rabbitmqhostname); using (IConnection conn = cf.CreateConnection()) { using (IModel ch = conn.CreateModel()) { ch.QueueDeclare("rabbitmq-dotnet-test", false, false, false, null); ch.BasicPublish("", "rabbitmq-dotnet-test", null, Encoding.UTF8.GetBytes("Hello, World")); BasicGetResult result = ch.BasicGet("rabbitmq-dotnet-test", true); if (result == null) { Console.WriteLine("No message received."); } else { Console.WriteLine("Received:"); DebugUtil.DumpProperties(result, Console.Out, 0); } ch.QueueDelete("rabbitmq-dotnet-test"); } } } catch (BrokerUnreachableException bex) { Exception ex = bex; while (ex != null) { Console.WriteLine(ex.ToString()); Console.WriteLine("inner:"); ex = ex.InnerException; } } catch (Exception ex) { Console.WriteLine(ex.ToString()); } }