コード例 #1
0
 public void Handle(RabbitMqEventStream stream)
 {
     try
     {
         var @event = JsonConvert.DeserializeObject <PressureTestContent>(stream.Data);
         Console.WriteLine($"PressureTestContent: {@event.Content}");
     }
     catch (Exception ex)
     {
         Console.WriteLine($"PressureTestContentHandler Exception:{ex.Message}");
     }
 }
コード例 #2
0
        public static void Publish <T>(string topicName, T data)
        {
            var channel = RabbitMqFactory.GetChannel(topicName);
            var es      = new RabbitMqEventStream(
                typeof(T).Name,
                JsonConvert.SerializeObject(data),
                TimeStampHelper.ToUtcTimeStamp(DateTime.Now));

            var body = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(es));
            var prop = channel.CreateBasicProperties();

            prop.Expiration = ConfigHelper.RmqExpiration;

            channel.BasicPublish(
                $"Exchange-{ExchangeType.Direct}-{topicName}",
                string.Empty,
                prop,
                body);
        }