コード例 #1
0
        // Simple message handler for the PingMessage message type
        public static Task Handle(
            // The first argument is assumed to be the message type
            PingMessage message,

            // Jasper supports method injection similar to ASP.Net Core MVC
            // In this case though, IMessageContext is scoped to the message
            // being handled
            IMessageContext context)
        {
            ConsoleWriter.Write(ConsoleColor.Blue, $"Got ping #{message.Number}");

            var response = new PongMessage
            {
                Number = message.Number
            };

            // This usage will send the response message
            // back to the original sender. Jasper uses message
            // headers to embed the reply address for exactly
            // this use case
            return(context.RespondToSender(response));
        }
コード例 #2
0
 // "Handle" is recognized by Jasper as a message handling
 // method. Handler methods can be static or instance methods
 public static void Handle(PongMessage message)
 {
     ConsoleWriter.Write(ConsoleColor.Blue, $"Got pong #{message.Number}");
 }