public void PublishRead(string queueName, API.DemoMessage message) { var body = message.ToByteArray(); var properties = _channel.CreateBasicProperties(); properties.Type = API.DemoMessage.Descriptor.Name; _channel.BasicPublish(exchange: "", routingKey: queueName, basicProperties: properties, body: body); }
public void Produce(API.DemoMessage message) { var body = message.ToByteArray(); var properties = _channel.CreateBasicProperties(); properties.Type = API.DemoMessage.Descriptor.Name; _channel.BasicPublish(exchange: "demo.write", routingKey: "single", basicProperties: properties, body: body); }
public static Task <API.DemoMessage> RequestMessage(BrokerConnection connection, int id) { API.DemoMessage message = null; var tcs = new TaskCompletionSource <API.DemoMessage>(); BrokerConnection.MessageReceivedEventHandler handler = null; handler = (o, e) => { message = e.Message; connection.MessageReceivedEvent -= handler; tcs.SetResult(message); }; connection.MessageReceivedEvent += handler; connection.Request(id); return(tcs.Task); }
public void Request(int id) { var body = new API.DemoMessage { Id = id } .ToByteArray(); var properties = _channel.CreateBasicProperties(); properties.ReplyTo = _queueName; properties.Type = API.DemoMessage.Descriptor.Name; _channel.BasicPublish(exchange: "demo.read", routingKey: "single", basicProperties: properties, body: body); }
public static async Task Main(string[] args) { Console.SetOut(new PrefixedWriter()); var connection = new BrokerConnection(); connection.Open(); Console.WriteLine("Connected"); // Subscribe to any requests received connection.Subscribe(); Console.WriteLine("Subscribed to to anonymous queue"); // Produce couple of messages to queue var msg1 = new API.DemoMessage { Id = 10, Description = "First message", Updated = Timestamp.FromDateTime(DateTime.Now.ToUniversalTime()) }; var msg2 = new API.DemoMessage { Id = 20, Description = "Second message", Updated = Timestamp.FromDateTime(DateTime.Now.ToUniversalTime()) }; connection.Produce(msg1); connection.Produce(msg2); Console.WriteLine("Produced 2 messages to queue: \'demo.write.single\'"); // Ask for some message from queue try { Console.WriteLine("Sent request for queue: \'demo.read.single\' with id: 10"); var received1 = await TimeoutAfter(Requests.RequestMessage(connection, 10), TimeSpan.FromSeconds(2)); Console.WriteLine("Received message: ID: [{0}], Description: [{1}], Updated: [{2}]", received1.Id, received1.Description, received1.Updated); } catch (TimeoutException e) { Console.WriteLine(e.Message); } connection.Close(); Console.WriteLine("Disconnected"); }
public ReadFromDatabaseEventArgs(string replyQueue, API.DemoMessage message) { ReplyQueue = replyQueue; Message = message; }
public WriteToDatabaseEventArgs(API.DemoMessage message) { Message = message; }
public MessageReceivedEventArgs(API.DemoMessage message) { Message = message; }