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}"); } }
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); }