public CommandProcessor(EnvironmentContext context,string routekey) { MessageConsumer = new MessageConsumer(); MessageProducer = new MessageProducer(); if (String.IsNullOrEmpty(routekey)) throw new Exception("Route key must not be null"); if (context == null) throw new Exception("CommandProcessor environment context must not be null"); _environment = context; RouteKey = routekey; MessageConsumer.OnMessageReceived += (msg) => { if (msg is CommandMessage) { try { if (msg.RoutingKey.Equals(_environment.GetRoute(RouteKey),StringComparison.CurrentCultureIgnoreCase)) { HandleMessage(msg); } } catch (Exception ex) { Log(msg.Ticket,ex.Message); } } }; }
public void MessageProducerCanSerializeToJson() { // Serialize var ex = new MessageProducer(); var json = ex.SerializeToJson(new CommandMessage() { RoutingKey = "test.route", ExecuteFile = "net.exe" }); Assert.IsTrue(json.Contains("CommandMessage")); }
public void MessageConsumerCanDeserializeFromJson() { // Serialize var ex = new MessageProducer(); var json = ex.SerializeToJson(new CommandMessage() { RoutingKey = "test.route", ExecuteFile = "net.exe" }); // DeSerialize var consumer = new MessageConsumer(); var msg = consumer.DeserializeFromJson(json); Assert.IsTrue(msg is CommandMessage); Assert.AreEqual("net.exe", ((CommandMessage)msg).ExecuteFile); }
public Job() { MessageProducer = new MessageProducer(); }