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);
                    }
                }
            };
        }
예제 #2
0
 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"));
 }
예제 #3
0
 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);
 }
예제 #4
0
 public Job()
 {
     MessageProducer = new MessageProducer();
 }