public void Publish <T>(T data) where T : IntegrationEvent
 {
     Logger.LogInformation("Begin publishing data");
     using (var channel = _channelFactory.CreateChannel())
     {
         var @eventName = typeof(T).FullName;
         var body       = Encoding.UTF8.GetBytes(JsonConvert.SerializeObject(data));
         channel.BasicPublish(@eventName, "", null, body);
         Logger.LogInformation("End publishing");
     }
 }
Exemple #2
0
 public void Publish(SagaCommandContext context, byte[] data)
 {
     using (var channel = _channelFactory.CreateChannel())
     {
         channel.ExchangeDeclare(context.MessageType, "direct", true, false, null);
         channel.QueueDeclare(context.DestinationAddress, true, false, false, null);
         channel.QueueDeclare(context.ReplyAddress, true, false, false, null);
         channel.QueueDeclare(context.FaultAddress, true, false, false, null);
         channel.QueueBind(context.DestinationAddress, context.MessageType, "", null);
         channel.BasicPublish(context.MessageType, "", true, new BasicProperties()
         {
             Headers    = context.ToDictionary(),
             Persistent = true,
         }, data);
         // we start to consume message on reply queue.
         StartConsumingMessage(context);
     }
 }